How to make values statement optional in sparql?

by herminia_bruen , in category: Third Party Scripts , 5 months ago

How to make values statement optional in sparql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by arnoldo.moen , 5 months 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.

Related Threads:

How to make a continuous delete statement in oracle?
How to make an query parameter optional in regex?
How to make nested variables optional in helm?
How to make route parameters optional in ember.js?Javascript
How to get values for time intervals of hours in one day in sparql?
How to pass the graph variable into from statement in sparql?