query-af58c7273d7be8493c9761d4fbf5f5e8

rq turtle/ttl

]reply[01:14, 22 January 2021 (UTC)) talk (GettinwikiwiditThe idea here being that if someone took office as the first person after a scheduled election year then they were most likely elected to that office. I also tried excluding people who were appointed, but it looks like no one was appointed under this circumstance. ]reply[01:38, 23 January 2021 (UTC)) talk (GettinwikiwiditI've used this heuristic to fill in people who were elected in regular elections. As mentioned above it's probably a good idea to try to cross check this against other sources. The ones without an election are likely appointed. This can also be cross checked. . The hypothesis is that these were all elected in special elections. There are only ~170 of them. It should be easy enough to check.(P748)appointed by qualifiers, I looked at their first congresses served in and removed those marked with (P2715)elected in For senators without

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
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 ?sen ?senLabel ?district ?districtLabel ?termNum ?appointed ?start WHERE {
  {
    SELECT ?sen ?district (MIN(?term) AS ?first) WHERE {
      ?sen p:P39 ?ps.
      ?ps ps:P39 wd:Q4416090;
        pq:P2937 ?term;
        pq:P768 ?district;
        pq:P580 ?start.
      FILTER(NOT EXISTS { ?ps pq:P2715 ?election. })
      FILTER(?start > "1913"^^xsd:dateTime)
    }
    GROUP BY ?sen ?district
  }
  ?sen p:P39 ?ps.
  ?ps ps:P39 wd:Q4416090;
    pq:P2937 ?first;
    pq:P768 ?district;
        pq:P580 ?start.
  ?first p:P31/pq:P1545 ?termNum.
  FILTER(NOT EXISTS { ?ps pq:P2715 ?election. })
  FILTER( xsd:integer(?termNum) > 65 )
  FILTER NOT EXISTS { ?ps pq:P748 ?appointed. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY ?start

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?appointed"):::projected v8("?district"):::projected v5("?election") v9("?first") v2("?ps") v6("?sen"):::projected v1("?start"):::projected v7("?term") v4("?termNum"):::projected a1((" ")) c14(["bd:serviceParam"]):::iri c7(["wd:Q4416090"]):::iri c16(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["not "]] subgraph f0e0["Exists Clause"] e0v1 --"p:qualifier/P748"--> e0v2 e0v2("?appointed"):::projected e0v1("?ps"):::projected end f0--EXISTS--> f0e0 f0 --> v2 f0 --> c1 f0 --> v3 v2 --"p:qualifier/P748"--> v3 f1[["http://www.w3.org/2001/XMLSchema#integer(?termNum) > '65^^xsd:integer'"]] f1 --> v4 f2[["not "]] subgraph f2e1["Exists Clause"] e1v1 --"p:qualifier/P2715"--> e1v2 e1v2("?election"):::projected e1v1("?ps"):::projected end f2--EXISTS--> f2e1 f2 --> v2 f2 --> c3 f2 --> v5 v2 --"p:qualifier/P2715"--> v5 f3[["?start > '1913^^xsd:dateTime'"]] f3 --> v1 f4[["not "]] subgraph f4e2["Exists Clause"] e2v1 --"p:qualifier/P2715"--> e2v2 e2v2("?election"):::projected e2v1("?ps"):::projected end f4--EXISTS--> f4e2 f4 --> v2 f4 --> c3 f4 --> v5 v2 --"p:qualifier/P2715"--> v5 v6 --"p:P39"--> v2 v2 --"p:statement/P39"--> c7 v2 --"p:qualifier/P2937"--> v7 v2 --"p:qualifier/P768"--> v8 v2 --"p:qualifier/P580"--> v1 bind6[/"min(?term)"/] v7 --o bind6 bind6 --as--o v9 v6 --"p:P39"--> v2 v2 --"p:statement/P39"--> c7 v2 --"p:qualifier/P2937"--> v9 v2 --"p:qualifier/P768"--> v8 v2 --"p:qualifier/P580"--> v1 v9 --"p:P31"--> a1 a1 --"p:qualifier/P1545"--> v4 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c14 --"wikibase:language"--> c16 end