query-874cbebe90f93e9c31097c1342dde0f8

rq turtle/ttl

Ensure country (P17) exists while electoral district (P768) is valid (or today)(P576)dissolved, abolished or demolished date and (P571)inception 's (P17)country are not between their (P576)dissolved, abolished or demolished date and (P571)inception where their (Q28007428)Dáil Éireann constituency Get all

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?constituency ?constituencyLabel ?country ?countryLabel ?inception ?dissolvedTime ?countryStart ?EndTime WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?constituency wdt:P31 wd:Q28007428.
  ?constituency wdt:P17 ?country.
  ?constituency wdt:P571 ?inception.
  OPTIONAL{?constituency wdt:P576 ?dissolved.}

  ?country wdt:P571 ?countryStart.
  OPTIONAL{?country wdt:P576 ?countryEnd.}

  BIND( if(bound(?dissolved), ?dissolved, now()) as ?dissolvedTime)
  BIND( if(bound(?countryEnd), ?countryEnd, now()) as ?EndTime)

  FILTER( ?inception < ?countryStart|| ?dissolvedTime > ?EndTime || ?inception > ?EndTime|| ?dissolvedTime < ?countryStart) 
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v9("?EndTime"):::projected v5("?constituency"):::projected v6("?country"):::projected v8("?countryEnd") v2("?countryStart"):::projected v7("?dissolved") v9("?dissolvedTime"):::projected v1("?inception"):::projected c2(["bd:serviceParam"]):::iri c6(["wd:Q28007428"]):::iri c4(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["(?inception < ?countryStart || (?dissolvedTime > ?EndTime || (?inception > ?EndTime || ?dissolvedTime < ?countryStart)))"]] f0 --> v1 f0 --> v2 f0 --> v9 f0 --> v9 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c2 --"wikibase:language"--> c4 end v5 --"wdt:P31"--> c6 v5 --"wdt:P17"--> v6 v5 --"wdt:P571"--> v1 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v5 -."wdt:P576".-> v7 end v6 --"wdt:P571"--> v2 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v6 -."wdt:P576".-> v8 end bind1[/"if(bound(?dissolved),?dissolved,NOW())"/] v7 --o bind1 bind1 --as--o v9 bind2[/"if(bound(?countryEnd),?countryEnd,NOW())"/] v8 --o bind2 bind2 --as--o v9