query-83c7f2c5fd3bad21dff9937f474b1153

rq turtle/ttl

Maxdate Haha, I see -- well then, let me inundate you with my latest related query: I keep getting lots of population values for the same entity (due to different years), but I'm not sure how to filter for the latest Year: Tagishsimon@

Use at

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 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)
    }
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  OPTIONAL {                  ## Population, if it exists
      ?i p:P1082 ?popstatement. 
      ?popstatement a wikibase:BestRank .
      ?popstatement ps:P1082 ?population .
      ?popstatement pq:P585 ?date .
  }
  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) . 
  }
} ORDER BY ASC(?iLabel)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v9("?area_norm") v10("?area_sqkm"):::projected v8("?areastatement") v7("?date"):::projected v4("?e") v2("?i"):::projected v1("?iLabel"):::projected v5("?popstatement"):::projected v6("?population"):::projected v3("?r") a1((" ")) c5(["en"]):::literal c8(["wikibase:BestRank"]):::iri c15(["wd:Q64364418"]):::iri c13(["wd:Q187223"]):::iri c3(["bd:serviceParam"]):::iri c14(["wd:Q9259"]):::iri c17(["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 s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c3 --"wikibase:language"--> c5 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:P1082".-> v5 v5 --"a"--> c8 v5 --"p:statement/P1082"--> v6 v5 --"p:qualifier/P585"--> v7 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:P2046".-> v8 v8 --"a"--> c8 subgraph minus2["MINUS"] style minus2 stroke-width:6px,fill:pink,stroke:red; v8 --"p:qualifier/P518"--> c13 end subgraph minus3["MINUS"] style minus3 stroke-width:6px,fill:pink,stroke:red; v8 --"p:qualifier/P518"--> c14 end subgraph minus4["MINUS"] style minus4 stroke-width:6px,fill:pink,stroke:red; v8 --"p:qualifier/P518"--> c15 end subgraph minus5["MINUS"] style minus5 stroke-width:6px,fill:pink,stroke:red; v8 --"p:qualifier/P1012"--> c17 end v8 --"p:statement/value-normalized/P2046"--> a1 a1 --"wikibase:quantityAmount"--> v9 bind6[/"numeric-round(?area_norm / '1000000^^xsd:integer')"/] v9 --o bind6 bind6 --as--o v10 end