'How to retrieve only actual values
I have a SPARQL query where I try to retrieve all current german municipalities from wikidata, with some of their properties.
For example I try to retrieve their postal codes and parent regions:
SELECT DISTINCT ?region ?regionLabel ?postalCode ?parentLabel WHERE {
?region wdt:P31 wd:Q262166. # Municipalities
?region wdt:P17 wd:Q183. # from Germany
MINUS { ?region p:P576 _:anyValue. } # Only regions which exist today
OPTIONAL { ?region wdt:P281 ?postalCode. } # Select postal code
OPTIONAL { ?region wdt:P131 ?parent. } # Select administrative parents
SERVICE wikibase:label { bd:serviceParam wikibase:language "de" . } # Show german labels
}
As you can seen, I already found out how to exclude those municipalities which doesn't exist any more (because they have a property p:P576
= end date). I know it is a little bit fuzzy, because it could be an end date in the future (which is only determined already).
But more important, the postal codes and parents include "historical ones", which I would like to exclude. I know that I could do something like answered in "https://stackoverflow.com/questions/49066390/how-to-get-only-the-most-recent-value-from-a-wikidata-property", but the solution their is to bind the end date of the properties, which is usually not set for the current value. Despite the fact that I don't know how to build the query with two optional values.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|