query-a44e132ed188185765b29d99274cb271
TODO
Use at
- https://query.wikidata.org/sparql
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
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#>
# This query identifies MPs and the final ends to their careers (Andrew Gray)
# It looks for
# - the last time someone left office as an MP
# - what the cause of their leaving office was
#defaultView:Timeline
SELECT DISTINCT ?item ?itemLabel ?constituencyLabel ?causeLabel ?end {
# find all MP positions
?membership wdt:P279 wd:Q16707842 .
# and people who held such a position
?item p:P39 ?positionStatement . ?positionStatement ps:P39 ?membership .
OPTIONAL { ?positionStatement pq:P768 ?constituency . } # constituency if known
OPTIONAL { ?positionStatement pq:P4100 ?party . } # party if known
?positionStatement pq:P580 ?start . # all members who have a start date (need to block out any without full dates)
?positionStatement pq:P582 ?end . # all members who have an end date
?positionStatement pq:P1534 ?cause . # cause of leaving office
FILTER (?end >= "1950-02-23T00:00:00Z"^^xsd:dateTime) . # everyone whose term ended after the 1950 general election
{?positionStatement pq:P1534 wd:Q52112831 } union #
{?positionStatement pq:P1534 wd:Q46993416 } union #
{?positionStatement pq:P1534 wd:Q46992747 } # filter to three special cases
FILTER NOT EXISTS {
?membership2 wdt:P279 wd:Q16707842 .
?item p:P39 ?positionStatement2 .
?positionStatement2 ps:P39 ?membership2 .
?positionStatement2 pq:P580 ?start2 .
FILTER (?start2 >= ?end) .
}
# filter out any where they came back to office at a later date
SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
}
order by ?end
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v11("?cause")
v8("?constituency")
v1("?end"):::projected
v4("?item"):::projected
v6("?membership")
v3("?membership2")
v9("?party")
v7("?positionStatement")
v5("?positionStatement2")
v10("?start")
v2("?start2")
c2(["wd:Q16707842"]):::iri
c17(["en"]):::literal
c15(["bd:serviceParam"]):::iri
c11(["wd:Q52112831"]):::iri
c12(["wd:Q46993416"]):::iri
c13(["wd:Q46992747"]):::iri
f0[["not "]]
subgraph f0e0["Exists Clause"]
e0f0[["?start2 >= ?end"]]
e0f0 --> e0v1
e0f0 --> e0v2
e0v3 --"p:direct/P279"--> e0c2
e0v4 --"p:P39"--> e0v5
e0v5 --"p:statement/P39"--> e0v3
e0v5 --"p:qualifier/P580"--> e0v1
e0v2("?end"):::projected
e0v4("?item"):::projected
e0v3("?membership2"):::projected
e0v5("?positionStatement2"):::projected
e0v1("?start2"):::projected
e0c2(["wd:Q16707842"]):::iri
end
f0--EXISTS--> f0e0
f0 --> v2
f0 --> v1
f0 --> v3
f0 --> c1
f0 --> c2
f0 --> v4
f0 --> c3
f0 --> v5
f0 --> c4
f0 --> c5
f1[["?start2 >= ?end"]]
f1 --> v2
f1 --> v1
v3 --"p:direct/P279"--> c2
v4 --"p:P39"--> v5
v5 --"p:statement/P39"--> v3
v5 --"p:qualifier/P580"--> v2
f2[["?end >= '1950-02-23T00:00:00Z^^xsd:dateTime'"]]
f2 --> v1
v6 --"p:direct/P279"--> c2
v4 --"p:P39"--> v7
v7 --"p:statement/P39"--> v6
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:qualifier/P768".-> v8
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:qualifier/P4100".-> v9
end
v7 --"p:qualifier/P580"--> v10
v7 --"p:qualifier/P582"--> v1
v7 --"p:qualifier/P1534"--> v11
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
v7 --"p:qualifier/P1534"--> c13
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v7 --"p:qualifier/P1534"--> c12
end
union1r <== or ==> union1l
end
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v7 --"p:qualifier/P1534"--> c11
end
union0r <== or ==> union0l
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c15 --"wikibase:language"--> c17
end