query-b33cd64777ce25400d54e72fe6acc966

rq turtle/ttl

Au 1er janvier 2021, il y avait 34 965 communes en France. SELECT ?insee ?commune WHERE { BIND ( "2021-01-01"^^xsd:dateTime as ?dateRecherche ) # Au 1er janvier 2021 ?commune p:P374 ?P374node . # existence d'un code Insee ?P374node ps:P374 ?insee . # valeur du code Insee OPTIONAL { ?P374node pq:P580 ?dateDébutCode . } # date de début du code Insee OPTIONAL { ?P374node pq:P582 ?dateFinCode . } # date de fin du code Insee FILTER ( !BOUND(?dateDébutCode) || ?dateDébutCode <= ?dateRecherche ) # ancien code Insee FILTER ( !BOUND(?dateFinCode) || ?dateFinCode > ?dateRecherche ) # futur code Insee { ?commune wdt:P31 wd:Q484170 . } UNION { VALUES ?commune {wd:Q90} } # nature de commune OPTIONAL { ?commune wdt:P571 ?dateCréation . } # date de création OPTIONAL { ?commune wdt:P576 ?dateDissolution . } # date de dissolution FILTER ( !BOUND(?dateCréation) || ?dateCréation <= ?dateRecherche ) # communes futures FILTER ( !BOUND(?dateDissolution) || ?dateDissolution > ?dateRecherche ) # communes passées } ORDER BY (?insee)

Use at

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/>
# Au 1er janvier 2021, il y avait 34 965 communes en France.
SELECT ?insee ?commune 
WHERE {
  BIND ( "2021-01-01"^^xsd:date as ?dateRecherche ) # Au 1er janvier 2021
  ?commune p:P374 ?P374node . # existence d'un code Insee
    ?P374node ps:P374 ?insee . # valeur du code Insee
    OPTIONAL { ?P374node pq:P580 ?dateDébutCode . } # date de début du code Insee
    OPTIONAL { ?P374node pq:P582 ?dateFinCode . } # date de fin du code Insee
    FILTER ( !BOUND(?dateDébutCode) || ?dateDébutCode <= ?dateRecherche ) # ancien code Insee
    FILTER ( !BOUND(?dateFinCode) || ?dateFinCode > ?dateRecherche ) # futur code Insee
  { ?commune wdt:P31 wd:Q484170 . } UNION { VALUES ?commune {wd:Q90} } # nature de commune
    OPTIONAL { ?commune wdt:P571 ?dateCréation . } # date de création
    OPTIONAL { ?commune wdt:P576 ?dateDissolution . } # date de dissolution
    FILTER ( !BOUND(?dateCréation) || ?dateCréation <= ?dateRecherche ) # communes futures
    FILTER ( !BOUND(?dateDissolution) || ?dateDissolution > ?dateRecherche ) # communes passées
}
ORDER BY (?insee)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v8("?P374node") v9("?commune"):::projected v4("?dateCréation") v2("?dateDissolution") v6("?dateDébutCode") v5("?dateFinCode") v7("?dateRecherche") v1("?insee"):::projected c6(["wd:Q484170"]):::iri f0[["(not bound(?dateDissolution) || ?dateDissolution > ?dateRecherche)"]] f0 --> v2 f0 --> v7 f1[["(not bound(?dateCréation) || ?dateCréation <= ?dateRecherche)"]] f1 --> v4 f1 --> v7 f2[["(not bound(?dateFinCode) || ?dateFinCode > ?dateRecherche)"]] f2 --> v5 f2 --> v7 f3[["(not bound(?dateDébutCode) || ?dateDébutCode <= ?dateRecherche)"]] f3 --> v6 f3 --> v7 bind4[/"'2021-01-01^^xsd:date'"/] bind4 --as--o v7 v9 --"p:P374"--> v8 v8 --"p:statement/P374"--> v1 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v8 -."p:qualifier/P580".-> v6 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v8 -."p:qualifier/P582".-> v5 end subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; bind5[/VALUES ?commune/] bind5-->v9 bind50(["wd:Q90"]) bind50 --> bind5 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v9 --"p:direct/P31"--> c6 end union0r <== or ==> union0l end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v9 -."p:direct/P571".-> v4 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v9 -."p:direct/P576".-> v2 end