query-83580f5a7455467bd2f6349032588a0d

rq turtle/ttl

All recently deceased MPs (ie this calendar year)

giving date of birth, last constituency, last date in Parliament, and reason for leaving

SELECT DISTINCT ?item ?itemLabel ?wikipedia ?born ?constituencyLabel ?left ?died { ?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) optional { ?positionStatement pq:P582 ?left . } ?positionStatement pq:P1534 ?cause . FILTER NOT EXISTS { ?membership2 wdt:P279 wd:Q16707842 . ?item p:P39 ?positionStatement2 . ?positionStatement2 ps:P39 ?membership2 . ?positionStatement2 pq:P580 ?start2 . FILTER (?start2 >= ?left) . } # filter out any where they came back to office at a later date ?item wdt:P570 ?died . # find all MPs who have died BIND(YEAR(NOW()) AS ?now) . FILTER (YEAR(?died) = ?now ) . # find all MPs who died this year # "BIND(YEAR(NOW())-1 AS ?now)" for last year, etc optional { ?item wdt:P569 ?born } . optional { ?wikipedia schema:about ?item . ?wikipedia schema:isPartOf https://en.wikipedia.org/. } . SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' } } order by desc(?died)

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
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#>
# All recently deceased MPs (ie this calendar year)
# giving date of birth, last constituency, last date in Parliament, and reason for leaving
SELECT DISTINCT ?item ?itemLabel ?wikipedia ?born ?constituencyLabel ?left ?died
{
 ?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)
 optional { ?positionStatement pq:P582 ?left . }
 ?positionStatement pq:P1534 ?cause .
 FILTER NOT EXISTS {
 ?membership2 wdt:P279 wd:Q16707842 .
 ?item p:P39 ?positionStatement2 . 
 ?positionStatement2 ps:P39 ?membership2 . 
 ?positionStatement2 pq:P580 ?start2 .
 FILTER (?start2 >= ?left) .  } 
 # filter out any where they came back to office at a later date
 ?item wdt:P570 ?died . 
 # find all MPs who have died
 BIND(YEAR(NOW()) AS ?now) . FILTER (YEAR(?died) = ?now ) . 
 # find all MPs who died this year
 # "BIND(YEAR(NOW())-1 AS ?now)" for last year, etc
 optional { ?item wdt:P569 ?born } . 
 optional { ?wikipedia schema:about ?item . ?wikipedia schema:isPartOf <https://en.wikipedia.org/>. } .
 SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
} order by desc(?died)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v14("?born"):::projected v13("?cause") v10("?constituency") v1("?died"):::projected v6("?item"):::projected v4("?left"):::projected v8("?membership") v5("?membership2") v14("?now") v11("?party") v9("?positionStatement") v7("?positionStatement2") v12("?start") v3("?start2") v15("?wikipedia"):::projected c2(["wd:Q16707842"]):::iri c18(["en"]):::literal c14([https://en.wikipedia.org/]):::iri c16(["bd:serviceParam"]):::iri f0[["year-from-dateTime(?died) = ?now"]] f0 --> v1 f0 --> v14 f1[["not "]] subgraph f1e0["Exists Clause"] e0f0[["?start2 >= ?left"]] e0f0 --> e0v1 e0f0 --> e0v2 e0v3 --"p:direct/P279"--> e0c2 e0v4 --"p:P39"--> e0v5 e0v5 --"p:statement/P39"--> e0v3 e0v5 --"p:qualifier/P580"--> e0v1 e0v4("?item"):::projected e0v2("?left"):::projected e0v3("?membership2"):::projected e0v5("?positionStatement2"):::projected e0v1("?start2"):::projected e0c2(["wd:Q16707842"]):::iri end f1--EXISTS--> f1e0 f1 --> v3 f1 --> v4 f1 --> v5 f1 --> c1 f1 --> c2 f1 --> v6 f1 --> c3 f1 --> v7 f1 --> c4 f1 --> c5 f2[["?start2 >= ?left"]] f2 --> v3 f2 --> v4 v5 --"p:direct/P279"--> c2 v6 --"p:P39"--> v7 v7 --"p:statement/P39"--> v5 v7 --"p:qualifier/P580"--> v3 v8 --"p:direct/P279"--> c2 v6 --"p:P39"--> v9 v9 --"p:statement/P39"--> v8 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v9 -."p:qualifier/P768".-> v10 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v9 -."p:qualifier/P4100".-> v11 end v9 --"p:qualifier/P580"--> v12 subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v9 -."p:qualifier/P582".-> v4 end v9 --"p:qualifier/P1534"--> v13 v6 --"p:direct/P570"--> v1 bind3[/"year-from-dateTime(NOW())"/] bind3 --as--o v14 subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:direct/P569".-> v14 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v15 -."schema:about".-> v6 v15 --"schema:isPartOf"--> c14 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c16 --"wikibase:language"--> c18 end