query-b9b2681dcb7ad7f380c01d2d8a52ccc8

rq turtle/ttl

TODO

Use at

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 pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT distinct ?item ?itemLabel ?date ?constituencyLabel ?probelection ?probelectionLabel 
WHERE
  { 
    ?item p:P39 ?statement . ?statement ps:P39 ?term . ?term wdt:P279 wd:Q16707842 .
    ?statement pq:P2715 wd:Q7864918 . 
    ?statement pq:P580 ?date . 
    ?statement pq:P768 ?constituency .
    ?constituency rdfs:label ?constituencyName.
    FILTER((LANG(?constituencyName)) = "en")

    # find the person without a specific by-election

    ?probelection wdt:P31 wd:Q1057954 ; wdt:P17 wd:Q145 ; wdt:P585 ?date ; rdfs:label ?probelection2Name . 
    FILTER((LANG(?probelection2Name)) = "en")
    FILTER CONTAINS(LCASE(?probelection2Name), LCASE(?constituencyName)).

    # find all by-elections on that date

    SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }

}
ORDER BY DESC(?date)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v7("?constituency") v3("?constituencyName") v1("?date"):::projected v4("?item"):::projected v8("?probelection"):::projected v2("?probelection2Name") v5("?statement") v6("?term") c5(["wd:Q16707842"]):::iri c1(["en"]):::literal c17(["bd:serviceParam"]):::iri c12(["wd:Q1057954"]):::iri c7(["wd:Q7864918"]):::iri c14(["wd:Q145"]):::iri f0[["contains(lower-case(?probelection2Name),lower-case(?constituencyName))"]] f0 --> v2 f0 --> v3 f1[["?probelection2Name = 'en'"]] f1 --> v2 f2[["?constituencyName = 'en'"]] f2 --> v3 v4 --"p:P39"--> v5 v5 --"p:statement/P39"--> v6 v6 --"p:direct/P279"--> c5 v5 --"p:qualifier/P2715"--> c7 v5 --"p:qualifier/P580"--> v1 v5 --"p:qualifier/P768"--> v7 v7 --"rdfs:label"--> v3 v8 --"p:direct/P31"--> c12 v8 --"p:direct/P17"--> c14 v8 --"p:direct/P585"--> v1 v8 --"rdfs:label"--> v2 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c17 --"wikibase:language"--> c1 end