query-c8112a649818495fd69fe2a733bd84d6

rq turtle/ttl

instances_of=law enforcement agency (Q732717); country=Brazil (Q155); NOT police station (Q861951) SELECT DISTINCT ?item ?itemLabel ?jurisdictionLabel ?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:Q732717. ?item p:P17 ?statement1. ?statement1 ps:P17 wd:Q155. # Change country here MINUS { ?item wdt:P31 wd:Q861951. } # NOT police station } } OPTIONAL { ?item wdt:P1001 ?jurisdiction. } OPTIONAL { ?item wdt:P856 ?official_website. } } ORDER BY (?jurisdiction)

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=law enforcement agency (Q732717); country=Brazil (Q155); NOT police station (Q861951)
SELECT DISTINCT ?item ?itemLabel ?jurisdictionLabel ?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:Q732717.
      ?item p:P17 ?statement1.
      ?statement1 ps:P17 wd:Q155.  # Change country here
      MINUS { ?item wdt:P31 wd:Q861951. } # NOT police station
    }
  }
  OPTIONAL { ?item wdt:P1001 ?jurisdiction. }
  OPTIONAL { ?item wdt:P856 ?official_website. }
}
ORDER BY  (?jurisdiction)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?item"):::projected v1("?jurisdiction") v5("?official_website"):::projected v3("?statement0") v4("?statement1") a1((" ")) c8(["wd:Q732717"]):::iri c2(["bd:serviceParam"]):::iri c4(["#91;AUTO_LANGUAGE#93;"]):::literal c13(["wd:Q861951"]):::iri c11(["wd:Q155"]):::iri subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c2 --"wikibase:language"--> c4 end v2 --"p:P31"--> v3 v3 --"p:statement/P31"--> a1 a1 --"p:direct/P279"--> c8 v2 --"p:P17"--> v4 v4 --"p:statement/P17"--> c11 subgraph minus0["MINUS"] style minus0 stroke-width:6px,fill:pink,stroke:red; v2 --"p:direct/P31"--> c13 end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P1001".-> v1 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P856".-> v5 end