query-3a9de1702f78eae19427139d929ccb40

rq turtle/ttl

(69) Geoshape map: the 2018 Taiwanese mayoral/magistrate election resultsNo.69 (2022.07.24T0748 created)

Use at

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#>
# title of the query
#title: geographic-shape map of the 2018 Taiwanese mayoral/magistrate election results
# viewed as map (also viewable as table)
# layered by ?partyLabel
#defaultView:Map{"layer":"?partyLabel"}
SELECT DISTINCT ?election ?electionLabel ?jurisdiction ?jurisdictionLabel ?geoshape ?winner ?winnerLabel ?party ?partyLabel
WHERE {
  # ?election is instance of (P31) "subclass of (P279)" [ZeroOrMorePath (*)] election (Q40231)
  ?election wdt:P31/wdt:P279* wd:Q40231;
            # ?election is part of (P361) [OneOrMorePath (+)] the 2018 Taiwanese mayoral/magistrate election (Q51167783)
            wdt:P361+ wd:Q51167783;
            # ?election's office contested (P541) is subclass of (P279) [ZeroOrMorePath (*)] head of government (Q2285706)
            wdt:P541/wdt:P279* wd:Q2285706;
            # ?election applies to jurisdiction (P1001): ?jurisdiction
            wdt:P1001 ?jurisdiction.
  # ?jurisdiction is instance of (P31) "subclass of (P279)" [ZeroOrMorePath (*)] ?x
  ?jurisdiction wdt:P31/wdt:P279* ?x
  # define ?x as special municipality of Taiwan (Q2225003) or county-level division of Taiwan (Q12083042)
  VALUES ?x {wd:Q2225003 wd:Q12083042}
  # optional: ?jurisdiction's geoshape (P3896) is ?geoshape
  OPTIONAL {?jurisdiction wdt:P3896 ?geoshape}
  # optional: ?election's "candidate" (P726) statement is ?x_winner
  OPTIONAL {?election p:P726 ?x_winner.
            # ?x_winner's value is ?winner
            ?x_winner ps:P726 ?winner;
                      # ?x_winner's qualifier "ranking" (P1352) is ?rank
                      pq:P1352 ?rank;
                      # ?x_winner's qualifier "represents" (P1352) is ?party
                      pq:P1268 ?party
            # ?rank is 1
            FILTER (?rank=1)}
  # 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

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?election"):::projected v6("?geoshape"):::projected v4("?jurisdiction"):::projected v9("?party"):::projected v1("?partyLabel"):::projected v2("?rank") v8("?winner"):::projected v6("?x") v7("?x_winner") a1((" ")) a2((" ")) a3((" ")) c4(["wd:Q40231"]):::iri c16(["bd:serviceParam"]):::iri c8(["wd:Q2285706"]):::iri c18(["#91;AUTO_LANGUAGE#93;,en"]):::literal c6(["wd:Q51167783"]):::iri v3 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c4 v3 --"p:direct/P361"--> c6 v3 --"p:direct/P541"--> a2 a2 --"p:direct/P279"--> c8 v3 --"p:direct/P1001"--> v4 v4 --"p:direct/P31"--> a3 a3 --"p:direct/P279"--> v6 bind0[/VALUES ?x/] bind0-->v6 bind00(["wd:Q2225003"]) bind00 --> bind0 bind01(["wd:Q12083042"]) bind01 --> bind0 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P3896".-> v6 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:P726".-> v7 v7 --"p:statement/P726"--> v8 v7 --"p:qualifier/P1352"--> v2 v7 --"p:qualifier/P1268"--> v9 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c16 --"wikibase:language"--> c18 end