query-de1a9f7ffbbecb15195af972a2edc385
MPs, and the different seats they sat for
counting on label takes account of the fact that some seats are split by Wikidata
and this is slightly counterintuitive (a reader might reasonably treat them as the same place)
see eg Ian Mikardo at Reading; the constituency 1885-1950 & 1955-1974 are distinct items
if we counted by ?constituency then he would total six, but really two are the "same" seat
select ?mp ?mpLabel ?seatcount ?seats WHERE { { SELECT ?mp ?mpLabel (COUNT(DISTINCT ?constituencyLabel) AS ?seatcount) (GROUP_CONCAT(DISTINCT(?constituencyLabel); separator=", ") as ?seats) WHERE { ?position wdt:P279 wd:Q16707842. ?mp p:P39 ?positionStatement . ?positionStatement ps:P39 ?position ; pq:P768 ?constituency . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . ?mp rdfs:label ?mpLabel . ?constituency rdfs:label ?constituencyLabel } } GROUP BY ?mp ?mpLabel } filter(?seatcount >4) } order by desc(?seatcount)
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 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#>
# MPs, and the different seats they sat for
# counting on label takes account of the fact that some seats are split by Wikidata
# and this is slightly counterintuitive (a reader might reasonably treat them as the same place)
# see eg Ian Mikardo at Reading; the constituency 1885-1950 & 1955-1974 are distinct items
# if we counted by ?constituency then he would total six, but really two are the "same" seat
select ?mp ?mpLabel ?seatcount ?seats
WHERE {
{
SELECT ?mp ?mpLabel (COUNT(DISTINCT ?constituencyLabel) AS ?seatcount) (GROUP_CONCAT(DISTINCT(?constituencyLabel); separator=", ") as ?seats)
WHERE {
?position wdt:P279 wd:Q16707842.
?mp p:P39 ?positionStatement . ?positionStatement ps:P39 ?position ; pq:P768 ?constituency .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
?mp rdfs:label ?mpLabel .
?constituency rdfs:label ?constituencyLabel }
} GROUP BY ?mp ?mpLabel
}
filter(?seatcount >4)
}
order by desc(?seatcount)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v5("?constituency")
v7("?constituencyLabel")
v3("?mp"):::projected
v6("?mpLabel"):::projected
v2("?position")
v4("?positionStatement")
v8("?seatcount"):::projected
v8("?seats"):::projected
c8(["bd:serviceParam"]):::iri
c3(["wd:Q16707842"]):::iri
c10(["en"]):::literal
f0[["?seatcount > '4^^xsd:integer'"]]
f0 --> v8
v2 --"p:direct/P279"--> c3
v3 --"p:P39"--> v4
v4 --"p:statement/P39"--> v2
v4 --"p:qualifier/P768"--> v5
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c8 --"wikibase:language"--> c10
v3 --"rdfs:label"--> v6
v5 --"rdfs:label"--> v7
end
bind3[/"count(?constituencyLabel)"/]
v7 --o bind3
bind3 --as--o v8
bind4[/"?constituencyLabel"/]
v7 --o bind4
bind4 --as--o v8