4

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

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!

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Nick Bartlett
  • 4,865
  • 2
  • 24
  • 37
  • Duplicate of question at http://answers.semanticweb.com/questions/21173/use-a-variable-without-returning-it-with-select – Jeen Broekstra Feb 21 '13 at 21:12
  • "(kleene star)" When you write `select * ...`, that's not a Kleene star. The Kleene star means "zero or more repetitions of something". E.g., `(ab)*` would match `"ababab"` and `"ab"` and `""`. In `select *`, the `*` is just a run-of-the-mill wildcard. – Joshua Taylor Oct 22 '14 at 20:37
  • @JoshuaTaylor you are very correct. – Nick Bartlett Oct 24 '14 at 14:36

1 Answers1

2

For variables scoped to a single pattern yes, use the blank node variable syntax as you demonstrated 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.

RobV
  • 28,022
  • 11
  • 77
  • 119