Edit: Please read the comments to this post - the post itself is answered.
The relevant part of my query (retrieving Nobel Prize winners who, at the time of winning, were head of state or head of government) is this:
?nobel_laureate p:P39 ?p39 . # p39 = "position held"
?p39 ps:P39 ?status .
?p39 pq:P580 ?start_time .
OPTIONAL { ?p39 pq:P582 ?end_time . }
...
FILTER ( ?point_in_time >= ?start_time && ?point_in_time <= ?end_time )
?nobel_laureateholds Nobel Prize winners.?status holdsthe values for the properties "office held by head of state" and "office held by head of government" for the country the Nobel Prize winner is a citizen of?point_in_timeis the time of winning the Nobel Prize.
I now want to retrieve the "start time" and "end time" qualifier values for the "position held" statements with value in ?status, e.g., "Prime Minister of Sweden" and "Monarch of Sweden" for Hjalmar Branting, who was a Swedish citizen.
He was Prime Minister of Sweden twice.
I have the problem that if I want to check if ?point_in_time is between "start time" and "end time", the different Prime Minister of Sweden statements get mixed up.
What can I do to keep them apart?
I did not try anything because I am clueless.
Edit: There a several other people from this Wikipedia list which don't show up in the output for reasons I can't find. Barack Obama and Abiy Ahmed are eliminated by the FILTER: For Mikhail Gorbachev and F.W. de Klerk, I don't know why they are missing.
Regarding the Abiy Ahmed Ali issue: the filter does not succeed if
?end_timeis not bound by theOPTIONALclause, because then the<=comparison results in an error.SPARQL has the
bound()function for this, which checks if the argument is bound or not. In this case something like (untested):However, QLever does not implement this, so you will get the error:
An alternative is to use
COALESCE. This function takesnarguments and returns the result of the first expression that does not trigger an error. So you can check the end date condition, if there is an end date it will produce true or false as required, if there is no end date you go to the second argument, which you need to choose such that it always evaluates to true (since somebody who is still in office qualifies for the list if the start date condition is met).Code:
Result (pictures removed to save space):