Kenman
Kenman

Reputation: 11

Need help for SPARQL Query

I have the following query. It works and seems to be good.

Now, I want to add the city. The problem is that some admin units are already the city, others are just districts and the city is at a higher level. Some of the cities are countries or states (e.g. Singapore, Washington), which could also be problematic.

The aim is to be able to query all cinemas in the world with this query. The query should therefore be performant. If necessary, certain information can also be output as individual fields, in which case I will filter this seamlessly in Excel.

SELECT DISTINCT  ?item ?itemLabel ?itemDescription ?admin_unit ?admin_unitLabel ?cityLabel ?country  ?wikiPage ?official_closure ?closureDate

  WHERE {
      ?item wdt:P31 wd:Q41253; wdt:P131 ?admin_unit. 
      ?admin_unit wdt:P17 wd:Q183.           # Deutschland
    
    OPTIONAL { ?admin_unit wdt:P17 ?country.}   
    # OPTIONAL { ?item wdt:P576 ?closureDate. }
    # OPTIONAL { ?item wdt:P3999 ?official_closure. }
    MINUS { ?item wdt:P576 ?closureDate. }
    MINUS { ?item wdt:P3999 ?official_closure. }
    MINUS { ?item (p:P5816) wd:Q56556915, wd:Q61962974, wd:Q106959824. }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "de,en" . }
  }
    
LIMIT 100  # just for testing. Later, I'll need all the items in the world

I have tried this. However, the query seems to be much slower with this. And it only returns a city for very few items.

   OPTIONAL {  ?admin_unit (wdt:P131)* ?city. 
               ?city wdt:P31 wd:Q515.  }

If helpful, these are the items that seem to describe cities: wd:Q133442, wd:Q7930989, wd:Q1549591, wd:Q129676344, wd:Q896881, wd:Q6213969

Upvotes: 1

Views: 45

Answers (0)

Related Questions