0

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.

Tobias Liefke
  • 8,637
  • 2
  • 41
  • 58
  • you can only get the most recent value if there is some date information. For postal code there is no such data attached to the statements, i.e. there is no date qualifier - and this would have been used to get the most recent one – UninformedUser Feb 18 '22 at 04:26
  • do you have an example with a municipality where you think it is a historical postal code? – UninformedUser Feb 18 '22 at 04:27
  • For some of the ones I found, there is a date attached. For example [Hauzenberg](https://www.wikidata.org/wiki/Q255888) has three of them. But in fact, for most of the statements there is no date information. – Tobias Liefke Feb 20 '22 at 17:20

0 Answers0