query-4831df0751160e868599b231f1252df6

rq turtle/ttl

TODO

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#>
SELECT distinct ?election ?electionLabel ?members ?veterans ?held_at_dissolution


WHERE {

  { SELECT ?election (count(distinct ?item) as ?members) where 
    {  {
   SELECT DISTINCT ?item ?membership ?election ?electiondate ?membership2 ?positionStatement2 WHERE {

     # find all general elections and their date
     ?election wdt:P31 wd:Q15283424 . ?election wdt:P585 ?electiondate . 
     filter (?electiondate >= "1990-01-01T00:00:00Z"^^xsd:dateTime) .  # throttle to post-1990

     # item holds a term which began with the election
     ?item p:P39 ?positionStatement . ?positionStatement ps:P39 ?membership . 
     ?membership wdt:P2715 ?election . ?positionStatement pq:P2715 ?election . 

     OPTIONAL {
         # find other positions held
         ?item p:P39 ?positionStatement2 .
         ?positionStatement2 ps:P39 ?membership2 .

         # ... where the term which preceded that one
         FILTER EXISTS {?membership2 ^wdt:P155 ?membership} .
     }
   }
}.
    } group by ?election
  } 

  { SELECT ?election (count(distinct ?item) as ?veterans) where 
    {  {
   SELECT DISTINCT ?item ?membership ?election ?electiondate ?membership2 ?positionStatement2 WHERE {

     # find all general elections and their date
     ?election wdt:P31 wd:Q15283424 . ?election wdt:P585 ?electiondate . 
     filter (?electiondate >= "1990-01-01T00:00:00Z"^^xsd:dateTime) .  # throttle to post-1990

     # item holds a term which began with the election
     ?item p:P39 ?positionStatement . ?positionStatement ps:P39 ?membership . 
     ?membership wdt:P2715 ?election . ?positionStatement pq:P2715 ?election . 

     OPTIONAL {
         # find other positions held
         ?item p:P39 ?positionStatement2 .
         ?positionStatement2 ps:P39 ?membership2 .

         # ... where the term which preceded that one
         FILTER EXISTS {?membership2 ^wdt:P155 ?membership} .
     }
   }
}.
      FILTER (BOUND (?membership2)) .
    } group by ?election
  }

  # people who served up to dissolution of the previous term
  { SELECT ?election (count(distinct ?item) as ?held_at_dissolution) where 
    {  {
   SELECT DISTINCT ?item ?membership ?election ?electiondate ?membership2 ?positionStatement2 WHERE {

     # find all general elections and their date
     ?election wdt:P31 wd:Q15283424 . ?election wdt:P585 ?electiondate . 
     filter (?electiondate >= "1990-01-01T00:00:00Z"^^xsd:dateTime) .  # throttle to post-1990

     # item holds a term which began with the election
     ?item p:P39 ?positionStatement . ?positionStatement ps:P39 ?membership . 
     ?membership wdt:P2715 ?election . ?positionStatement pq:P2715 ?election . 

     OPTIONAL {
         # find other positions held
         ?item p:P39 ?positionStatement2 .
         ?positionStatement2 ps:P39 ?membership2 .

         # ... where the term which preceded that one
         FILTER EXISTS {?membership2 ^wdt:P155 ?membership} .
     }
   }
}.
      FILTER (BOUND (?positionStatement2)) .
#      ?positionStatement2 pq:P1534 wd:Q741182 .
    } group by ?election
  } 

  SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
} order by desc(?electiondate)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?election"):::projected v1("?electiondate") v10("?held_at_dissolution"):::projected v5("?item") v8("?members"):::projected v2("?membership") v3("?membership2") v6("?positionStatement") v7("?positionStatement2") v9("?veterans"):::projected c13(["en"]):::literal c11(["bd:serviceParam"]):::iri c4(["wd:Q15283424"]):::iri f0[["?electiondate >= '1990-01-01T00:00:00Z^^xsd:dateTime'"]] f0 --> v1 v4 --"p:direct/P31"--> c4 v4 --"p:direct/P585"--> v1 v5 --"p:P39"--> v6 v6 --"p:statement/P39"--> v2 v2 --"p:direct/P2715"--> v4 v6 --"p:qualifier/P2715"--> v4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v5 -."p:P39".-> v7 v7 --"p:statement/P39"--> v3 end bind2[/"count(?item)"/] v5 --o bind2 bind2 --as--o v8 f3[["bound(?membership2)"]] f3 --> v3 f4[["?electiondate >= '1990-01-01T00:00:00Z^^xsd:dateTime'"]] f4 --> v1 v4 --"p:direct/P31"--> c4 v4 --"p:direct/P585"--> v1 v5 --"p:P39"--> v6 v6 --"p:statement/P39"--> v2 v2 --"p:direct/P2715"--> v4 v6 --"p:qualifier/P2715"--> v4 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v5 -."p:P39".-> v7 v7 --"p:statement/P39"--> v3 end bind6[/"count(?item)"/] v5 --o bind6 bind6 --as--o v9 f7[["bound(?positionStatement2)"]] f7 --> v7 f8[["?electiondate >= '1990-01-01T00:00:00Z^^xsd:dateTime'"]] f8 --> v1 v4 --"p:direct/P31"--> c4 v4 --"p:direct/P585"--> v1 v5 --"p:P39"--> v6 v6 --"p:statement/P39"--> v2 v2 --"p:direct/P2715"--> v4 v6 --"p:qualifier/P2715"--> v4 subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v5 -."p:P39".-> v7 v7 --"p:statement/P39"--> v3 end bind10[/"count(?item)"/] v5 --o bind10 bind10 --as--o v10 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c11 --"wikibase:language"--> c13 end