query-ec2eefd9ae1f4f659519276270221a35

rq turtle/ttl

All human settlements that are are in a country (and at least one) non recognised country SELECT DISTINCT ?object ?objectLabel ?country ?countryLabel ?country2 ?country2Label #(COUNT(DISTINCT ?object) AS ?count) WHERE { ?object wdt:P17 ?country. #Belonging to a county ?object wdt:P17 ?country2. ?country2 wdt:P31/wdt:P279 wd:Q15634554. #Non recognised countries MINUS{?object wdt:P31/wdt:P279 wd:Q15239622.} #Filtering out all disputed territorry FILTER(STR(?country2) != STR(?country)) # use < instead of != to have each result only once MINUS { ?country wdt:P582|wdt:P576 ?ended. } #Countries have not ended or dissolved MINUS { ?country2 wdt:P582|wdt:P576 ?ended.} MINUS {?country wdt:P31/wdt:P279 wd:Q3024240} #Former countries MINUS {?country2 wdt:P31/wdt:P279 wd:Q3024240} ?object wdt:P31/wdt:P279* wd:Q486972. #Human settlements SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } }

GROUP BY ?country ?countryLabel ?country2 ?country2Label

ORDER BY DESC(?count)

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#All human settlements that are are in a country (and at least one) non recognised country
SELECT DISTINCT ?object ?objectLabel ?country ?countryLabel ?country2 ?country2Label #(COUNT(DISTINCT ?object) AS ?count)
WHERE {
  ?object wdt:P17 ?country. #Belonging to a county
  ?object wdt:P17 ?country2.
  ?country2 wdt:P31/wdt:P279* wd:Q15634554. #Non recognised countries
  MINUS{?object wdt:P31/wdt:P279* wd:Q15239622.} #Filtering out all disputed territorry
  FILTER(STR(?country2) != STR(?country)) # use < instead of != to have each result only once
  MINUS { ?country wdt:P582|wdt:P576 ?ended. } #Countries have not ended or dissolved
  MINUS { ?country2 wdt:P582|wdt:P576 ?ended.}
  MINUS {?country wdt:P31/wdt:P279* wd:Q3024240} #Former countries
  MINUS {?country2 wdt:P31/wdt:P279* wd:Q3024240}
  ?object wdt:P31/wdt:P279* wd:Q486972. #Human settlements
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
#GROUP BY ?country ?countryLabel ?country2 ?country2Label
#ORDER BY DESC(?count)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?country"):::projected v1("?country2"):::projected v4("?ended") v3("?object"):::projected a1((" ")) a2((" ")) a3((" ")) a4((" ")) a5((" ")) c4(["wd:Q15634554"]):::iri c13(["en"]):::literal c5(["wd:Q15239622"]):::iri c8(["wd:Q3024240"]):::iri c9(["wd:Q486972"]):::iri c11(["bd:serviceParam"]):::iri f0[["str(?country2) != str(?country)"]] f0 --> v1 f0 --> v2 v3 --"wdt:P17"--> v2 v3 --"wdt:P17"--> v1 v1 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c4 subgraph minus1["MINUS"] style minus1 stroke-width:6px,fill:pink,stroke:red; v3 --"wdt:P31"--> a2 a2 --"wdt:P279"--> c5 end subgraph minus2["MINUS"] style minus2 stroke-width:6px,fill:pink,stroke:red; subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P576"--> v4 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P582"--> v4 end union0r <== or ==> union0l end end subgraph minus3["MINUS"] style minus3 stroke-width:6px,fill:pink,stroke:red; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P576"--> v4 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P582"--> v4 end union1r <== or ==> union1l end end subgraph minus4["MINUS"] style minus4 stroke-width:6px,fill:pink,stroke:red; v2 --"wdt:P31"--> a3 a3 --"wdt:P279"--> c8 end subgraph minus5["MINUS"] style minus5 stroke-width:6px,fill:pink,stroke:red; v1 --"wdt:P31"--> a4 a4 --"wdt:P279"--> c8 end v3 --"wdt:P31"--> a5 a5 --"wdt:P279"--> c9 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c11 --"wikibase:language"--> c13 end