query-543d42753d003b9c8bf2acc4516bb3cf
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 (REPLACE(STR(?item),".*Q","Q") AS ?id)
WHERE {
BIND ( "2019-01-02"^^xsd:date as ?dateQuery )
?item p:P31 ?nature.
{ ?nature ps:P31 wd:Q484170. } # commune de France
UNION { ?nature ps:P31 wd:Q2989454. } # commune nouvelle
UNION { ?nature ps:P31 wd:Q22927616. } # commune française à statut particulier
OPTIONAL { ?nature pq:P582 ?dateFin }
OPTIONAL { ?item wdt:P576 ?dateFin. } # date dissolution
FILTER ( !BOUND(?dateFin)|| ?dateFin > ?dateQuery )
OPTIONAL { ?nature pq:P580 ?dateDébut }
OPTIONAL { ?item wdt:P571 ?dateDébut. } # date création
FILTER ( !BOUND(?dateDébut) || ?dateDébut < ?dateQuery )
FILTER ( !STRSTARTS(?insee, "98") ) # - Polynésie
FILTER ( !STRSTARTS(?insee, "975") ) # - Saint-Pierre et Miquelon
?item wdt:P374 ?insee.
}
ORDER BY (?insee)
Query found at
- https://www.wikidata.org/wiki/User_talk:Roland45
- https://www.wikidata.org/wiki/Wikidata:Request_a_query/Archive/2019/06
- https://www.wikidata.org/wiki/Wikidata:Request_a_query/Archive/2020/01
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v2("?dateDébut")
v4("?dateFin")
v5("?dateQuery")
v7("?id")
v1("?insee"):::projected
v5("?item"):::projected
v6("?nature")
c6(["wd:Q2989454"]):::iri
c7(["wd:Q22927616"]):::iri
c5(["wd:Q484170"]):::iri
f0[["not starts-with(?insee,'975')"]]
f0 --> v1
f1[["not starts-with(?insee,'98')"]]
f1 --> v1
f2[["(not bound(?dateDébut) || ?dateDébut < ?dateQuery)"]]
f2 --> v2
f2 --> v5
f3[["(not bound(?dateFin) || ?dateFin > ?dateQuery)"]]
f3 --> v4
f3 --> v5
bind4[/"'2019-01-02^^xsd:date'"/]
bind4 --as--o v5
v5 --"p:P31"--> v6
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
v6 --"p:statement/P31"--> c7
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v6 --"p:statement/P31"--> c6
end
union1r <== or ==> union1l
end
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v6 --"p:statement/P31"--> c5
end
union0r <== or ==> union0l
end
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v6 -."p:qualifier/P582".-> v4
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v5 -."p:direct/P576".-> v4
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v6 -."p:qualifier/P580".-> v2
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v5 -."p:direct/P571".-> v2
end
v5 --"p:direct/P374"--> v1
bind5[/"replace(str(?item),'.*Q','Q')"/]
v5 --o bind5
bind5 --as--o v7