query-fe889480b53a4860968cdb55babdcaeb

rq turtle/ttl

Communes avec départements et régions. Au 1er janvier 2013, il y avait 36 681 communes en France. SELECT ?insee ?commune ?nom ?inseeDépartement ?département ?inseeRégion ?région WHERE { BIND ( "2013-01-01"^^xsd:dateTime as ?dateRecherche ) # Au 1er janvier 2013 ?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

{ ?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é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 départements et régions. Au 1er janvier 2013, il y avait 36 681 communes en France.
SELECT ?insee ?commune ?nom ?inseeDépartement ?département ?inseeRégion ?région
WHERE {
  BIND ( "2013-01-01"^^xsd:date as ?dateRecherche ) # Au 1er janvier 2013
  ?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 

   { 
    ?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é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; v18("?P131nodeDépartement") v21("?P131nodeRégion") v23("?P1448node") v15("?P374node") v22("?commune"):::projected v11("?dateCréation") v10("?dateDissolution") v13("?dateDébutCode") v9("?dateDébutDépartement") v4("?dateDébutNom") v7("?dateDébutRégion") v12("?dateFinCode") v8("?dateFinDépartement") v2("?dateFinNom") v6("?dateFinRégion") v14("?dateRecherche") v16("?département"):::projected v24("?dépréciationNom") v1("?insee"):::projected v22("?inseeArrondissement") v22("?inseeDépartement"):::projected v23("?inseeRégion"):::projected v5("?nom"):::projected v23("?région"):::projected c14(["wd:Q583865"]):::iri c7(["wd:Q484170"]):::iri f0[["(not bound(?dateFinNom) || ?dateFinNom > ?dateRecherche)"]] f0 --> v2 f0 --> v14 f1[["(not bound(?dateDébutNom) || ?dateDébutNom <= ?dateRecherche)"]] f1 --> v4 f1 --> v14 f2[["?nom = 'fr'"]] f2 --> v5 f3[["(not bound(?dateFinRégion) || ?dateFinRégion > ?dateRecherche)"]] f3 --> v6 f3 --> v14 f4[["(not bound(?dateDébutRégion) || ?dateDébutRégion <= ?dateRecherche)"]] f4 --> v7 f4 --> v14 f5[["(not bound(?dateFinDépartement) || ?dateFinDépartement > ?dateRecherche)"]] f5 --> v8 f5 --> v14 f6[["(not bound(?dateDébutDépartement) || ?dateDébutDépartement <= ?dateRecherche)"]] f6 --> v9 f6 --> v14 f7[["(not bound(?dateDissolution) || ?dateDissolution > ?dateRecherche)"]] f7 --> v10 f7 --> v14 f8[["(not bound(?dateCréation) || ?dateCréation <= ?dateRecherche)"]] f8 --> v11 f8 --> v14 f9[["(not bound(?dateFinCode) || ?dateFinCode > ?dateRecherche)"]] f9 --> v12 f9 --> v14 f10[["(not bound(?dateDébutCode) || ?dateDébutCode <= ?dateRecherche)"]] f10 --> v13 f10 --> v14 bind11[/"'2013-01-01^^xsd:date'"/] bind11 --as--o v14 v22 --"p:P374"--> v15 v15 --"p:statement/P374"--> v1 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v15 -."p:qualifier/P580".-> v13 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v15 -."p:qualifier/P582".-> v12 end subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; bind12[/VALUES ?commune ?inseeArrondissement ?inseeDépartement ?inseeRégion ?région/] bind12-->v22 bind12-->v22 bind12-->v22 bind12-->v23 bind12-->v23 bind120(["wd:Q90"]) bind120 --> bind12 bind121(["75"]) bind121 --> bind12 bind122(["751"]) bind122 --> bind12 bind123(["11"]) bind123 --> bind12 bind124(["wd:Q13917"]) bind124 --> bind12 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v22 --"p:direct/P31"--> c7 subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v22 -."p:direct/P571".-> v11 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v22 -."p:direct/P576".-> v10 end v16 --"p:direct/P2586"--> v22 v22 --"p:P131"--> v18 v18 --"p:statement/P131"--> v16 subgraph minus13["MINUS"] style minus13 stroke-width:6px,fill:pink,stroke:red; v18 --"p:qualifier/P1013"--> c14 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v18 -."p:qualifier/P580".-> v9 end subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v18 -."p:qualifier/P582".-> v8 end subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; v23 --"p:direct/P2585"--> v23 v16 --"p:P131"--> v21 v21 --"p:statement/P131"--> v23 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v23 --"p:direct/P2585"--> v23 v22 --"p:P131"--> v21 v21 --"p:statement/P131"--> v23 end union1r <== or ==> union1l end subgraph optional6["(optional)"] style optional6 fill:#bbf,stroke-dasharray: 5 5; v21 -."p:qualifier/P580".-> v7 end subgraph optional7["(optional)"] style optional7 fill:#bbf,stroke-dasharray: 5 5; v21 -."p:qualifier/P582".-> v6 end end union0r <== or ==> union0l end v22 --"p:P1448"--> v23 v23 --"p:statement/P1448"--> v5 subgraph minus14["MINUS"] style minus14 stroke-width:6px,fill:pink,stroke:red; v23 --"p:qualifier/P2241"--> v24 end subgraph optional8["(optional)"] style optional8 fill:#bbf,stroke-dasharray: 5 5; v23 -."p:qualifier/P580".-> v4 end subgraph optional9["(optional)"] style optional9 fill:#bbf,stroke-dasharray: 5 5; v23 -."p:qualifier/P582".-> v2 end