query-0890849d8e164f354773593129e11fb8

rq turtle/ttl

All former MPs alive on election day (Andrew Gray)

note that election is explicitly hardcoded in three places because MINUS clauses are odd

SELECT distinct ?item ?itemLabel ?died ?born { ?item p:P39 ?positionStatement . ?positionStatement ps:P39 ?membership . ?membership wdt:P279 wd:Q16707842 . ?positionStatement pq:P582 ?end . FILTER (?end < ?electionday) . wd:Q3586935 wdt:P585 ?electionday . # find all MPs who served any terms in office before this date (nb will include any unknown end dates) MINUS { ?item wdt:P570 ?died . FILTER (?died < ?electionday) . wd:Q3586935 wdt:P585 ?electionday } MINUS { ?item wdt:P570 ?died . FILTER isBLANK(?died) . } # remove all who died before this date, or have a date of death unknown MINUS { ?item p:P39 ?positionStatement2 . ?positionStatement2 ps:P39 ?membership2 . ?membership2 wdt:P279 wd:Q16707842 . ?positionStatement2 pq:P2715 wd:Q3586935 . } # remove all those who were elected at this specific election and thus were an MP on that day optional { ?item wdt:P569 ?born } . SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' } }

Use at

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#>
# All former MPs alive on election day (Andrew Gray)
# note that election is explicitly hardcoded in three places because MINUS clauses are odd

SELECT distinct ?item ?itemLabel ?died ?born
{
  ?item p:P39 ?positionStatement . ?positionStatement ps:P39 ?membership . ?membership wdt:P279 wd:Q16707842 .
  ?positionStatement pq:P582 ?end . FILTER (?end < ?electionday) . wd:Q3586935 wdt:P585 ?electionday .
  # find all MPs who served any terms in office before this date (nb will include any unknown end dates)
  MINUS { ?item wdt:P570 ?died . FILTER (?died < ?electionday) . wd:Q3586935 wdt:P585 ?electionday }
  MINUS { ?item wdt:P570 ?died . FILTER isBLANK(?died) . }
  # remove all who died before this date, or have a date of death unknown
  MINUS { ?item p:P39 ?positionStatement2 . ?positionStatement2 ps:P39 ?membership2 .
         ?membership2 wdt:P279 wd:Q16707842 . ?positionStatement2 pq:P2715 wd:Q3586935 . }
  # remove all those who were elected at this specific election and thus were an MP on that day
  optional { ?item wdt:P569 ?born } .
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v9("?born"):::projected v6("?died"):::projected v2("?electionday") v1("?end") v3("?item"):::projected v5("?membership") v8("?membership2") v4("?positionStatement") v7("?positionStatement2") c6(["wd:Q3586935"]):::iri c4(["wd:Q16707842"]):::iri c14(["en"]):::literal c12(["bd:serviceParam"]):::iri f0[["?end < ?electionday"]] f0 --> v1 f0 --> v2 v3 --"p:P39"--> v4 v4 --"p:statement/P39"--> v5 v5 --"p:direct/P279"--> c4 v4 --"p:qualifier/P582"--> v1 c6 --"p:direct/P585"--> v2 subgraph minus1["MINUS"] style minus1 stroke-width:6px,fill:pink,stroke:red; f2[["?died < ?electionday"]] f2 --> v6 f2 --> v2 v3 --"p:direct/P570"--> v6 c6 --"p:direct/P585"--> v2 end subgraph minus3["MINUS"] style minus3 stroke-width:6px,fill:pink,stroke:red; f4[["isBlank(?died)"]] f4 --> v6 v3 --"p:direct/P570"--> v6 end subgraph minus5["MINUS"] style minus5 stroke-width:6px,fill:pink,stroke:red; v3 --"p:P39"--> v7 v7 --"p:statement/P39"--> v8 v8 --"p:direct/P279"--> c4 v7 --"p:qualifier/P2715"--> c6 end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:direct/P569".-> v9 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c12 --"wikibase:language"--> c14 end