Is there some way to use a kind of placeholder variable with SPARQL without returning it when using SELECT * ? (kleene star)

For example:

SELECT * WHERE{ 
   ?s dcterms:title ?title; 
      foaf:person ?name. 
   ?s2 :inProject ?s. 
}

Where I would not want to return the ?s variable, just the ?title, ?name, and ?s2 variables while leaving the SELECT *.

I understand I can limit the select results by using SELECT ?title ?name ..., but I'm just curious if there is some kind of notation for placeholder variables or some way to manage this.


EDIT: - I understand you can use blank nodes to accomplish this in some cases, for example:

SELECT * WHERE{ 
   _:s dcterms:title ?title; 
      foaf:person ?name. 
   ?s2 :inProject _:s. 
}

However, doesn't this cause problems since blank nodes can't be used across basic graph patterns? For example, this breaks in the case:

SELECT * WHERE{ 
   _:s dcterms:title ?title; 
      foaf:person ?name. 
   OPTIONAL{ ?s2 :inProject _:s. }
}

Thanks!

asked 21 Feb '13, 11:24

Dev-Deverton's gravatar image

Dev-Deverton
414
accept rate: 0%

edited 21 Feb '13, 13:48


 SELECT * 
 WHERE{ _:s dcterms:title ?title ; foaf:person ?name. ?s2 :inProject _:s }

_:s serves as a non-distinguished variable that will not be returned as a solution to the query.

link

answered 21 Feb '13, 11:39

Signified's gravatar image

Signified ♦
23.7k1623
accept rate: 37%

edited 21 Feb '13, 11:41

1

Doesn't this cause a problem with scope when using multiple graph patterns? You can't use this in a query such as: SELECT * WHERE { _:s dcterms:title ?title ; foaf:person ?name. OPTIONAL{?s2 :inProject _:s}}, correct? Supposedly blank nodes can't be used across basic graph patterns...

(21 Feb '13, 13:40) Dev-Deverton Dev-Deverton's gravatar image

Duplicating my answer from SO:

For variables scoped to a single pattern yes, use the blank node variable syntax as you demonstrated by @Signified's answer and in your question

In the general case no, if you use a variable then SELECT * will return it.

One possible workaround is to use sub-queries where you do list variables and leave out the variables you don't want e.g.

SELECT * WHERE
{ 
  {
    SELECT ?title ?name ?s2 WHERE 
    {
      ?s dcterms:title ?title; 
      foaf:person ?name. 
      OPTIONAL{ ?s2 :inProject ?s. }
    }
  }
}

But then I assume this is exactly what you are trying to avoid since you end up listing variables anyway.

link

answered 21 Feb '13, 18:00

Rob%20Vesse's gravatar image

Rob Vesse ♦
13.8k1715
accept rate: 29%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×1,266

Asked: 21 Feb '13, 11:24

Seen: 419 times

Last updated: 21 Feb '13, 18:00