query-72695733db8315f0721b720441ab595b

rq turtle/ttl

Get assembly constituencies which changed districts with new and old district tewikilinks during 2022 reorg SELECT DISTINCT ?assembly (CONCAT("[[",STR(?page_titleTE),"]]") as ?assemblytewikilink) (CONCAT("[[",STR(?page_titleTE_dist),"]]") as ?new_dist_tewiki) (CONCAT("[[",STR(?page_titleTE_old_dist),"]]") as ?old_dist_tewiki) WHERE { ?assembly wdt:P31 wd:Q54375413. { ?assembly p:P131 ?districtnode. ?districtnode ps:P131 ?newdistrict. ?newdistrict wdt:P131 wd:Q1159. ?tewikilink schema:about ?assembly; schema:isPartOf https://te.wikipedia.org/; schema:name ?page_titleTE. ?tewikilink_dist schema:about ?newdistrict; schema:isPartOf https://te.wikipedia.org/; schema:name ?page_titleTE_dist.
OPTIONAL { ?districtnode pq:P580 ?startdate. } BIND(IF(BOUND(?startdate), "yes", "no") AS ?startflag_) BIND(IF(BOUND(?enddate), "yes", "no") AS ?endflag_) BIND(IF(BOUND(?startdate), YEAR(?startdate), 0 ) AS ?startyear) BIND(IF(BOUND(?enddate), YEAR(?enddate), 0 ) AS ?endyear)

FILTER (?startflag_ ="yes" && ?endflag_="no" &&year(?startdate) =2022 )

} { ?assembly p:P131 ?olddistrictnode. ?olddistrictnode ps:P131 ?olddistrict. ?olddistrict wdt:P131 wd:Q1159. ?tewikilink_old_dist schema:about ?olddistrict; schema:isPartOf https://te.wikipedia.org/; schema:name ?page_titleTE_old_dist.
OPTIONAL { ?olddistrictnode pq:P582 ?oldenddate. } BIND(IF(BOUND(?oldenddate), "yes", "no") AS ?oldendflag_) BIND(IF(BOUND(?oldenddate), YEAR(?oldenddate), 0 ) AS ?oldendyear)

FILTER (?oldendflag_="yes" && (year(?oldenddate) =2022) )

} SERVICE wikibase:label { bd:serviceParam wikibase:language "te,en". } } ORDER BY (?page_titleTE_dist) (?assemblyLabel)

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
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#>
#Get assembly constituencies  which changed districts with new and old district tewikilinks during 2022 reorg
SELECT DISTINCT ?assembly (CONCAT("[[",STR(?page_titleTE),"]]") as ?assemblytewikilink)
(CONCAT("[[",STR(?page_titleTE_dist),"]]") as ?new_dist_tewiki) 
(CONCAT("[[",STR(?page_titleTE_old_dist),"]]") as ?old_dist_tewiki)
   WHERE {
  ?assembly wdt:P31 wd:Q54375413.
  {
  ?assembly    p:P131 ?districtnode. 
  ?districtnode ps:P131 ?newdistrict.
  ?newdistrict wdt:P131    wd:Q1159.
  ?tewikilink schema:about ?assembly;
    schema:isPartOf <https://te.wikipedia.org/>;
    schema:name ?page_titleTE.
  ?tewikilink_dist schema:about ?newdistrict;
    schema:isPartOf <https://te.wikipedia.org/>;
    schema:name ?page_titleTE_dist.  
  OPTIONAL { ?districtnode pq:P580 ?startdate. }
  BIND(IF(BOUND(?startdate), "yes", "no") AS ?startflag_)
  BIND(IF(BOUND(?enddate), "yes", "no") AS ?endflag_)
  BIND(IF(BOUND(?startdate), YEAR(?startdate), 0 ) AS ?startyear)
  BIND(IF(BOUND(?enddate), YEAR(?enddate), 0 ) AS ?endyear)
#  FILTER (?startflag_ ="yes" && ?endflag_="no"  &&year(?startdate) =2022  ) 
  }
  {
  ?assembly    p:P131 ?olddistrictnode. 
  ?olddistrictnode ps:P131 ?olddistrict.
  ?olddistrict wdt:P131    wd:Q1159.
  ?tewikilink_old_dist schema:about ?olddistrict;
    schema:isPartOf <https://te.wikipedia.org/>;
    schema:name ?page_titleTE_old_dist.  
  OPTIONAL { ?olddistrictnode pq:P582 ?oldenddate. }
  BIND(IF(BOUND(?oldenddate), "yes", "no") AS ?oldendflag_)
  BIND(IF(BOUND(?oldenddate), YEAR(?oldenddate), 0 ) AS ?oldendyear)
#  FILTER (?oldendflag_="yes"    &&  (year(?oldenddate) =2022) )  
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "te,en". } 
}
ORDER BY (?page_titleTE_dist) (?assemblyLabel)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?assembly"):::projected v2("?assemblyLabel") v21("?assemblytewikilink") v4("?districtnode") v11("?endflag_") v13("?endyear") v22("?new_dist_tewiki") v5("?newdistrict") v23("?old_dist_tewiki") v15("?olddistrict") v14("?olddistrictnode") v18("?oldenddate") v19("?oldendflag_") v20("?oldendyear") v7("?page_titleTE"):::projected v1("?page_titleTE_dist"):::projected v17("?page_titleTE_old_dist"):::projected v9("?startdate") v10("?startflag_") v12("?startyear") v6("?tewikilink") v8("?tewikilink_dist") v16("?tewikilink_old_dist") c2(["wd:Q54375413"]):::iri c9([https://te.wikipedia.org/]):::iri c14(["bd:serviceParam"]):::iri c16(["te,en"]):::literal c6(["wd:Q1159"]):::iri v3 --"p:direct/P31"--> c2 v3 --"p:P131"--> v4 v4 --"p:statement/P131"--> v5 v5 --"p:direct/P131"--> c6 v6 --"schema:about"--> v3 v6 --"schema:isPartOf"--> c9 v6 --"schema:name"--> v7 v8 --"schema:about"--> v5 v8 --"schema:isPartOf"--> c9 v8 --"schema:name"--> v1 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:qualifier/P580".-> v9 end bind0[/"if(bound(?startdate),'yes','no')"/] v9 --o bind0 bind0 --as--o v10 bind1[/"if(bound(?enddate),'yes','no')"/] null --o bind1 bind1 --as--o v11 bind2[/"if(bound(?startdate),year-from-dateTime(?startdate),'0^^xsd:integer')"/] v9 --o bind2 bind2 --as--o v12 bind3[/"if(bound(?enddate),year-from-dateTime(?enddate),'0^^xsd:integer')"/] null --o bind3 bind3 --as--o v13 v3 --"p:P131"--> v14 v14 --"p:statement/P131"--> v15 v15 --"p:direct/P131"--> c6 v16 --"schema:about"--> v15 v16 --"schema:isPartOf"--> c9 v16 --"schema:name"--> v17 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v14 -."p:qualifier/P582".-> v18 end bind4[/"if(bound(?oldenddate),'yes','no')"/] v18 --o bind4 bind4 --as--o v19 bind5[/"if(bound(?oldenddate),year-from-dateTime(?oldenddate),'0^^xsd:integer')"/] v18 --o bind5 bind5 --as--o v20 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c14 --"wikibase:language"--> c16 end bind6[/"concat('#91;#91;',str(?page_titleTE),'#93;#93;')"/] v7 --o bind6 bind6 --as--o v21 bind7[/"concat('#91;#91;',str(?page_titleTE_dist),'#93;#93;')"/] v1 --o bind7 bind7 --as--o v22 bind8[/"concat('#91;#91;',str(?page_titleTE_old_dist),'#93;#93;')"/] v17 --o bind8 bind8 --as--o v23