sparql-examples

A set of SPARQL examples that are used in test resources

View the Project on GitHub mxenoph/sparql-examples

001

rq turtle/ttl

What hospitals have a heliport?

Use at



PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT DISTINCT ?item ?itemLabel ?geo WHERE {
  # 1. The item must be an instance or subclass of a hospital
  ?item wdt:P31/wdt:P279* wd:Q16917.
  
  # 2. The item must also have a property indicating it is/has a heliport
  # Using P31 (instance of) or P466 (occupant) depending on how it's tagged
  ?item wdt:P31/wdt:P279* wd:Q502074.
  
  # 3. Get the coordinates
  ?item wdt:P625 ?geo.
  
  # 4. Standard Wikidata service to get human-readable labels
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v2("?geo"):::projected 
  v1("?item"):::projected 
  a1((" "))
  a2((" "))
  c7([http://www.bigdata.com/rdf#serviceParam]):::iri 
  c3(["wd:Q16917"]):::iri 
  c9(["#91;AUTO_LANGUAGE#93;,en"]):::literal 
  c4(["wd:Q502074"]):::iri 
  v1 --"wdt:P31"-->  a1
  a1 --"wdt:P279"-->  c3
  v1 --"wdt:P31"-->  a2
  a2 --"wdt:P279"-->  c4
  v1 --"wdt:P625"-->  v2
  subgraph s1["http://wikiba.se/ontology#label"]
    style s1 stroke-width:4px;
    c7 --"wikibase:language"-->  c9
  end