query-07ce2660fdf32a5d3f809f58cff476b7

rq turtle/ttl

Wikidata entries for British ambassadors and high commissioners

all people who held at least one such position

one line per position held (so many people appear repeatedly)

start/end dates for that particular position

select distinct ?person ?personLabel ?positionLabel ?startyear ?endyear ?birthyear ?deathyear ?image ?otherpositionLabel ?otherstartyear ?otherendyear where { { ?position wdt:P31 wd:Q18115939 . } union { ?position wdt:P31 wd:Q56760832 } . # position is UK ambassador or high commissioner

?person p:P39 ?positionStatement . ?positionStatement ps:P39 ?position . # find positions they held

{ ?person wdt:P18 ?image . } .
optional { ?positionStatement pq:P580 ?start . bind(year(?start) as ?startyear) } # id start year optional { ?positionStatement pq:P582 ?end . bind(year(?end) as ?endyear) } # id end year optional { ?person wdt:P569 ?born . bind(year(?born) as ?birthyear) } # id start year optional { ?person wdt:P570 ?died . bind(year(?died) as ?deathyear) } # id end year optional { ?person p:P39 ?otherpositionStatement . ?otherpositionStatement ps:P39 ?otherposition . filter not exists { ?otherposition wdt:P31 wd:Q18115939 . } filter not exists { ?otherposition wdt:P31 wd:Q56760832 . } filter not exists { ?otherpositionStatement ps:P39 wd:Q121998 . } optional { ?otherpositionStatement pq:P580 ?otherstart . bind(year(?otherstart) as ?otherstartyear) } optional { ?otherpositionStatement pq:P580 ?otherend . bind(year(?otherend) as ?otherendyear) } }

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 pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Wikidata entries for British ambassadors and high commissioners
# all people who held at least one such position
# one line per position held (so many people appear repeatedly)
# start/end dates for that particular position

select distinct ?person ?personLabel ?positionLabel ?startyear ?endyear ?birthyear ?deathyear ?image ?otherpositionLabel ?otherstartyear ?otherendyear where
{
  { ?position wdt:P31 wd:Q18115939 . } union { ?position wdt:P31 wd:Q56760832 } . # position is UK ambassador or high commissioner

    ?person p:P39 ?positionStatement . ?positionStatement ps:P39 ?position . # find positions they held
  { ?person wdt:P18 ?image . } .  
    optional { ?positionStatement pq:P580 ?start . bind(year(?start) as ?startyear) } # id start year
    optional { ?positionStatement pq:P582 ?end . bind(year(?end) as ?endyear) } # id end year
    optional { ?person wdt:P569 ?born . bind(year(?born) as ?birthyear) } # id start year
    optional { ?person wdt:P570 ?died . bind(year(?died) as ?deathyear) } # id end year
    optional { ?person p:P39 ?otherpositionStatement . ?otherpositionStatement ps:P39 ?otherposition . 
              filter not exists { ?otherposition wdt:P31 wd:Q18115939 . } 
              filter not exists { ?otherposition wdt:P31 wd:Q56760832 . } 
              filter not exists { ?otherpositionStatement ps:P39 wd:Q121998 . }
              optional { ?otherpositionStatement pq:P580 ?otherstart . bind(year(?otherstart) as ?otherstartyear) }
              optional { ?otherpositionStatement pq:P580 ?otherend . bind(year(?otherend) as ?otherendyear) }
             }

  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; v12("?birthyear"):::projected v11("?born") v14("?deathyear"):::projected v13("?died") v9("?end") v10("?endyear"):::projected v6("?image"):::projected v17("?otherend") v18("?otherendyear"):::projected v1("?otherposition") v2("?otherpositionStatement") v15("?otherstart") v16("?otherstartyear"):::projected v4("?person"):::projected v3("?position") v5("?positionStatement") v7("?start") v8("?startyear"):::projected c2(["wd:Q18115939"]):::iri c3(["wd:Q56760832"]):::iri c13(["bd:serviceParam"]):::iri c5(["wd:Q121998"]):::iri c15(["#91;AUTO_LANGUAGE#93;,en"]):::literal subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v3 --"p:direct/P31"--> c3 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v3 --"p:direct/P31"--> c2 end union0r <== or ==> union0l end v4 --"p:P39"--> v5 v5 --"p:statement/P39"--> v3 v4 --"p:direct/P18"--> v6 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v5 -."p:qualifier/P580".-> v7 bind0[/"year-from-dateTime(?start)"/] v7 --o bind0 bind0 --as--o v8 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v5 -."p:qualifier/P582".-> v9 bind1[/"year-from-dateTime(?end)"/] v9 --o bind1 bind1 --as--o v10 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P569".-> v11 bind2[/"year-from-dateTime(?born)"/] v11 --o bind2 bind2 --as--o v12 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P570".-> v13 bind3[/"year-from-dateTime(?died)"/] v13 --o bind3 bind3 --as--o v14 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:P39".-> v2 v2 --"p:statement/P39"--> v1 subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:qualifier/P580".-> v15 bind4[/"year-from-dateTime(?otherstart)"/] v15 --o bind4 bind4 --as--o v16 end subgraph optional6["(optional)"] style optional6 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:qualifier/P580".-> v17 bind5[/"year-from-dateTime(?otherend)"/] v17 --o bind5 bind5 --as--o v18 end end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c13 --"wikibase:language"--> c15 end