query-32b12f38c5c8ee7fbd8cda95faa8c6ee
TODO
Use at
- https://query.wikidata.org/sparql
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
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/>
SELECT ?insee ?commune
WHERE {
BIND ( "2017-01-01"^^xsd:date as ?dateRecherche ) # date recherchée
# values ?commune {wd:Q55589867}
# ?commune wdt:P374 ?insee. # code INSEE
?commune p:P374 ?P374node . # there is a P374
?P374node ps:P374 ?insee . # with this value
optional {?P374node pq:P580 ?start . } # may have a start date
optional {?P374node pq:P582 ?end . } # may have an end date
bind(if(!bound(?start), "2016"^^xsd:integer,year(?start)) as ?startdate)
bind(if(!bound(?end), "2018"^^xsd:integer,year(?end)) as ?enddate)
filter (?startdate < 2017)
filter (?enddate > 2017)
?commune p:P31 ?nature.
{?nature ps:P31 wd:Q484170.} # commune de France
UNION { ?nature ps:P31 wd:Q22927616. } # commune française à statut particulier
OPTIONAL { ?commune wdt:P571 ?dateCréation. } # date création
OPTIONAL { ?commune wdt:P576 ?dateDissolution. } # date dissolution
FILTER ( !BOUND(?dateCréation)|| ?dateDissolution > ?dateRecherche ) # communes passées
FILTER ( !STRSTARTS(?insee, "98") ) # - Polynésie
FILTER ( !STRSTARTS(?insee, "975") ) # - Saint-Pierre et Miquelon
}
ORDER BY (?insee)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v8("?P374node")
v7("?commune"):::projected
v2("?dateCréation")
v3("?dateDissolution")
v7("?dateRecherche")
v10("?end")
v11("?enddate")
v1("?insee"):::projected
v11("?nature")
v9("?start")
v11("?startdate")
c11(["wd:Q22927616"]):::iri
c10(["wd:Q484170"]):::iri
f0[["not starts-with(?insee,'975')"]]
f0 --> v1
f1[["not starts-with(?insee,'98')"]]
f1 --> v1
f2[["(not bound(?dateCréation) || ?dateDissolution > ?dateRecherche)"]]
f2 --> v2
f2 --> v3
f2 --> v7
f3[["?enddate > '2017^^xsd:integer'"]]
f3 --> v11
f4[["?startdate < '2017^^xsd:integer'"]]
f4 --> v11
bind5[/"'2017-01-01^^xsd:date'"/]
bind5 --as--o v7
v7 --"p:P374"--> v8
v8 --"p:statement/P374"--> v1
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v8 -."p:qualifier/P580".-> v9
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v8 -."p:qualifier/P582".-> v10
end
bind6[/"if(not bound(?start),'2016^^xsd:integer',year-from-dateTime(?start))"/]
v9 --o bind6
bind6 --as--o v11
bind7[/"if(not bound(?end),'2018^^xsd:integer',year-from-dateTime(?end))"/]
v10 --o bind7
bind7 --as--o v11
v7 --"p:P31"--> v11
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v11 --"p:statement/P31"--> c11
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v11 --"p:statement/P31"--> c10
end
union0r <== or ==> union0l
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:direct/P571".-> v2
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v7 -."p:direct/P576".-> v3
end