query-fb77cabde34072d30b96d35e09858212

rq turtle/ttl

Get political alignment (P1387) as a historic line chart representing how left or right leaning the total parliament is

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 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#>
#defaultView:LineChart
SELECT (sum(?sum)/sum(?count) as ?parliamentary_average_alignment) (?time as ?date) ?positionLabel WHERE {

SELECT DISTINCT ?positionLabel ?parliament  ?time (sum(?value) as ?sum) (count(?value) as ?count) WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?member p:P39 ?mp.
  ?mp ps:P39 ?position. 
  ?position wdt:P279* wd:Q486839.
  ?position wdt:P1001 wd:Q27.                 
  ?mp pq:P2937 ?parliament.             
  ?parliament wdt:P571 ?time. 
  FILTER (?time > "1900-01-01T00:00:00+00:00"^^xsd:dateTime)   
  ?mp pq:P4100 ?group.
  ?group wdt:P1387 ?alignment.
  bind (if (?alignment = wd:Q204481, "3"^^xsd:integer, 
        if (?alignment = wd:Q76074, "2"^^xsd:integer,  
        if (?alignment = wd:Q844072, "1"^^xsd:integer, 
        if (?alignment = wd:Q6587194, "0"^^xsd:integer,
        if (?alignment = wd:Q737014, "-1"^^xsd:integer,  
        if (?alignment = wd:Q164597, "-2"^^xsd:integer,  
        if (?alignment = wd:Q1129409, "-3"^^xsd:integer, "0"^^xsd:integer))))))) as ?value) 
}                                                                                        
group by ?value ?parliament ?parliamentLabel ?time ?positionLabel
}
group by ?time ?positionLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v11("?_anon_d00291b7e9a143df8ec0be8c8ebd714c40237"):::projected v12("?_anon_d00291b7e9a143df8ec0be8c8ebd714c40238"):::projected v7("?alignment") v10("?count") v14("?date") v6("?group") v2("?member") v3("?mp") v5("?parliament") v13("?parliamentary_average_alignment") v4("?position") v9("?sum") v1("?time"):::projected v8("?value") c9(["wd:Q486839"]):::iri c11(["wd:Q27"]):::iri c3(["bd:serviceParam"]):::iri c5(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["?time > '1900-01-01T00:00:00+00:00^^xsd:dateTime'"]] f0 --> v1 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c3 --"wikibase:language"--> c5 end v2 --"p:P39"--> v3 v3 --"p:statement/P39"--> v4 v4 --"p:direct/P279"--> c9 v4 --"p:direct/P1001"--> c11 v3 --"p:qualifier/P2937"--> v5 v5 --"p:direct/P571"--> v1 v3 --"p:qualifier/P4100"--> v6 v6 --"p:direct/P1387"--> v7 bind1[/"if(?alignment = 'wd:Q204481','3^^xsd:integer',if(?alignment = 'wd:Q76074','2^^xsd:integer',if(?alignment = 'wd:Q844072','1^^xsd:integer',if(?alignment = 'wd:Q6587194','0^^xsd:integer',if(?alignment = 'wd:Q737014','-1^^xsd:integer',if(?alignment = 'wd:Q164597','-2^^xsd:integer',if(?alignment = 'wd:Q1129409','-3^^xsd:integer','0^^xsd:integer')))))))"/] v7 --o bind1 bind1 --as--o v8 bind4[/"sum(?value)"/] v8 --o bind4 bind4 --as--o v9 bind5[/"count(?value)"/] v8 --o bind5 bind5 --as--o v10 bind8[/"sum(?sum)"/] v9 --o bind8 bind8 --as--o v11 bind9[/"sum(?count)"/] v10 --o bind9 bind9 --as--o v12 bind10[/" / "/] null --o bind10 null --o bind10 bind10 --as--o v13 bind11[/"?time"/] v1 --o bind11 bind11 --as--o v14