sparql-examples

A set of SPARQL examples that are used in different TGX resources

View the Project on GitHub BiGCAT-UM/sparql-examples

060

rq turtle/ttl

Country aspect: Locations as topics for a specific country

Use at

PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://wikidata.org/entity/>
PREFIX wikibase: <http://wikiba.se/ontology#>
# title: Locations as topics for a specific country
PREFIX target: <http://www.wikidata.org/entity/Q35>

#defaultView:Map{"markercluster":true}.
SELECT 
  ?location ?locationLabel 
  ?work ?workLabel 
  ?geo
  ?layer
WITH {
  SELECT ?location ?work ?geo ?type WHERE {
    ?location wdt:P17 target: .
    
    # Geocoordinates may possible be under a headquarter property
    ?location wdt:P159? / wdt:P625 ?geo.
    ?work wdt:P921 ?location .
    
    # Filter encyclopedic articles - that may not be so relevant
    FILTER NOT EXISTS { ?work wdt:P31 wd:Q17329259 }
  }
} AS %results
WHERE {
  INCLUDE %results
          
  # Move here for speed of query
  OPTIONAL {
    ?work wdt:P31 / rdfs:label ?layer . 
    FILTER (LANG(?layer) = 'en')
  }
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en,da,de,es,fr,jp,nl,no,ru,sv,zh". }
} 
graph TD