query-2ad42658ceba4a4c387e9c4b60dec28b
TODO
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?i ?iLabel ?population ?area_sqkm ?popstatement ?date
WHERE
{
{ SELECT ?i (MAX(?date_) as ?date) WHERE
{
{
SELECT DISTINCT ?e ?i ?r WHERE {
VALUES ?i {
## Problematic entities with multiple population values
wd:Q884 wd:Q31057 wd:Q35555 wd:Q220982 wd:Q31063 wd:Q475038
}
OPTIONAL { ?i owl:sameAs ?r. }
BIND(COALESCE(?r, ?i) AS ?e)
} }
OPTIONAL { ## Population, if it exists
?i p:P1082 ?popstatement.
?popstatement a wikibase:BestRank .
# ?popstatement ps:P1082 ?population .
?popstatement pq:P585 ?date_ .
}
} GROUP BY ?i } OPTIONAL { ## Population, if it exists
?i p:P1082 ?popstatement.
?popstatement a wikibase:BestRank .
?popstatement ps:P1082 ?population .
?popstatement pq:P585 ?date . ## <<<<< The ?date must be the same as the ?date found by MAX(?date) in the first select <<<
}
OPTIONAL { ## Area, if it exists
?i p:P2046 ?areastatement .
?areastatement a wikibase:BestRank .
MINUS { ?areastatement pq:P518 wd:Q187223. } ## Filter out lagoons
MINUS { ?areastatement pq:P518 wd:Q9259. } ## Filter out UNESCO sites
MINUS { ?areastatement pq:P518 wd:Q64364418. } ## Filter out buffer zones
MINUS { ?areastatement pq:P1012 wd:Q389717. } ## Filter out contested Islands
?areastatement psn:P2046/wikibase:quantityAmount ?area_norm .
BIND( ROUND(?area_norm/1000000) as ?area_sqkm) .
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} ORDER BY ASC(?iLabel)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v10("?area_norm")
v11("?area_sqkm"):::projected
v9("?areastatement")
v7("?date"):::projected
v6("?date_")
v4("?e")
v2("?i"):::projected
v1("?iLabel"):::projected
v5("?popstatement"):::projected
v8("?population"):::projected
v3("?r")
a1((" "))
c4(["wikibase:BestRank"]):::iri
c19(["en"]):::literal
c11(["wd:Q64364418"]):::iri
c9(["wd:Q187223"]):::iri
c17(["bd:serviceParam"]):::iri
c10(["wd:Q9259"]):::iri
c13(["wd:Q389717"]):::iri
bind0[/VALUES ?i/]
bind0-->v2
bind00(["wd:Q884"])
bind00 --> bind0
bind01(["wd:Q31057"])
bind01 --> bind0
bind02(["wd:Q35555"])
bind02 --> bind0
bind03(["wd:Q220982"])
bind03 --> bind0
bind04(["wd:Q31063"])
bind04 --> bind0
bind05(["wd:Q475038"])
bind05 --> bind0
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v2 -."owl:sameAs".-> v3
end
bind1[/"?r?i"/]
v3 --o bind1
v2 --o bind1
bind1 --as--o v4
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:P1082".-> v5
v5 --"a"--> c4
v5 --"p:qualifier/P585"--> v6
end
bind3[/"max(?date_)"/]
v6 --o bind3
bind3 --as--o v7
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:P1082".-> v5
v5 --"a"--> c4
v5 --"p:statement/P1082"--> v8
v5 --"p:qualifier/P585"--> v7
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:P2046".-> v9
v9 --"a"--> c4
subgraph minus4["MINUS"]
style minus4 stroke-width:6px,fill:pink,stroke:red;
v9 --"p:qualifier/P518"--> c9
end
subgraph minus5["MINUS"]
style minus5 stroke-width:6px,fill:pink,stroke:red;
v9 --"p:qualifier/P518"--> c10
end
subgraph minus6["MINUS"]
style minus6 stroke-width:6px,fill:pink,stroke:red;
v9 --"p:qualifier/P518"--> c11
end
subgraph minus7["MINUS"]
style minus7 stroke-width:6px,fill:pink,stroke:red;
v9 --"p:qualifier/P1012"--> c13
end
v9 --"p:statement/value-normalized/P2046"--> a1
a1 --"wikibase:quantityAmount"--> v10
bind8[/"numeric-round(?area_norm / '1000000^^xsd:integer')"/]
v10 --o bind8
bind8 --as--o v11
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c17 --"wikibase:language"--> c19
end