query-b6d34257d565e39ec4607fb39c45c50a

rq turtle/ttl

title: Query for all second level administrative entities (Township-level) of Taiwan (should be 368) SELECT ?divisions ?divisionLabel WHERE { {?divisions wdt:P31 wd:Q2367508. FILTER NOT EXISTS { ?divisions p:P31 [ ps:P31 wd:Q2367508; pq:P582 ?endDate ] } } UNION {?divisions wdt:P31 wd:Q12039044. FILTER NOT EXISTS { ?divisions p:P31 [ ps:P31 wd:Q12039044; pq:P582 ?endDate ] } } UNION {?divisions wdt:P31 wd:Q713146 . FILTER NOT EXISTS { ?divisions p:P31 [ ps:P31 wd:Q713146; pq:P582 ?endDate ] } } UNION {?divisions wdt:P31 wd:Q17194218 . FILTER NOT EXISTS { ?divisions p:P31 [ ps:P31 wd:Q17194218; pq:P582 ?endDate ] } } UNION {?divisions wdt:P31 wd:Q705296.
FILTER NOT EXISTS { ?divisions p:P31 [ ps:P31 wd:Q705296; pq:P582 ?endDate ] } } UNION {?divisions wdt:P31 wd:Q17194217 .
FILTER NOT EXISTS { ?divisions p:P31 [ ps:P31 wd:Q17194217; pq:P582 ?endDate ] } } . MINUS { ?divisions wdt:P1366 [] } OPTIONAL { ?divisions rdfs:label ?divisionLabel . FILTER (lang(?divisionLabel) = "en") } } ORDER BY ?divisionLabel

Use at

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
#title: Query for all second level administrative entities (Township-level) of Taiwan (should be 368)
SELECT ?divisions ?divisionLabel WHERE {
  {?divisions wdt:P31 wd:Q2367508.
    FILTER NOT EXISTS { ?divisions p:P31 [ ps:P31 wd:Q2367508; pq:P582 ?endDate ] }
  } UNION
  {?divisions wdt:P31 wd:Q12039044. 
      FILTER NOT EXISTS { ?divisions p:P31 [ ps:P31 wd:Q12039044; pq:P582 ?endDate ] }
} UNION
  {?divisions wdt:P31 wd:Q713146 .
        FILTER NOT EXISTS { ?divisions p:P31 [ ps:P31 wd:Q713146; pq:P582 ?endDate ] }
} UNION
  {?divisions wdt:P31 wd:Q17194218 .
          FILTER NOT EXISTS { ?divisions p:P31 [ ps:P31 wd:Q17194218; pq:P582 ?endDate ] }
}  UNION
    {?divisions wdt:P31 wd:Q705296.     
   FILTER NOT EXISTS { ?divisions p:P31 [ ps:P31 wd:Q705296; pq:P582 ?endDate ] }
} UNION
  {?divisions wdt:P31 wd:Q17194217 .     
   FILTER NOT EXISTS { ?divisions p:P31 [ ps:P31 wd:Q17194217; pq:P582 ?endDate ] }
} .
  MINUS { ?divisions wdt:P1366 [] }
  OPTIONAL {
    ?divisions rdfs:label ?divisionLabel .
    FILTER (lang(?divisionLabel) = "en")
  }
} ORDER BY ?divisionLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?divisionLabel"):::projected v3("?divisions"):::projected v2("?endDate") a1((" ")) a2((" ")) a3((" ")) a4((" ")) a5((" ")) a6((" ")) a7((" ")) c7(["wd:Q12039044"]):::iri c8(["wd:Q713146"]):::iri c10(["wd:Q705296"]):::iri c3(["wd:Q2367508"]):::iri c9(["wd:Q17194218"]):::iri c11(["wd:Q17194217"]):::iri subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; subgraph union2[" Union "] subgraph union2l[" "] style union2l fill:#abf,stroke-dasharray: 3 3; subgraph union3[" Union "] subgraph union3l[" "] style union3l fill:#abf,stroke-dasharray: 3 3; subgraph union4[" Union "] subgraph union4l[" "] style union4l fill:#abf,stroke-dasharray: 3 3; f0[["not "]] subgraph f0e0["Exists Clause"] e0a1 --"p:statement/P31"--> e0c2 e0a1 --"p:qualifier/P582"--> e0v1 e0v2 --"p:P31"--> e0a1 e0v2("?divisions"):::projected e0v1("?endDate"):::projected e0a1((" ")):::projected e0c2(["wd:Q17194217"]):::iri end f0--EXISTS--> f0e0 f0 --> a6 f0 --> c2 f0 --> c11 f0 --> c4 f0 --> v2 f0 --> v3 f0 --> c5 a6 --"p:statement/P31"--> c11 a6 --"p:qualifier/P582"--> v2 v3 --"p:P31"--> a6 v3 --"p:direct/P31"--> c11 end subgraph union4r[" "] style union4r fill:#abf,stroke-dasharray: 3 3; f1[["not "]] subgraph f1e1["Exists Clause"] e1a1 --"p:statement/P31"--> e1c2 e1a1 --"p:qualifier/P582"--> e1v1 e1v2 --"p:P31"--> e1a1 e1v2("?divisions"):::projected e1v1("?endDate"):::projected e1a1((" ")):::projected e1c2(["wd:Q705296"]):::iri end f1--EXISTS--> f1e1 f1 --> a5 f1 --> c2 f1 --> c10 f1 --> c4 f1 --> v2 f1 --> v3 f1 --> c5 a5 --"p:statement/P31"--> c10 a5 --"p:qualifier/P582"--> v2 v3 --"p:P31"--> a5 v3 --"p:direct/P31"--> c10 end union4r <== or ==> union4l end end subgraph union3r[" "] style union3r fill:#abf,stroke-dasharray: 3 3; f2[["not "]] subgraph f2e2["Exists Clause"] e2a1 --"p:statement/P31"--> e2c2 e2a1 --"p:qualifier/P582"--> e2v1 e2v2 --"p:P31"--> e2a1 e2v2("?divisions"):::projected e2v1("?endDate"):::projected e2a1((" ")):::projected e2c2(["wd:Q17194218"]):::iri end f2--EXISTS--> f2e2 f2 --> a4 f2 --> c2 f2 --> c9 f2 --> c4 f2 --> v2 f2 --> v3 f2 --> c5 a4 --"p:statement/P31"--> c9 a4 --"p:qualifier/P582"--> v2 v3 --"p:P31"--> a4 v3 --"p:direct/P31"--> c9 end union3r <== or ==> union3l end end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; f3[["not "]] subgraph f3e3["Exists Clause"] e3a1 --"p:statement/P31"--> e3c2 e3a1 --"p:qualifier/P582"--> e3v1 e3v2 --"p:P31"--> e3a1 e3v2("?divisions"):::projected e3v1("?endDate"):::projected e3a1((" ")):::projected e3c2(["wd:Q713146"]):::iri end f3--EXISTS--> f3e3 f3 --> a3 f3 --> c2 f3 --> c8 f3 --> c4 f3 --> v2 f3 --> v3 f3 --> c5 a3 --"p:statement/P31"--> c8 a3 --"p:qualifier/P582"--> v2 v3 --"p:P31"--> a3 v3 --"p:direct/P31"--> c8 end union2r <== or ==> union2l end end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; f4[["not "]] subgraph f4e4["Exists Clause"] e4a1 --"p:statement/P31"--> e4c2 e4a1 --"p:qualifier/P582"--> e4v1 e4v2 --"p:P31"--> e4a1 e4v2("?divisions"):::projected e4v1("?endDate"):::projected e4a1((" ")):::projected e4c2(["wd:Q12039044"]):::iri end f4--EXISTS--> f4e4 f4 --> a2 f4 --> c2 f4 --> c7 f4 --> c4 f4 --> v2 f4 --> v3 f4 --> c5 a2 --"p:statement/P31"--> c7 a2 --"p:qualifier/P582"--> v2 v3 --"p:P31"--> a2 v3 --"p:direct/P31"--> c7 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; f5[["not "]] subgraph f5e5["Exists Clause"] e5a1 --"p:statement/P31"--> e5c2 e5a1 --"p:qualifier/P582"--> e5v1 e5v2 --"p:P31"--> e5a1 e5v2("?divisions"):::projected e5v1("?endDate"):::projected e5a1((" ")):::projected e5c2(["wd:Q2367508"]):::iri end f5--EXISTS--> f5e5 f5 --> a1 f5 --> c2 f5 --> c3 f5 --> c4 f5 --> v2 f5 --> v3 f5 --> c5 a1 --"p:statement/P31"--> c3 a1 --"p:qualifier/P582"--> v2 v3 --"p:P31"--> a1 v3 --"p:direct/P31"--> c3 end union0r <== or ==> union0l end subgraph minus6["MINUS"] style minus6 stroke-width:6px,fill:pink,stroke:red; v3 --"p:direct/P1366"--> a7 end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."rdfs:label".-> v1 end