query-e2dc84f595544ce0616f039726717c49

rq turtle/ttl

Get qualifiers of statement with preferred rank is missing entirely. (P1082)population statistics for a set of jurisdictions. I'd like to find cases where the statement with the preferred rank (whatever would be returned with a normal query) is either outdated or missing a reference... or where the (P1082)population I'm trying to do some quality assurance on the My understanding is that to get statement qualifiers, I need to refer directly to the statement node, but doing so seems to bypass the mechanism for returning only the preferred statement, instead returning all of them. I can access the rank itself, but how do I filter down to just the statement with the highest rank? I don't care about 19th century population figures; I just want the latest/preferred ones. My working draft query is below.

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?jurisdiction ?jurisdictionLabel ?population ( year(?PiT) as ?year ) ?rank ?refURL
WHERE {
    VALUES ?jurisdiction { wd:Q1904 wd:Q8686 wd:Q42651 wd:Q172 wd:Q5826 wd:Q514796 }
    OPTIONAL { 
      ?jurisdiction p:P1082 ?statementNode .
      ?statementNode ps:P1082 ?population .
      ?statementNode wikibase:rank ?rank .
      OPTIONAL {
        ?statementNode pq:P585 ?PiT .
      }
      OPTIONAL {
        ?statementNode prov:wasDerivedFrom ?referenceNode .
        ?referenceNode pr:P854 ?refURL .
      }
    }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?jurisdiction ?rank ?year

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?PiT"):::projected v4("?jurisdiction"):::projected v5("?population"):::projected v2("?rank"):::projected v8("?refURL"):::projected v7("?referenceNode") v4("?statementNode") v9("?year") c8(["bd:serviceParam"]):::iri c10(["en"]):::literal bind0[/VALUES ?jurisdiction/] bind0-->v4 bind00(["wd:Q1904"]) bind00 --> bind0 bind01(["wd:Q8686"]) bind01 --> bind0 bind02(["wd:Q42651"]) bind02 --> bind0 bind03(["wd:Q172"]) bind03 --> bind0 bind04(["wd:Q5826"]) bind04 --> bind0 bind05(["wd:Q514796"]) bind05 --> bind0 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:P1082".-> v4 v4 --"p:statement/P1082"--> v5 v4 --"wikibase:rank"--> v2 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:qualifier/P585".-> v6 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v4 -."prov:wasDerivedFrom".-> v7 v7 --"p:reference/P854"--> v8 end end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 end bind1[/"year-from-dateTime(?PiT)"/] v6 --o bind1 bind1 --as--o v9