query-53919d42d7519df7f00f6c06c370617e

rq turtle/ttl

List of countries with share common human settlement with other countries SELECT ?country ?countryLabel ?country2 ?country2Label (COUNT(DISTINCT ?object) AS ?count) WHERE { ?object wdt:P17 ?country. #Belonging to a county ?object wdt:P17 ?country2. ?object wdt:P31/wdt:P279 wd:Q486972. #Human settlements FILTER(STR(?country2) < STR(?country)) # use < instead of != to have each result only once MINUS{?object wdt:P31/wdt:P279 wd:Q15239622.} #Filtering out all disputed territorry 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} 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#>
#List of countries with share common human settlement with other countries
SELECT ?country ?countryLabel ?country2 ?country2Label (COUNT(DISTINCT ?object) AS ?count)
WHERE {
  ?object wdt:P17 ?country. #Belonging to a county
  ?object wdt:P17 ?country2.
  ?object wdt:P31/wdt:P279* wd:Q486972. #Human settlements
  FILTER(STR(?country2) < STR(?country)) # use < instead of != to have each result only once
  MINUS{?object wdt:P31/wdt:P279* wd:Q15239622.} #Filtering out all disputed territorry
  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}
  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; v6("?count") v3("?country"):::projected v2("?country2"):::projected v5("?ended") v4("?object"):::projected a1((" ")) a2((" ")) a3((" ")) a4((" ")) c5(["wd:Q15239622"]):::iri c4(["wd:Q486972"]):::iri c8(["wd:Q3024240"]):::iri c10(["bd:serviceParam"]):::iri c12(["en"]):::literal f0[["str(?country2) < str(?country)"]] f0 --> v2 f0 --> v3 v4 --"wdt:P17"--> v3 v4 --"wdt:P17"--> v2 v4 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c4 subgraph minus1["MINUS"] style minus1 stroke-width:6px,fill:pink,stroke:red; v4 --"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; v3 --"wdt:P576"--> v5 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v3 --"wdt:P582"--> v5 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; v2 --"wdt:P576"--> v5 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P582"--> v5 end union1r <== or ==> union1l end end subgraph minus4["MINUS"] style minus4 stroke-width:6px,fill:pink,stroke:red; v3 --"wdt:P31"--> a3 a3 --"wdt:P279"--> c8 end subgraph minus5["MINUS"] style minus5 stroke-width:6px,fill:pink,stroke:red; v2 --"wdt:P31"--> a4 a4 --"wdt:P279"--> c8 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 end bind7[/"count(?object)"/] v4 --o bind7 bind7 --as--o v6