query-106cdd6b190b7aa2169d40bbce5a9c99

rq turtle/ttl

Ergebnisse der Bundestagswahl 2017

Use at

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 rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pqv: <http://www.wikidata.org/prop/qualifier/value/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:Map{"hide":["?shape", "?layer", "?rgb"]}
SELECT ?district ?districtLabel ?mdl ?mdlLabel ?party (?partyLabel AS ?layer) ?votesPercentage ?rgb ?shape WHERE {
  ?district wdt:P3896 ?shape;
            p:P991 [
              ps:P991 ?mdl;
              pq:P2937 wd:Q41079386;
              pq:P1268 ?party;
              pqv:P1111 [ wikibase:quantityAmount ?votesPercentage; wikibase:quantityUnit wd:Q11229 ]
            ];
  BIND(xsd:integer(?districtNumberString) AS ?districtNumber)
  ?party wdt:P462?/wdt:P465 ?rgbOriginal.
  BIND(IF(?votesPercentage >= (100/2),
          ?rgbOriginal,
          IF(?votesPercentage >= (100/3),
             REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(?rgbOriginal, "80(..)(..)", "A0$1$2"), "(..)80(..)", "$1A0$2"), "(..)(..)80", "$1$2A0"), "00(..)(..)", "40$1$2"), "(..)00(..)", "$140$2"), "(..)(..)00", "$1$240"),
             REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(?rgbOriginal, "80(..)(..)", "C0$1$2"), "(..)80(..)", "$1C0$2"), "(..)(..)80", "$1$2C0"), "00(..)(..)", "80$1$2"), "(..)00(..)", "$180$2"), "(..)(..)00", "$1$280")
            )
         ) AS ?rgb)
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
    ?district rdfs:label ?districtLabel .
    ?party rdfs:label ?partyLabel .
    ?mdl rdfs:label ?mdlLabel .
  }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?district"):::projected v9("?districtLabel"):::projected v6("?districtNumber") v12("?layer") v3("?mdl"):::projected v11("?mdlLabel"):::projected v4("?party"):::projected v10("?partyLabel"):::projected v8("?rgb"):::projected v7("?rgbOriginal") v2("?shape"):::projected v5("?votesPercentage"):::projected a1((" ")) a2((" ")) a3((" ")) c4(["wd:Q41079386"]):::iri c14(["bd:serviceParam"]):::iri c8(["wd:Q11229"]):::iri c16(["#91;AUTO_LANGUAGE#93;,en"]):::literal v1 --"p:direct/P3896"--> v2 a1 --"p:statement/P991"--> v3 a1 --"p:qualifier/P2937"--> c4 a1 --"p:qualifier/P1268"--> v4 a2 --"wikibase:quantityAmount"--> v5 a2 --"wikibase:quantityUnit"--> c8 a1 --"p:qualifier/value/P1111"--> a2 v1 --"p:P991"--> a1 bind0[/"http://www.w3.org/2001/XMLSchema#integer(?districtNumberString)"/] null --o bind0 bind0 --as--o v6 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v4 --"p:direct/P462"--> a3 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; end union0r <== or ==> union0l end a3 --"p:direct/P465"--> v7 bind1[/"if(?votesPercentage >= '100^^xsd:integer' / '2^^xsd:integer',?rgbOriginal,if(?votesPercentage >= '100^^xsd:integer' / '3^^xsd:integer',replace(replace(replace(replace(replace(replace(?rgbOriginal,'80(..)(..)','A0$1$2'),'(..)80(..)','$1A0$2'),'(..)(..)80','$1$2A0'),'00(..)(..)','40$1$2'),'(..)00(..)','$140$2'),'(..)(..)00','$1$240'),replace(replace(replace(replace(replace(replace(?rgbOriginal,'80(..)(..)','C0$1$2'),'(..)80(..)','$1C0$2'),'(..)(..)80','$1$2C0'),'00(..)(..)','80$1$2'),'(..)00(..)','$180$2'),'(..)(..)00','$1$280')))"/] v5 --o bind1 v7 --o bind1 bind1 --as--o v8 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c14 --"wikibase:language"--> c16 v1 --"rdfs:label"--> v9 v4 --"rdfs:label"--> v10 v3 --"rdfs:label"--> v11 end bind2[/"?partyLabel"/] v10 --o bind2 bind2 --as--o v12