query-ff53e17b9a609b5736f46a4e4580870d

rq turtle/ttl

by-elections in the 1979-83 Parliament

this query finds all MPs who had another MP sit for the same seat in the same Parliament

if they started after the first one's term ended, it guesses they were matched

it then puts them in the correct order, counts the gap in days

and checks for a couple of false-positive risks (split terms and suspensions)

SELECT DISTINCT ?previousMPLabel ?constituencyLabel ?end ?causeLabel ?days ?electionLabel ?start ?newMPLabel { ?newMP p:P39 ?positionStatement . ?positionStatement ps:P39 wd:Q41582619 . ?positionStatement pq:P768 ?constituency . ?positionStatement pq:P580 ?start . ?positionStatement pq:P2715 ?election . # this makes sure a by-election happened and not just a change of affiliation, etc

?previousMP p:P39 ?positionStatement2 . ?positionStatement2 ps:P39 wd:Q41582619 . ?positionStatement2 pq:P768 ?constituency . # restricts it to the same seat
?positionStatement2 pq:P582 ?end . OPTIONAL { ?positionStatement2 pq:P1534 ?cause . } # in case cause not stated

FILTER (?start > ?end) . # make sure they're in the right order! bind((?start-?end) as ?days) . # find how long the gap was

SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' } } ORDER BY ?constituencyLabel

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
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#>
# by-elections in the 1979-83 Parliament
# this query finds all MPs who had another MP sit for the same seat in the same Parliament
# if they started after the first one's term ended, it guesses they were matched
# it then puts them in the correct order, counts the gap in days
# and checks for a couple of false-positive risks (split terms and suspensions)
SELECT DISTINCT ?previousMPLabel ?constituencyLabel ?end ?causeLabel ?days ?electionLabel ?start ?newMPLabel
 {
 ?newMP p:P39 ?positionStatement .
 ?positionStatement ps:P39 wd:Q41582619 . 
 ?positionStatement pq:P768 ?constituency .
 ?positionStatement pq:P580 ?start .
 ?positionStatement pq:P2715 ?election . # this makes sure a by-election happened and not just a change of affiliation, etc

 ?previousMP p:P39 ?positionStatement2 .
 ?positionStatement2 ps:P39 wd:Q41582619 . 
 ?positionStatement2 pq:P768 ?constituency . # restricts it to the same seat  
 ?positionStatement2 pq:P582 ?end . 
 OPTIONAL { ?positionStatement2 pq:P1534 ?cause . } # in case cause not stated

 FILTER (?start > ?end) . # make sure they're in the right order!
 bind((?start-?end) as ?days) . # find how long the gap was

 SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
}
ORDER BY ?constituencyLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v10("?cause") v6("?constituency") v1("?constituencyLabel"):::projected v11("?days"):::projected v7("?election") v3("?end"):::projected v4("?newMP") v5("?positionStatement") v9("?positionStatement2") v8("?previousMP") v2("?start"):::projected c10(["bd:serviceParam"]):::iri c12(["en"]):::literal c3(["wd:Q41582619"]):::iri f0[["?start > ?end"]] f0 --> v2 f0 --> v3 v4 --"p:P39"--> v5 v5 --"p:statement/P39"--> c3 v5 --"p:qualifier/P768"--> v6 v5 --"p:qualifier/P580"--> v2 v5 --"p:qualifier/P2715"--> v7 v8 --"p:P39"--> v9 v9 --"p:statement/P39"--> c3 v9 --"p:qualifier/P768"--> v6 v9 --"p:qualifier/P582"--> v3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v9 -."p:qualifier/P1534".-> v10 end bind1[/"?start - ?end"/] v2 --o bind1 v3 --o bind1 bind1 --as--o v11 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 end