query-146472e9f9789efd635e78bfc98bf0d0

rq turtle/ttl

Wikidata entries for British ambassadors and high commissioners

count is number of distinct individuals in Wikidata known to hold the role

and number sourced to the FCO database

select distinct ?item ?itemLabel ?count ?importedcount where { { ?item wdt:P31 wd:Q18115939 . } union { ?item wdt:P31 wd:Q56760832 } . # ambassador or high commissioner

optional { select distinct ?item (count(distinct ?holder) as ?count) where { { ?item wdt:P31 wd:Q18115939 . } union { ?item wdt:P31 wd:Q56760832 } . ?holder p:P39 ?positionStatement . ?positionStatement ps:P39 ?item . } group by ?item } optional { select distinct ?item (count(distinct ?importedholder) as ?importedcount) where { { ?item wdt:P31 wd:Q18115939 . } union { ?item wdt:P31 wd:Q56760832 } . ?importedholder p:P39 ?positionStatement . ?positionStatement ps:P39 ?item . ?positionStatement prov:wasDerivedFrom ?ref . ?ref pr:P248 wd:Q56808876 . } group by ?item } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
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 p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Wikidata entries for British ambassadors and high commissioners
# count is number of distinct individuals in Wikidata known to hold the role
# and number sourced to the FCO database

select distinct ?item ?itemLabel ?count ?importedcount where
{
  { ?item wdt:P31 wd:Q18115939 . } union { ?item wdt:P31 wd:Q56760832 } . # ambassador or high commissioner

  optional { select distinct ?item (count(distinct ?holder) as ?count) 
             where
                    {
                      { ?item wdt:P31 wd:Q18115939 . } union { ?item wdt:P31 wd:Q56760832 } .
                      ?holder p:P39 ?positionStatement . ?positionStatement ps:P39 ?item . 
                    } group by ?item
            }
  optional { select distinct ?item (count(distinct ?importedholder) as ?importedcount) 
             where
                    {
                      { ?item wdt:P31 wd:Q18115939 . } union { ?item wdt:P31 wd:Q56760832 } .
                      ?importedholder p:P39 ?positionStatement . ?positionStatement ps:P39 ?item . 
                          ?positionStatement prov:wasDerivedFrom ?ref . ?ref pr:P248 wd:Q56808876 .
                    } group by ?item
            }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?count"):::projected v2("?holder") v7("?importedcount"):::projected v5("?importedholder") v1("?item"):::projected v3("?positionStatement") v6("?ref") c2(["wd:Q18115939"]):::iri c10(["bd:serviceParam"]):::iri c3(["wd:Q56760832"]):::iri c8(["wd:Q56808876"]):::iri c12(["#91;AUTO_LANGUAGE#93;,en"]):::literal subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P31"--> c3 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P31"--> c2 end union0r <== or ==> union0l end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; v1 -."p:direct/P31".-> c3 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P31"--> c2 end union1r <== or ==> union1l end v2 --"p:P39"--> v3 v3 --"p:statement/P39"--> v1 bind1[/"count(?holder)"/] v2 --o bind1 bind1 --as--o v4 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; subgraph union2[" Union "] subgraph union2l[" "] style union2l fill:#abf,stroke-dasharray: 3 3; v1 -."p:direct/P31".-> c3 end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P31"--> c2 end union2r <== or ==> union2l end v5 --"p:P39"--> v3 v3 --"p:statement/P39"--> v1 v3 --"prov:wasDerivedFrom"--> v6 v6 --"p:reference/P248"--> c8 bind3[/"count(?importedholder)"/] v5 --o bind3 bind3 --as--o v7 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 end