How to make values statement optional in sparql?

by herminia_bruen , in category: Third Party Scripts , 24 days ago

How to make values statement optional in sparql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by arnoldo.moen , 23 days ago

@herminia_bruen 

In SPARQL, you can make a values statement optional by using the OPTIONAL keyword. For example, let's say you have a query that includes a values statement like this:

1
2
3
4
5
SELECT ?property ?value
WHERE {
  VALUES ?property { <http://example.com/prop1> <http://example.com/prop2> }
  ?subject ?property ?value
}


To make the values statement optional, you can modify the query like this:

1
2
3
4
5
6
7
SELECT ?subject ?property ?value
WHERE {
  ?subject ?property ?value
  OPTIONAL {
    VALUES ?property { <http://example.com/prop1> <http://example.com/prop2> }
  }
}


This way, the values statement will only be applied to the results if it is available, but it is not required for the query to return results.