query-971109a6c2c93c72bd1b8d0e61d16bf5
Party breakdown on a single date
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 rdfs: <http://www.w3.org/2000/01/rdf-schema#>
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#>
# # # generate all members serving on a specific date
#
# see https://www.wikidata.org/wiki/Wikidata:WikiProject_British_Politicians
# as of Feb 2019 this query will work comprehensively for any date since the 1886 election
# including, where known, constituency, party, start & end dates, election, & reason term ended
#
# 1886 onwards = data precise to the day (a few minor exceptions wrt resignation dates etc)
# (taken from Historic Hansard/MySociety then manually cleaned & validated)
# 1832-1886 = data from Historic Hansard but not yet validated, known to be somewhat incomplete
# 1386-1421, 1509-1604 = can only say "served at some point during the term" so
# there will be some ambiguities (note last column for relevant data)
#
# data for earliest periods is taken from History of Parliament but due to gaps
# in the historical record is inevitably not complete - eg 1401 has only 40 MPs.
#
# 1640-1832 is completely blank, and 1421-1509, 1604-1640 are v patchy.
#
# To run this query, change the date ("2016-05-10T00:00:00Z") below - keep the same format
# then scroll down and click the blue [>] button to the lower left
SELECT DISTINCT ?party1 ?name ?rgb (count(DISTINCT(?item)) as ?count)
where {
# # # # # # # # # # # # #
# # # # # # # # # # # # # #
# # # # # # sub in value here # # # #
bind(("2016-05-10T00:00:00Z"^^xsd:dateTime) as ?date) .
# # # # # # sub in value here # # # #
# # # # # # # # # # # # # #
# # # # # # # # # # # # #
?item p:P39 ?positionStatement . ?positionStatement ps:P39 ?term .
{ ?term wdt:P279 wd:Q16707842 } union { ?term wdt:P279 wd:Q18015642 } union { ?term wdt:P279 wd:Q18018860 }
OPTIONAL { ?positionStatement pq:P768 ?constituency . }
{ ?positionStatement pq:P4100 ?party . } # nb PARTY IS REQUIRED
OPTIONAL { ?positionStatement pq:P580 ?start . }
OPTIONAL { ?positionStatement pq:P582 ?end . }
?term wdt:P571 ?termstart . optional { ?term wdt:P576 ?termend . }
filter (COALESCE(?start, ?termstart) <= ?date ) . filter (COALESCE(?end, ?termend, NOW()) >= ?date ) .
# use qualifier dates; if not known use term dates; if no end date use now
BIND(IF(?party = wd:Q6467393, wd:Q9630 , ?party) AS ?party1) .
optional { ?party1 wdt:P465 ?rgb } . # colour if known
?party1 rdfs:label ?longname FILTER (LANG(?longname) = "en") .
OPTIONAL { ?party1 wdt:P1813 ?shortname FILTER (LANG(?shortname) = "en") }
BIND(IF(BOUND(?shortname), ?shortname, ?longname) AS ?name)
SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
} group by ?party1 ?name ?rgb order by desc(?count)
#defaultView:BubbleChart
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v12("?constituency")
v17("?count")
v9("?date")
v4("?end")
v9("?item"):::projected
v2("?longname")
v16("?name"):::projected
v13("?party")
v14("?party1"):::projected
v10("?positionStatement")
v15("?rgb"):::projected
v3("?shortname")
v7("?start")
v11("?term")
v5("?termend")
v8("?termstart")
c7(["wd:Q18018860"]):::iri
c5(["wd:Q16707842"]):::iri
c1(["en"]):::literal
c18(["bd:serviceParam"]):::iri
c6(["wd:Q18015642"]):::iri
f0[["?longname = 'en'"]]
f0 --> v2
f1[["?end?termendNOW() >= ?date"]]
f1 --> v4
f1 --> v5
f1 --> v9
f2[["?start?termstart <= ?date"]]
f2 --> v7
f2 --> v8
f2 --> v9
bind3[/"'2016-05-10T00:00:00Z^^xsd:dateTime'"/]
bind3 --as--o v9
v9 --"p:P39"--> v10
v10 --"p:statement/P39"--> 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;
v11 --"p:direct/P279"--> c7
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v11 --"p:direct/P279"--> c6
end
union1r <== or ==> union1l
end
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v11 --"p:direct/P279"--> c5
end
union0r <== or ==> union0l
end
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v10 -."p:qualifier/P768".-> v12
end
v10 --"p:qualifier/P4100"--> v13
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v10 -."p:qualifier/P580".-> v7
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v10 -."p:qualifier/P582".-> v4
end
v11 --"p:direct/P571"--> v8
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v11 -."p:direct/P576".-> v5
end
bind4[/"if(?party = 'wd:Q6467393','wd:Q9630',?party)"/]
v13 --o bind4
bind4 --as--o v14
subgraph optional4["(optional)"]
style optional4 fill:#bbf,stroke-dasharray: 5 5;
v14 -."p:direct/P465".-> v15
end
v14 --"rdfs:label"--> v2
subgraph optional5["(optional)"]
style optional5 fill:#bbf,stroke-dasharray: 5 5;
v14 -."p:direct/P1813".-> v3
end
bind5[/"if(bound(?shortname),?shortname,?longname)"/]
v3 --o bind5
v2 --o bind5
bind5 --as--o v16
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c18 --"wikibase:language"--> c1
end
bind7[/"count(?item)"/]
v9 --o bind7
bind7 --as--o v17