query-1d8294df8a0961faeb5bebe97f907fbb
TODO
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 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 ?election ?electionLabel ?electiondate ?members ?veterans ?held_at_dissolution
WHERE {
{ SELECT ?election ?electiondate (count(distinct ?item) as ?members) where
{ {
SELECT DISTINCT ?item ?membership ?election ?electiondate ?membership2 ?positionStatement2 ?reason WHERE {
# find all general elections and their date
?election wdt:P31 wd:Q15283424 . ?election wdt:P585 ?electiondate .
filter (?electiondate >= "1832-01-01T00:00:00Z"^^xsd:dateTime) . # throttle to post-1990
# item holds a term which began with the election
?item p:P39 ?positionStatement . ?positionStatement ps:P39 ?membership .
?membership wdt:P2715 ?election . ?positionStatement pq:P2715 ?election .
OPTIONAL {
# find other positions held
?item p:P39 ?positionStatement2 .
?positionStatement2 ps:P39 ?membership2 .
?positionStatement2 pq:P580 ?start . filter ( ?start < ?electiondate ) .
?membership2 wdt:P279 wd:Q16707842 .
optional {?positionStatement2 pq:P1534 ?reason .}
# ... where the term which preceded that one
# FILTER EXISTS {?membership wdt:P155 ?membership2} .
}
}
}.
} group by ?election ?electiondate
}
{ SELECT ?election ?electiondate (count(distinct ?item) as ?veterans) where
{ {
SELECT DISTINCT ?item ?membership ?election ?electiondate ?membership2 ?positionStatement2 ?reason WHERE {
# find all general elections and their date
?election wdt:P31 wd:Q15283424 . ?election wdt:P585 ?electiondate .
filter (?electiondate >= "1832-01-01T00:00:00Z"^^xsd:dateTime) . # throttle to post-1990
# item holds a term which began with the election
?item p:P39 ?positionStatement . ?positionStatement ps:P39 ?membership .
?membership wdt:P2715 ?election . ?positionStatement pq:P2715 ?election .
OPTIONAL {
# find other positions held
?item p:P39 ?positionStatement2 .
?positionStatement2 ps:P39 ?membership2 .
?positionStatement2 pq:P580 ?start . filter ( ?start < ?electiondate ) .
?membership2 wdt:P279 wd:Q16707842 .
optional {?positionStatement2 pq:P1534 ?reason .}
# ... where the term which preceded that one
# FILTER EXISTS {?membership wdt:P155 ?membership2} .
}
}
}.
FILTER (BOUND (?membership2)) .
} group by ?election ?electiondate
}
# people who served up to dissolution of the previous term
{ SELECT ?election ?electiondate (count(distinct ?item) as ?held_at_dissolution) where
{ {
SELECT DISTINCT ?item ?membership ?election ?electiondate ?membership2 ?positionStatement2 ?reason WHERE {
# find all general elections and their date
?election wdt:P31 wd:Q15283424 . ?election wdt:P585 ?electiondate .
filter (?electiondate >= "1832-01-01T00:00:00Z"^^xsd:dateTime) . # throttle to post-1990
# item holds a term which began with the election
?item p:P39 ?positionStatement . ?positionStatement ps:P39 ?membership .
?membership wdt:P2715 ?election . ?positionStatement pq:P2715 ?election .
OPTIONAL {
# find other positions held
?item p:P39 ?positionStatement2 .
?positionStatement2 ps:P39 ?membership2 .
?positionStatement2 pq:P580 ?start . filter ( ?start < ?electiondate ) .
?membership2 wdt:P279 wd:Q16707842 .
optional {?positionStatement2 pq:P1534 ?reason .}
# ... where the term which preceded that one
# FILTER EXISTS {?membership wdt:P155 ?membership2} .
}
}
}.
FILTER (BOUND (?positionStatement2)) .
FILTER EXISTS {?membership wdt:P155 ?membership2} .
filter(?reason=wd:Q741182)
} group by ?election ?electiondate
}
SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
} order by desc(?electiondate)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?election"):::projected
v1("?electiondate"):::projected
v12("?held_at_dissolution"):::projected
v4("?item")
v10("?members"):::projected
v6("?membership")
v8("?membership2")
v5("?positionStatement")
v7("?positionStatement2")
v9("?reason")
v2("?start")
v11("?veterans"):::projected
c11(["wd:Q16707842"]):::iri
c18(["en"]):::literal
c16(["bd:serviceParam"]):::iri
c3(["wd:Q15283424"]):::iri
f0[["?electiondate >= '1832-01-01T00:00:00Z^^xsd:dateTime'"]]
f0 --> v1
v3 --"p:direct/P31"--> c3
v3 --"p:direct/P585"--> v1
v4 --"p:P39"--> v5
v5 --"p:statement/P39"--> v6
v6 --"p:direct/P2715"--> v3
v5 --"p:qualifier/P2715"--> v3
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:P39".-> v7
v7 --"p:statement/P39"--> v8
v7 --"p:qualifier/P580"--> v2
v8 --"p:direct/P279"--> c11
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:qualifier/P1534".-> v9
end
end
bind2[/"count(?item)"/]
v4 --o bind2
bind2 --as--o v10
f3[["bound(?membership2)"]]
f3 --> v8
f4[["?electiondate >= '1832-01-01T00:00:00Z^^xsd:dateTime'"]]
f4 --> v1
v3 --"p:direct/P31"--> c3
v3 --"p:direct/P585"--> v1
v4 --"p:P39"--> v5
v5 --"p:statement/P39"--> v6
v6 --"p:direct/P2715"--> v3
v5 --"p:qualifier/P2715"--> v3
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:P39".-> v7
v7 --"p:statement/P39"--> v8
v7 --"p:qualifier/P580"--> v2
v8 --"p:direct/P279"--> c11
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:qualifier/P1534".-> v9
end
end
bind6[/"count(?item)"/]
v4 --o bind6
bind6 --as--o v11
f7[["?reason = 'wd:Q741182'"]]
f7 --> v9
f8[[" "]]
subgraph f8e0["Exists Clause"]
e0v1 --"p:direct/P155"--> e0v2
e0v1("?membership"):::projected
e0v2("?membership2"):::projected
end
f8--EXISTS--> f8e0
f8 --> v6
f8 --> c14
f8 --> v8
v6 --"p:direct/P155"--> v8
f9[["bound(?positionStatement2)"]]
f9 --> v7
f10[["?electiondate >= '1832-01-01T00:00:00Z^^xsd:dateTime'"]]
f10 --> v1
v3 --"p:direct/P31"--> c3
v3 --"p:direct/P585"--> v1
v4 --"p:P39"--> v5
v5 --"p:statement/P39"--> v6
v6 --"p:direct/P2715"--> v3
v5 --"p:qualifier/P2715"--> v3
subgraph optional4["(optional)"]
style optional4 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:P39".-> v7
v7 --"p:statement/P39"--> v8
v7 --"p:qualifier/P580"--> v2
v8 --"p:direct/P279"--> c11
subgraph optional5["(optional)"]
style optional5 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:qualifier/P1534".-> v9
end
end
bind12[/"count(?item)"/]
v4 --o bind12
bind12 --as--o v12
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c16 --"wikibase:language"--> c18
end