query-d2fd9342912f3b030c1a728405b262bb
This query identifies MPs and the final ends to their careers
It looks for
- the last time someone left office as an MP
- what the cause of their leaving office was
SELECT DISTINCT (count (?item) as ?count) ?causeLabel { ?membership wdt:P279 wd:Q16707842 . # find all MP positions ?item p:P39 ?positionStatement . ?positionStatement ps:P39 ?membership . # and people who held such a position 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 . FILTER NOT EXISTS { ?membership2 wdt:P279 wd:Q16707842 . ?item p:P39 ?positionStatement2 . ?positionStatement2 ps:P39 ?membership2 . ?positionStatement2 pq:P580 ?start2 . optional { ?positionStatement2 pq:P582 ?end2 .} BIND(COALESCE(?end2, ?start2) AS ?check) . filter (?check > ?end) } # filter out any where they came back to office at a later date # the COALESCE form is weird but catches any that had two overlapping final terms starting on different dates # which does sometimes happen for last term "returned in two places" SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' } } GROUP BY ?causeLabel ORDER BY ?count
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#>
# This query identifies MPs and the final ends to their careers
# It looks for
# - the last time someone left office as an MP
# - what the cause of their leaving office was
SELECT DISTINCT (count (?item) as ?count) ?causeLabel
{
?membership wdt:P279 wd:Q16707842 . # find all MP positions
?item p:P39 ?positionStatement . ?positionStatement ps:P39 ?membership . # and people who held such a position
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 .
FILTER NOT EXISTS {
?membership2 wdt:P279 wd:Q16707842 .
?item p:P39 ?positionStatement2 .
?positionStatement2 ps:P39 ?membership2 .
?positionStatement2 pq:P580 ?start2 .
optional { ?positionStatement2 pq:P582 ?end2 .}
BIND(COALESCE(?end2, ?start2) AS ?check) . filter (?check > ?end)
} # filter out any where they came back to office at a later date
# the COALESCE form is weird but catches any that had two overlapping final terms starting on different dates
# which does sometimes happen for last term "returned in two places"
SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
}
GROUP BY ?causeLabel
ORDER BY ?count