query-a5dfa796fdd38735e82caeaef70872e8

rq turtle/ttl

Country-level query example

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# instances_of=crematorium (Q157570); country=Brazil (Q155);
#defaultView:Map
SELECT DISTINCT ?item ?itemLabel ?itemDescription ?country ?located_in_adm ?geo ?official_website WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
  {
    SELECT DISTINCT ?item WHERE {
      ?item p:P31 ?statement0.
      ?statement0 (ps:P31/(wdt:P279*)) wd:Q157570.
      ?item p:P17 ?statement1.
      ?statement1 ps:P17 wd:Q155.  # Change country here
      # MINUS { ?item wdt:P31 wd:QXXXXXX. } # @TODO remove potential pet crematories
    }
  }

  OPTIONAL { ?item wdt:P17 ?country. }
  OPTIONAL { ?item wdt:P131 ?located_in_adm. }
  OPTIONAL { ?item wdt:P625 ?geo. }
  OPTIONAL { ?item wdt:P856 ?official_website. }
}
ORDER BY  (?country) (?located_in_adm)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?country"):::projected v6("?geo"):::projected v3("?item"):::projected v2("?located_in_adm"):::projected v7("?official_website"):::projected v4("?statement0") v5("?statement1") a1((" ")) c8(["wd:Q157570"]):::iri c2(["bd:serviceParam"]):::iri c4(["#91;AUTO_LANGUAGE#93;"]):::literal c11(["wd:Q155"]):::iri subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c2 --"wikibase:language"--> c4 end v3 --"p:P31"--> v4 v4 --"p:statement/P31"--> a1 a1 --"p:direct/P279"--> c8 v3 --"p:P17"--> v5 v5 --"p:statement/P17"--> c11 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:direct/P17".-> v1 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:direct/P131".-> v2 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:direct/P625".-> v6 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:direct/P856".-> v7 end