query-bb7cbb7ec0397de146b245cd700b1bdc
Number of female MPs and of ones named "John" over time
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#>
# UK parliaments with count of Johns and count of women
#defaultView:LineChart
SELECT ?date ?count ?label WHERE {
# get ?johns and ?women
{
# count of Johns in each parliament
SELECT ?parliament (COUNT(DISTINCT ?mp) AS ?johns) WHERE {
{
# all MPs with their associated parliament
SELECT DISTINCT ?mp ?parliament WHERE {
?mp wdt:P31 wd:Q5.
{
# new data model: position held – Member of the nth Parliament of the United Kingdom
?mp p:P39/ps:P39 ?position.
?position wdt:P279 wd:Q16707842;
p:P279/pq:P2937|wdt:P2937 ?parliament.
} UNION {
# old data model: member of – nth Parliament of the United Kingdom
?mp p:P463/ps:P463 ?parliament.
?parliament wdt:P31 wd:Q21094819.
}
}
}
?mp wdt:P735 wd:Q4925477.
}
GROUP BY ?parliament
}
{
# count of women in each parliament
SELECT ?parliament (COUNT(DISTINCT ?mp) AS ?women) WHERE {
{
# all MPs with their associated parliament
SELECT DISTINCT ?mp ?parliament WHERE {
?mp wdt:P31 wd:Q5.
{
# new data model: position held – Member of the nth Parliament of the United Kingdom
?mp p:P39/ps:P39 ?position.
?position wdt:P279 wd:Q16707842;
p:P279/pq:P2937|wdt:P2937 ?parliament.
} UNION {
# old data model: member of – nth Parliament of the United Kingdom
?mp p:P463/ps:P463 ?parliament.
?parliament wdt:P31 wd:Q21094819.
}
}
}
?mp wdt:P21/wdt:P279* wd:Q6581072. # (P279*: include transgender females – non yet, but will probably happen in the future)
}
GROUP BY ?parliament
}
# fan out single result
# ?parliament ?johns ?women
# into two results
# ?parliament "Johns" ?johns
# ?parliament "women" ?women
# so the line chart works
VALUES ?label { "Johns"@en "women"@en }
BIND(IF(?label = "Johns"@en, ?johns, ?women) AS ?count)
# get parliament date for the chart
?parliament wdt:P571|wdt:P580 ?date.
# add labels
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?date
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v8("?count"):::projected
v1("?date"):::projected
v5("?johns")
v7("?label"):::projected
v2("?mp")
v4("?parliament")
v3("?position")
v6("?women")
a1((" "))
a2((" "))
a3((" "))
a4((" "))
a5((" "))
a6((" "))
a7((" "))
c6(["wd:Q16707842"]):::iri
c16(["wd:Q6581072"]):::iri
c12(["wd:Q21094819"]):::iri
c20(["bd:serviceParam"]):::iri
c14(["wd:Q4925477"]):::iri
c2(["wd:Q5"]):::iri
c22(["#91;AUTO_LANGUAGE#93;,en"]):::literal
v2 --"p:direct/P31"--> c2
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v2 --"p:P463"--> a3
a3 --"p:statement/P463"--> v4
v4 --"p:direct/P31"--> c12
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v2 --"p:P39"--> a1
a1 --"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"--> a2
a2 --"p:qualifier/P2937"--> v4
end
union1r <== or ==> union1l
end
end
union0r <== or ==> union0l
end
v2 --"p:direct/P735"--> c14
bind1[/"count(?mp)"/]
v2 --o bind1
bind1 --as--o v5
v2 --"p:direct/P31"--> c2
subgraph union2[" Union "]
subgraph union2l[" "]
style union2l fill:#abf,stroke-dasharray: 3 3;
v2 --"p:P463"--> a6
a6 --"p:statement/P463"--> v4
v4 --"p:direct/P31"--> c12
end
subgraph union2r[" "]
style union2r fill:#abf,stroke-dasharray: 3 3;
v2 --"p:P39"--> a4
a4 --"p:statement/P39"--> v3
v3 --"p:direct/P279"--> c6
subgraph union3[" Union "]
subgraph union3l[" "]
style union3l fill:#abf,stroke-dasharray: 3 3;
v3 --"p:direct/P2937"--> v4
end
subgraph union3r[" "]
style union3r fill:#abf,stroke-dasharray: 3 3;
v3 --"p:P279"--> a5
a5 --"p:qualifier/P2937"--> v4
end
union3r <== or ==> union3l
end
end
union2r <== or ==> union2l
end
v2 --"p:direct/P21"--> a7
a7 --"p:direct/P279"--> c16
bind3[/"count(?mp)"/]
v2 --o bind3
bind3 --as--o v6
bind4[/VALUES ?label/]
bind4-->v7
bind40([sJohns^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>"])
bind40 --> bind4
bind41([swomen^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>"])
bind41 --> bind4
bind5[/"if(?label = sJohns^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>',?johns,?women)"/]
v7 --o bind5
v5 --o bind5
v6 --o bind5
bind5 --as--o v8
subgraph union4[" Union "]
subgraph union4l[" "]
style union4l fill:#abf,stroke-dasharray: 3 3;
v4 --"p:direct/P580"--> v1
end
subgraph union4r[" "]
style union4r fill:#abf,stroke-dasharray: 3 3;
v4 --"p:direct/P571"--> v1
end
union4r <== or ==> union4l
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c20 --"wikibase:language"--> c22
end