query-fe8fcda8b50a58ec3dcb78a2c38ce1a0
(73) Map of electoral districts layered by party: successful/all candidates in the 2020 Taiwanese legislative electionNo.73 (2023.04.10T1954 created)
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#>
### Note: Cf. Nos. 29, 30, and 31.
# title of the query
#title: map of successful/all candidates' electoral districts in the 2020 Taiwanese legislative election
# viewed as map, layered by ?partyLabel (also viewable as table and image grid)
#defaultView:Map{"layer":"?partyLabel"}
SELECT DISTINCT ?candidate ?candidateLabel ?resultLabel ?ranking ?jurisdictionLabel ?coord ?partyLabel ?candidate_number
?votes_received ?percentage ?image ?genderLabel ?birth_date ?age
WHERE {
# ?candidate is instance of (P31) human (Q5)
?candidate wdt:P31 wd:Q5;
# ?candidate's "candidacy in election" (P3602) statement is ?x_election
p:P3602 ?x_election.
# ?x_election's value is ?election
?x_election ps:P3602 ?election.
# ?election is part of (P361) [OneOrMorePath (+)] 2020 Taiwanese legislative election (Q60287334)
?election wdt:P361+ wd:Q60287334;
# ?election is instance of (P31) "subclass of (P279)" [ZeroOrMorePath (*)] election in a constituency (Q112611340)
wdt:P31/wdt:P279* wd:Q112611340
# optional: ?x_election's qualifier "results" (P2501) is ?result
OPTIONAL {?x_election pq:P2501 ?result}
# ?result is elected (Q20826785)
### Note: This line can be removed so that ALL, not only SUCCESSFUL, candidates are queried.
FILTER (?result = wd:Q20826785)
# optional: ?election applies to jurisdiction (P1001): ?jurisdiction
OPTIONAL {?election wdt:P1001 ?jurisdiction
# optional: ?jurisdiction's coordinate location (P625) is ?coord
OPTIONAL {?jurisdiction wdt:P625 ?coord} }
# optional: ?x_election's qualifier "represents" (P1268) is ?party
OPTIONAL {?x_election pq:P1268 ?party}
# optional: ?x_election's qualifier "ranking" (P1352) is ?ranking
OPTIONAL {?x_election pq:P1352 ?ranking}
# optional: ?x_election's qualifier "candidate number" (P4243) is ?candidate_number
OPTIONAL {?x_election pq:P4243 ?candidate_number}
# optional: ?x_election's qualifier "votes received" (P1111) is ?votes_received
OPTIONAL {?x_election pq:P1111 ?votes_received}
# optional: ?election's total valid votes (P1697) is ?total_valid_votes
OPTIONAL {?election wdt:P1697 ?total_valid_votes}
# calculate the percentage, and bind the percentage as ?percentage
BIND(?votes_received/?total_valid_votes*100 AS ?percentage)
# optional: ?candidate's image (P18) is ?image
OPTIONAL {?candidate wdt:P18 ?image}
# optional: ?candidate's gender (P21) is ?gender
OPTIONAL {?candidate wdt:P21 ?gender}
# optional: ?candidate's date of birth (P569) is ?birth_date
OPTIONAL {?candidate wdt:P569 ?birth_date}
# optional: ?election's point in time (P585) is ?election_date
OPTIONAL {?election wdt:P585 ?election_date}
# use IF to calculate the age, and bind the age as ?age
BIND(IF(MONTH(?election_date)>MONTH(?birth_date) || (MONTH(?election_date)=MONTH(?birth_date) && DAY(?election_date)>=DAY(?birth_date)),
YEAR(?election_date)-YEAR(?birth_date), YEAR(?election_date)-YEAR(?birth_date)-1) AS ?age)
# show label in auto language as default, and English when no default label exists
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
# order layer by ?partyLabel
ORDER BY ?partyLabel
Query found at
- https://www.wikidata.org/wiki/User:Neo-Jay/Query
- https://www.wikidata.org/wiki/User:Neo-Jay/Query/1.1
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v18("?age"):::projected
v16("?birth_date"):::projected
v3("?candidate"):::projected
v10("?candidate_number"):::projected
v7("?coord"):::projected
v5("?election")
v17("?election_date")
v15("?gender")
v14("?image"):::projected
v6("?jurisdiction")
v8("?party")
v1("?partyLabel"):::projected
v13("?percentage"):::projected
v9("?ranking"):::projected
v2("?result")
v12("?total_valid_votes")
v11("?votes_received"):::projected
v4("?x_election")
a1((" "))
c23(["bd:serviceParam"]):::iri
c3(["wd:Q5"]):::iri
c7(["wd:Q60287334"]):::iri
c25(["#91;AUTO_LANGUAGE#93;,en"]):::literal
c9(["wd:Q112611340"]):::iri
f0[["?result = 'wd:Q20826785'"]]
f0 --> v2
v3 --"p:direct/P31"--> c3
v3 --"p:P3602"--> v4
v4 --"p:statement/P3602"--> v5
v5 --"p:direct/P361"--> c7
v5 --"p:direct/P31"--> a1
a1 --"p:direct/P279"--> c9
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:qualifier/P2501".-> v2
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v5 -."p:direct/P1001".-> v6
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v6 -."p:direct/P625".-> v7
end
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:qualifier/P1268".-> v8
end
subgraph optional4["(optional)"]
style optional4 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:qualifier/P1352".-> v9
end
subgraph optional5["(optional)"]
style optional5 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:qualifier/P4243".-> v10
end
subgraph optional6["(optional)"]
style optional6 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:qualifier/P1111".-> v11
end
subgraph optional7["(optional)"]
style optional7 fill:#bbf,stroke-dasharray: 5 5;
v5 -."p:direct/P1697".-> v12
end
bind1[/"?votes_received / ?total_valid_votes * '100^^xsd:integer'"/]
v11 --o bind1
v12 --o bind1
bind1 --as--o v13
subgraph optional8["(optional)"]
style optional8 fill:#bbf,stroke-dasharray: 5 5;
v3 -."p:direct/P18".-> v14
end
subgraph optional9["(optional)"]
style optional9 fill:#bbf,stroke-dasharray: 5 5;
v3 -."p:direct/P21".-> v15
end
subgraph optional10["(optional)"]
style optional10 fill:#bbf,stroke-dasharray: 5 5;
v3 -."p:direct/P569".-> v16
end
subgraph optional11["(optional)"]
style optional11 fill:#bbf,stroke-dasharray: 5 5;
v5 -."p:direct/P585".-> v17
end
bind2[/"if((month-from-dateTime(?election_date) > month-from-dateTime(?birth_date) || month-from-dateTime(?election_date) = month-from-dateTime(?birth_date)day-from-dateTime(?election_date) >= day-from-dateTime(?birth_date)),year-from-dateTime(?election_date) - year-from-dateTime(?birth_date),year-from-dateTime(?election_date) - year-from-dateTime(?birth_date) + '-1^^xsd:integer')"/]
v17 --o bind2
v16 --o bind2
bind2 --as--o v18
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c23 --"wikibase:language"--> c25
end