query-d92dc5232000170e68b98414e8540784
Seats represented in a given medieval Parliament, and those that may be missing data
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#>
select distinct ?seatLabel ?seat ?coord (count(distinct ?mp) as ?count) ?class ?rgb
(GROUP_CONCAT(DISTINCT ?mpn;separator=", ") AS ?names) where
{
VALUES ?term {wd:Q60576698} . # 1394 MP
{ ?mp p:P39 ?ps . ?ps ps:P39 ?term . ?ps pq:P768 ?seat . optional { ?seat wdt:P625 ?coord }
?mp rdfs:label ?mpn . filter(lang(?mpn) = "en") .
optional { ?seat wdt:P131 ?parent .
optional { ?parent wdt:P31 wd:Q1138494 . bind("county" as ?class) . bind("0000FF" as ?rgb) }
optional { ?parent wdt:P31 wd:Q98558416 . bind("county" as ?class) . bind("0000FF" as ?rgb) }
optional { ?parent wdt:P31 ?type . ?type wdt:P279* wd:Q486972 . bind("borough" as ?class) . bind("FF0000" as ?rgb) } }
} # find all MPs that year + seat types
union { ?mp2 p:P39 ?ps2 . ?ps2 ps:P39 ?s2 . ?s2 wdt:P156+ ?term .
?s2 wdt:P571 ?y2 . ?term wdt:P571 ?y1 . bind(year(?y1) - year(?y2) as ?diff) . filter (?diff <= 5) .
?ps2 pq:P768 ?seat . ?seat wdt:P625 ?coord . bind("not represented" as ?class) . bind("000000" as ?rgb) .
filter not exists { ?mp p:P39 ?ps . ?ps ps:P39 ?term . ?ps pq:P768 ?seat } }
# find all those represented at some point in previous five years
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} group by ?seat ?seatLabel ?coord ?class ?rgb
#defaultView:Map
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v17("?class"):::projected
v6("?coord"):::projected
v17("?count")
v17("?diff")
v3("?mp"):::projected
v12("?mp2")
v2("?mpn"):::projected
v18("?names")
v7("?parent")
v4("?ps")
v13("?ps2")
v17("?rgb"):::projected
v14("?s2")
v5("?seat"):::projected
v1("?term")
v10("?type")
v16("?y1")
v15("?y2")
c12(["wd:Q486972"]):::iri
c9(["wd:Q1138494"]):::iri
c17(["bd:serviceParam"]):::iri
c10(["wd:Q98558416"]):::iri
c19(["#91;AUTO_LANGUAGE#93;,en"]):::literal
bind0[/VALUES ?term/]
bind0-->v1
bind00(["wd:Q60576698"])
bind00 --> bind0
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
f1[["not "]]
subgraph f1e0["Exists Clause"]
e0v1 --"p:P39"--> e0v2
e0v2 --"p:statement/P39"--> e0v3
e0v2 --"p:qualifier/P768"--> e0v4
e0v1("?mp"):::projected
e0v2("?ps"):::projected
e0v4("?seat"):::projected
e0v3("?term"):::projected
end
f1--EXISTS--> f1e0
f1 --> v3
f1 --> c2
f1 --> v4
f1 --> c3
f1 --> v1
f1 --> c4
f1 --> v5
v3 --"p:P39"--> v4
v4 --"p:statement/P39"--> v1
v4 --"p:qualifier/P768"--> v5
f2[["?diff <= '5^^xsd:integer'"]]
f2 --> v17
v12 --"p:P39"--> v13
v13 --"p:statement/P39"--> v14
v14 --"p:direct/P156"--> v1
v14 --"p:direct/P571"--> v15
v1 --"p:direct/P571"--> v16
bind3[/"year-from-dateTime(?y1) - year-from-dateTime(?y2)"/]
v16 --o bind3
v15 --o bind3
bind3 --as--o v17
v13 --"p:qualifier/P768"--> v5
v5 --"p:direct/P625"--> v6
bind4[/"'not represented'"/]
bind4 --as--o v17
bind5[/"'000000'"/]
bind5 --as--o v17
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
f6[["?mpn = 'en'"]]
f6 --> v2
v3 --"p:P39"--> v4
v4 --"p:statement/P39"--> v1
v4 --"p:qualifier/P768"--> v5
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v5 -."p:direct/P625".-> v6
end
v3 --"rdfs:label"--> v2
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v5 -."p:direct/P131".-> v7
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:direct/P31".-> c9
bind7[/"'county'"/]
bind7 --as--o v17
bind8[/"'0000FF'"/]
bind8 --as--o v17
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:direct/P31".-> c10
bind9[/"'county'"/]
bind9 --as--o v17
bind10[/"'0000FF'"/]
bind10 --as--o v17
end
subgraph optional4["(optional)"]
style optional4 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:direct/P31".-> v10
v10 --"p:direct/P279"--> c12
bind11[/"'borough'"/]
bind11 --as--o v17
bind12[/"'FF0000'"/]
bind12 --as--o v17
end
end
end
union0r <== or ==> union0l
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c17 --"wikibase:language"--> c19
end
bind15[/"count(?mp)"/]
v3 --o bind15
bind15 --as--o v17
bind16[/"?mpn"/]
v2 --o bind16
bind16 --as--o v18