query-ab5fc9b41be781412389bf32876bb9f0
Database connectionsNumber of MPs in the ODNB, by parliament
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#>
# For a given UK parliament, find
# - how many MPs sat in it
# - how many of those have died
# - how many of those who have died are in the ODNB
# - how many *overall* are in the ODNB
# (remember the ODNB only adds people three years after their death)
#
SELECT ?start ?percent_died_in_odnb
#defaultView:LineChart
WHERE {
# get ?odnb
{
# count of ODNB entries in each parliament
SELECT ?parliament (COUNT(DISTINCT ?mp) AS ?odnb) WHERE {
{
# all MPs with their associated parliament
SELECT DISTINCT ?mp ?parliament WHERE {
?mp wdt:P31 wd:Q5.
# using the new data model - so limits how far back it goes
?mp p:P39/ps:P39 ?position .
?position wdt:P279 wd:Q16707842; p:P279/pq:P2937|wdt:P2937 ?parliament.
}
}
?mp wdt:P1415 ?odnb
}
GROUP BY ?parliament
} {
# count of members entries in each parliament
SELECT ?parliament (COUNT(DISTINCT ?mp) AS ?mps) WHERE {
?mp wdt:P31 wd:Q5.
?mp p:P39/ps:P39 ?position.
?position wdt:P279 wd:Q16707842; p:P279/pq:P2937|wdt:P2937 ?parliament.
}
GROUP BY ?parliament
} {
# count of dead MPs in each parliament
SELECT ?parliament (COUNT(DISTINCT ?mp) AS ?died) WHERE {
{
# all MPs with their associated parliament
SELECT DISTINCT ?mp ?parliament WHERE {
?mp wdt:P31 wd:Q5.
# using the new data model - so limits how far back it goes
?mp p:P39/ps:P39 ?position .
?position wdt:P279 wd:Q16707842; p:P279/pq:P2937|wdt:P2937 ?parliament.
}
}
?mp wdt:P570 ?died .
}
GROUP BY ?parliament
} BIND(?odnb AS ?odnbcount)
BIND(?mps AS ?mpcount)
BIND(ROUND(100*(?odnbcount/?mpcount)) AS ?percent_in_odnb)
BIND(?died AS ?diedcount)
BIND(ROUND(100*(?odnbcount/?diedcount)) AS ?percent_died_in_odnb)
# get parliament dates
?parliament wdt:P571|wdt:P580 ?start.
?parliament wdt:P576|wdt:P582 ?end.
# add labels
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?start
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v8("?died")
v11("?diedcount")
v13("?end")
v2("?mp")
v9("?mpcount")
v6("?mps")
v6("?odnb")
v8("?odnbcount")
v4("?parliament")
v12("?percent_died_in_odnb"):::projected
v10("?percent_in_odnb")
v3("?position")
v1("?start"):::projected
a1((" "))
a2((" "))
a3((" "))
a4((" "))
a5((" "))
a6((" "))
c6(["wd:Q16707842"]):::iri
c17(["bd:serviceParam"]):::iri
c2(["wd:Q5"]):::iri
c19(["#91;AUTO_LANGUAGE#93;,en"]):::literal
v2 --"p:direct/P31"--> c2
v2 --"p:P39"--> a1
a1 --"p:statement/P39"--> v3
v3 --"p:direct/P279"--> c6
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v3 --"p:direct/P2937"--> v4
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v3 --"p:P279"--> a2
a2 --"p:qualifier/P2937"--> v4
end
union0r <== or ==> union0l
end
v2 --"p:direct/P1415"--> v6
bind1[/"count(?mp)"/]
v2 --o bind1
bind1 --as--o v6
v2 --"p:direct/P31"--> c2
v2 --"p:P39"--> a3
a3 --"p:statement/P39"--> v3
v3 --"p:direct/P279"--> c6
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
v3 --"p:direct/P2937"--> v4
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v3 --"p:P279"--> a4
a4 --"p:qualifier/P2937"--> v4
end
union1r <== or ==> union1l
end
bind3[/"count(?mp)"/]
v2 --o bind3
bind3 --as--o v6
v2 --"p:direct/P31"--> c2
v2 --"p:P39"--> a5
a5 --"p:statement/P39"--> v3
v3 --"p:direct/P279"--> c6
subgraph union2[" Union "]
subgraph union2l[" "]
style union2l fill:#abf,stroke-dasharray: 3 3;
v3 --"p:direct/P2937"--> v4
end
subgraph union2r[" "]
style union2r fill:#abf,stroke-dasharray: 3 3;
v3 --"p:P279"--> a6
a6 --"p:qualifier/P2937"--> v4
end
union2r <== or ==> union2l
end
v2 --"p:direct/P570"--> v8
bind5[/"count(?mp)"/]
v2 --o bind5
bind5 --as--o v8
bind6[/"?odnb"/]
v6 --o bind6
bind6 --as--o v8
bind7[/"?mps"/]
v6 --o bind7
bind7 --as--o v9
bind8[/"numeric-round('100^^xsd:integer' * ?odnbcount / ?mpcount)"/]
v8 --o bind8
v9 --o bind8
bind8 --as--o v10
bind9[/"?died"/]
v8 --o bind9
bind9 --as--o v11
bind10[/"numeric-round('100^^xsd:integer' * ?odnbcount / ?diedcount)"/]
v8 --o bind10
v11 --o bind10
bind10 --as--o v12
subgraph union3[" Union "]
subgraph union3l[" "]
style union3l fill:#abf,stroke-dasharray: 3 3;
v4 --"p:direct/P580"--> v1
end
subgraph union3r[" "]
style union3r fill:#abf,stroke-dasharray: 3 3;
v4 --"p:direct/P571"--> v1
end
union3r <== or ==> union3l
end
subgraph union4[" Union "]
subgraph union4l[" "]
style union4l fill:#abf,stroke-dasharray: 3 3;
v4 --"p:direct/P582"--> v13
end
subgraph union4r[" "]
style union4r fill:#abf,stroke-dasharray: 3 3;
v4 --"p:direct/P576"--> v13
end
union4r <== or ==> union4l
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c17 --"wikibase:language"--> c19
end