Is there a way to use a variable without returning it using SPARQL "select *"?

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

For instance:

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

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

I understand that I can limit the selection results with SELECT ?title ?name ... , but I'm just wondering if there is some kind of notation for the placeholder variables or how to manage this somehow.


EDIT:

I understand that you can use empty nodes to accomplish this in some cases, for example:

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

However, this does not cause problems, since empty nodes cannot be used in the baseline templates? For example, this is interrupted if:

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

Thanks!

+4
source share
1 answer

For variables bound to the same template, yes, use the empty node variable syntax, as you showed in your question

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

A possible workaround is to use subqueries in which you list the variables, and leave the variables you don't want, for example.

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

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

+2
source

All Articles