query-bc6eb7c461e5a864e76335fa9b0f2b6d
QA reportsQA - multiple start/end dates
Use at
- https://query.wikidata.org/sparql
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#>
select ?person ?personLabel ?positionLabel ?start ?end ?start2 ?end2 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
?positionStatement pq:P580 ?start . # id start year
?positionStatement pq:P582 ?end . # id end year
optional {?positionStatement pq:P580 ?start2 . filter(?start!=?start2)} # id start year
optional {?positionStatement pq:P582 ?end2 . filter(?end!=?end2)} # id end year
bind(coalesce(?start2,?end2) as ?keep)
filter (bound(?keep))
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;
v2("?end"):::projected
v3("?end2"):::projected
v9("?keep")
v7("?person"):::projected
v6("?position")
v8("?positionStatement")
v4("?start"):::projected
v5("?start2"):::projected
c2(["wd:Q18115939"]):::iri
c9(["bd:serviceParam"]):::iri
c3(["wd:Q56760832"]):::iri
c11(["#91;AUTO_LANGUAGE#93;,en"]):::literal
f0[["bound(?keep)"]]
f0 --> v9
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v6 --"p:direct/P31"--> c3
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v6 --"p:direct/P31"--> c2
end
union0r <== or ==> union0l
end
v7 --"p:P39"--> v8
v8 --"p:statement/P39"--> v6
v8 --"p:qualifier/P580"--> v4
v8 --"p:qualifier/P582"--> v2
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v8 -."p:qualifier/P580".-> v5
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v8 -."p:qualifier/P582".-> v3
end
bind1[/"?start2?end2"/]
v5 --o bind1
v3 --o bind1
bind1 --as--o v9
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c9 --"wikibase:language"--> c11
end