query-7a30818a69491af409e24ba420a1caa3

rq turtle/ttl

Communes avec arrondissements, départements et régions. Au 1er janvier 2004, il y avait 36 682 communes en France. SELECT ?insee ?commune ?nom ?inseeArrondissement ?arrondissement ?inseeDépartement ?département ?inseeRégion ?région WHERE { BIND ( "2004-01-01"^^xsd:dateTime as ?dateRecherche ) # Au 1er janvier 2004 ?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 . # nature de commune OPTIONAL { ?commune wdt:P571 ?dateCréation . } # date de création OPTIONAL { ?commune wdt:P576 ?dateDissolution . } # date de dissolution

?département wdt:P2586 ?inseeDépartement. # code Insee du département
?commune p:P131 ?P131nodeDépartement .
?P131nodeDépartement ps:P131 ?département .  # valeur du département
MINUS { ?P131nodeDépartement pq:P1013 wd:Q583865 . } # département collectivité
OPTIONAL { ?P131nodeDépartement pq:P580 ?dateDébutDépartement . } # date de début du département
OPTIONAL { ?P131nodeDépartement pq:P582 ?dateFinDépartement . } # date de fin du département

OPTIONAL { # pas d'arrondissements à Mayotte
?arrondissement wdt:P3423 ?inseeArrondissement. # code Insee de l'arrondissement
?commune p:P131 ?P131nodeArrondissement .
?P131nodeArrondissement ps:P131 ?arrondissement .  # valeur de l'arrondissement
OPTIONAL { ?P131nodeArrondissement pq:P580 ?dateDébutArrondissement . } # date de début de l'arrondissement
OPTIONAL { ?P131nodeArrondissement pq:P582 ?dateFinArrondissement . } # date de fin de l'arrondissement
  }

{ ?région wdt:P2585 ?inseeRégion. # code Insee de la région ?commune p:P131 ?P131nodeRégion . ?P131nodeRégion ps:P131 ?région . # valeur de la région } UNION { ?région wdt:P2585 ?inseeRégion. # code Insee de la région ?département p:P131 ?P131nodeRégion . ?P131nodeRégion ps:P131 ?région . # valeur de la région } OPTIONAL { ?P131nodeRégion pq:P580 ?dateDébutRégion . } # date de début de la région OPTIONAL { ?P131nodeRégion pq:P582 ?dateFinRégion . } # date de fin de la région

 }   
UNION { VALUES (?commune ?inseeDépartement ?inseeArrondissement ?inseeRégion ?région) {(wd:Q90 "75" "751" "11" wd:Q13917)} } # Paris

FILTER ( !BOUND(?dateCréation) || ?dateCréation <= ?dateRecherche ) # communes futures
FILTER ( !BOUND(?dateDissolution) || ?dateDissolution > ?dateRecherche ) # communes passées
FILTER ( !BOUND(?dateDébutDépartement) || ?dateDébutDépartement <= ?dateRecherche ) # ancien département
FILTER ( !BOUND(?dateFinDépartement) || ?dateFinDépartement > ?dateRecherche ) # futur département 
FILTER ( !BOUND(?dateDébutArrondissement) || ?dateDébutArrondissement <= ?dateRecherche ) # ancien arrondissement
FILTER ( !BOUND(?dateFinArrondissement) || ?dateFinArrondissement > ?dateRecherche ) # futur arrondissement 
FILTER ( !BOUND(?dateDébutRégion) || ?dateDébutRégion <= ?dateRecherche ) # ancienne région
FILTER ( !BOUND(?dateFinRégion) || ?dateFinRégion > ?dateRecherche ) # future région

?commune p:P1448 ?P1448node . # existence d'un nom ?P1448node ps:P1448 ?nom . # valeur du nom FILTER( lang(?nom)="fr" ). # nom en français MINUS { ?P1448node pq:P2241 ?dépréciationNom . } # nom erroné OPTIONAL { ?P1448node pq:P580 ?dateDébutNom . } # date de début du nom OPTIONAL { ?P1448node pq:P582 ?dateFinNom . } # date de fin du nom FILTER ( !BOUND(?dateDébutNom) || ?dateDébutNom <= ?dateRecherche ) # ancien nom FILTER ( !BOUND(?dateFinNom) || ?dateFinNom > ?dateRecherche ) # futur nom } 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/>
# Communes avec arrondissements, départements et régions. Au 1er janvier 2004, il y avait 36 682 communes en France.
SELECT ?insee ?commune ?nom ?inseeArrondissement ?arrondissement ?inseeDépartement ?département ?inseeRégion ?région
WHERE {
  BIND ( "2004-01-01"^^xsd:date as ?dateRecherche ) # Au 1er janvier 2004
  ?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 .  # nature de commune
    OPTIONAL { ?commune wdt:P571 ?dateCréation . } # date de création
    OPTIONAL { ?commune wdt:P576 ?dateDissolution . } # date de dissolution

    ?département wdt:P2586 ?inseeDépartement. # code Insee du département
    ?commune p:P131 ?P131nodeDépartement .
    ?P131nodeDépartement ps:P131 ?département .  # valeur du département
    MINUS { ?P131nodeDépartement pq:P1013 wd:Q583865 . } # département collectivité
    OPTIONAL { ?P131nodeDépartement pq:P580 ?dateDébutDépartement . } # date de début du département
    OPTIONAL { ?P131nodeDépartement pq:P582 ?dateFinDépartement . } # date de fin du département 

    OPTIONAL { # pas d'arrondissements à Mayotte
    ?arrondissement wdt:P3423 ?inseeArrondissement. # code Insee de l'arrondissement
    ?commune p:P131 ?P131nodeArrondissement .
    ?P131nodeArrondissement ps:P131 ?arrondissement .  # valeur de l'arrondissement
    OPTIONAL { ?P131nodeArrondissement pq:P580 ?dateDébutArrondissement . } # date de début de l'arrondissement
    OPTIONAL { ?P131nodeArrondissement pq:P582 ?dateFinArrondissement . } # date de fin de l'arrondissement
      }  

   { 
    ?région wdt:P2585 ?inseeRégion. # code Insee de la région
    ?commune p:P131 ?P131nodeRégion .
    ?P131nodeRégion ps:P131 ?région .  # valeur de la région
      }
    UNION { 
     ?région wdt:P2585 ?inseeRégion. # code Insee de la région
    ?département p:P131 ?P131nodeRégion . 
    ?P131nodeRégion ps:P131 ?région .  # valeur de la région
      }
    OPTIONAL { ?P131nodeRégion pq:P580 ?dateDébutRégion . } # date de début de la région
    OPTIONAL { ?P131nodeRégion pq:P582 ?dateFinRégion . } # date de fin de la région

     }   
    UNION { VALUES (?commune ?inseeDépartement ?inseeArrondissement ?inseeRégion ?région) {(wd:Q90 "75" "751" "11" wd:Q13917)} } # Paris 

    FILTER ( !BOUND(?dateCréation) || ?dateCréation <= ?dateRecherche ) # communes futures
    FILTER ( !BOUND(?dateDissolution) || ?dateDissolution > ?dateRecherche ) # communes passées
    FILTER ( !BOUND(?dateDébutDépartement) || ?dateDébutDépartement <= ?dateRecherche ) # ancien département
    FILTER ( !BOUND(?dateFinDépartement) || ?dateFinDépartement > ?dateRecherche ) # futur département 
    FILTER ( !BOUND(?dateDébutArrondissement) || ?dateDébutArrondissement <= ?dateRecherche ) # ancien arrondissement
    FILTER ( !BOUND(?dateFinArrondissement) || ?dateFinArrondissement > ?dateRecherche ) # futur arrondissement 
    FILTER ( !BOUND(?dateDébutRégion) || ?dateDébutRégion <= ?dateRecherche ) # ancienne région
    FILTER ( !BOUND(?dateFinRégion) || ?dateFinRégion > ?dateRecherche ) # future région 

  ?commune p:P1448 ?P1448node . # existence d'un nom
    ?P1448node ps:P1448 ?nom . # valeur du nom
    FILTER( lang(?nom)="fr" ). # nom en français
    MINUS { ?P1448node pq:P2241 ?dépréciationNom . } # nom erroné
    OPTIONAL { ?P1448node pq:P580 ?dateDébutNom . } # date de début du nom
    OPTIONAL { ?P1448node pq:P582 ?dateFinNom . } # date de fin du nom
    FILTER ( !BOUND(?dateDébutNom) || ?dateDébutNom <= ?dateRecherche ) # ancien nom
    FILTER ( !BOUND(?dateFinNom) || ?dateFinNom > ?dateRecherche ) # futur nom
}
ORDER BY (?insee)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v23("?P131nodeArrondissement") v20("?P131nodeDépartement") v26("?P131nodeRégion") v27("?P1448node") v17("?P374node") v21("?arrondissement"):::projected v27("?commune"):::projected v13("?dateCréation") v12("?dateDissolution") v9("?dateDébutArrondissement") v15("?dateDébutCode") v11("?dateDébutDépartement") v4("?dateDébutNom") v7("?dateDébutRégion") v8("?dateFinArrondissement") v14("?dateFinCode") v10("?dateFinDépartement") v2("?dateFinNom") v6("?dateFinRégion") v16("?dateRecherche") v18("?département"):::projected v28("?dépréciationNom") v1("?insee"):::projected v27("?inseeArrondissement"):::projected v27("?inseeDépartement"):::projected v27("?inseeRégion"):::projected v5("?nom"):::projected v27("?région"):::projected c14(["wd:Q583865"]):::iri c7(["wd:Q484170"]):::iri f0[["(not bound(?dateFinNom) || ?dateFinNom > ?dateRecherche)"]] f0 --> v2 f0 --> v16 f1[["(not bound(?dateDébutNom) || ?dateDébutNom <= ?dateRecherche)"]] f1 --> v4 f1 --> v16 f2[["?nom = 'fr'"]] f2 --> v5 f3[["(not bound(?dateFinRégion) || ?dateFinRégion > ?dateRecherche)"]] f3 --> v6 f3 --> v16 f4[["(not bound(?dateDébutRégion) || ?dateDébutRégion <= ?dateRecherche)"]] f4 --> v7 f4 --> v16 f5[["(not bound(?dateFinArrondissement) || ?dateFinArrondissement > ?dateRecherche)"]] f5 --> v8 f5 --> v16 f6[["(not bound(?dateDébutArrondissement) || ?dateDébutArrondissement <= ?dateRecherche)"]] f6 --> v9 f6 --> v16 f7[["(not bound(?dateFinDépartement) || ?dateFinDépartement > ?dateRecherche)"]] f7 --> v10 f7 --> v16 f8[["(not bound(?dateDébutDépartement) || ?dateDébutDépartement <= ?dateRecherche)"]] f8 --> v11 f8 --> v16 f9[["(not bound(?dateDissolution) || ?dateDissolution > ?dateRecherche)"]] f9 --> v12 f9 --> v16 f10[["(not bound(?dateCréation) || ?dateCréation <= ?dateRecherche)"]] f10 --> v13 f10 --> v16 f11[["(not bound(?dateFinCode) || ?dateFinCode > ?dateRecherche)"]] f11 --> v14 f11 --> v16 f12[["(not bound(?dateDébutCode) || ?dateDébutCode <= ?dateRecherche)"]] f12 --> v15 f12 --> v16 bind13[/"'2004-01-01^^xsd:date'"/] bind13 --as--o v16 v27 --"p:P374"--> v17 v17 --"p:statement/P374"--> v1 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v17 -."p:qualifier/P580".-> v15 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v17 -."p:qualifier/P582".-> v14 end subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; bind14[/VALUES ?commune ?inseeArrondissement ?inseeDépartement ?inseeRégion ?région/] bind14-->v27 bind14-->v27 bind14-->v27 bind14-->v27 bind14-->v27 bind140(["wd:Q90"]) bind140 --> bind14 bind141(["75"]) bind141 --> bind14 bind142(["751"]) bind142 --> bind14 bind143(["11"]) bind143 --> bind14 bind144(["wd:Q13917"]) bind144 --> bind14 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v27 --"p:direct/P31"--> c7 subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v27 -."p:direct/P571".-> v13 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v27 -."p:direct/P576".-> v12 end v18 --"p:direct/P2586"--> v27 v27 --"p:P131"--> v20 v20 --"p:statement/P131"--> v18 subgraph minus15["MINUS"] style minus15 stroke-width:6px,fill:pink,stroke:red; v20 --"p:qualifier/P1013"--> c14 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v20 -."p:qualifier/P580".-> v11 end subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v20 -."p:qualifier/P582".-> v10 end subgraph optional6["(optional)"] style optional6 fill:#bbf,stroke-dasharray: 5 5; v21 -."p:direct/P3423".-> v27 v27 --"p:P131"--> v23 v23 --"p:statement/P131"--> v21 subgraph optional7["(optional)"] style optional7 fill:#bbf,stroke-dasharray: 5 5; v23 -."p:qualifier/P580".-> v9 end subgraph optional8["(optional)"] style optional8 fill:#bbf,stroke-dasharray: 5 5; v23 -."p:qualifier/P582".-> v8 end end subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; v27 --"p:direct/P2585"--> v27 v18 --"p:P131"--> v26 v26 --"p:statement/P131"--> v27 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v27 --"p:direct/P2585"--> v27 v27 --"p:P131"--> v26 v26 --"p:statement/P131"--> v27 end union1r <== or ==> union1l end subgraph optional9["(optional)"] style optional9 fill:#bbf,stroke-dasharray: 5 5; v26 -."p:qualifier/P580".-> v7 end subgraph optional10["(optional)"] style optional10 fill:#bbf,stroke-dasharray: 5 5; v26 -."p:qualifier/P582".-> v6 end end union0r <== or ==> union0l end v27 --"p:P1448"--> v27 v27 --"p:statement/P1448"--> v5 subgraph minus16["MINUS"] style minus16 stroke-width:6px,fill:pink,stroke:red; v27 --"p:qualifier/P2241"--> v28 end subgraph optional11["(optional)"] style optional11 fill:#bbf,stroke-dasharray: 5 5; v27 -."p:qualifier/P580".-> v4 end subgraph optional12["(optional)"] style optional12 fill:#bbf,stroke-dasharray: 5 5; v27 -."p:qualifier/P582".-> v2 end