query-909efaef89490feb793b65b503d2f81e

rq turtle/ttl

Number of person-days per party in the 2017- Parliament

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
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 ?partyLabel (sum(?duration) as ?total)
   WHERE {
     { ?mp p:P39 ?ps . ?ps ps:P39 wd:Q30524710 . ?ps pq:P580 ?start . ?ps pq:P582 ?end . 
       ?ps pq:P4100 ?party1 . 
       BIND((?end-?start) AS ?duration) }
     # period for all ended terms
     union
     { ?mp p:P39 ?ps . ?ps ps:P39 wd:Q30524710 . ?ps pq:P580 ?start .
       ?ps pq:P4100 ?party1 . 
       filter not exists { ?ps pq:P582 ?end } . BIND(floor((NOW() - ?start)) as ?duration) }
     # time elapsed in a term which is still ongoing; floor rounds down to whole days 
     BIND(IF(?party1 = wd:Q6467393, wd:Q9630 , ?party1) AS ?party) .
     # merges co-op into Labour
     SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} group by ?partyLabel order by desc(?total)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v8("?duration"):::projected v5("?end") v2("?mp") v8("?party") v6("?party1") v3("?ps") v4("?start") v9("?total") c8(["bd:serviceParam"]):::iri c3(["wd:Q30524710"]):::iri c10(["en"]):::literal subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; f0[["not "]] subgraph f0e0["Exists Clause"] e0v1 --"p:qualifier/P582"--> e0v2 e0v2("?end"):::projected e0v1("?ps"):::projected end f0--EXISTS--> f0e0 f0 --> v3 f0 --> c5 f0 --> v5 v3 --"p:qualifier/P582"--> v5 v2 --"p:P39"--> v3 v3 --"p:statement/P39"--> c3 v3 --"p:qualifier/P580"--> v4 v3 --"p:qualifier/P4100"--> v6 bind1[/"numeric-floor(NOW() - ?start)"/] v4 --o bind1 bind1 --as--o v8 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v2 --"p:P39"--> v3 v3 --"p:statement/P39"--> c3 v3 --"p:qualifier/P580"--> v4 v3 --"p:qualifier/P582"--> v5 v3 --"p:qualifier/P4100"--> v6 bind2[/"?end - ?start"/] v5 --o bind2 v4 --o bind2 bind2 --as--o v8 end union0r <== or ==> union0l end bind3[/"if(?party1 = 'wd:Q6467393','wd:Q9630',?party1)"/] v6 --o bind3 bind3 --as--o v8 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 end bind5[/"sum(?duration)"/] v8 --o bind5 bind5 --as--o v9