query-c71ac17c9b6e8e617607125c872bb771

rq turtle/ttl

Communes avec les arrondissements. Au 1er janvier 2003, il y avait 36 678 communes en France. SELECT ?insee ?commune ?nom ?inseeArrondissement ?arrondissement WHERE { BIND ( "2003-01-01"^^xsd:dateTime as ?dateRecherche ) # Au 1er janvier 2003 ?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

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 l'arrondissement
OPTIONAL { ?P131nodeArrondissement pq:P582 ?dateFinArrondissement . } # date de l'arrondissement
  }

}
UNION { VALUES (?commune ?inseeDépartement ?inseeArrondissement ) {(wd:Q90 "75" "751")} } # Paris FILTER ( !BOUND(?dateCréation) || ?dateCréation <= ?dateRecherche ) # communes futures FILTER ( !BOUND(?dateDissolution) || ?dateDissolution > ?dateRecherche ) # communes passées FILTER ( !BOUND(?dateDébutArrondissement) || ?dateDébutArrondissement <= ?dateRecherche ) # ancien arrondissement FILTER ( !BOUND(?dateFinArrondissement) || ?dateFinArrondissement > ?dateRecherche ) # futur arrondissement

?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 les arrondissements. Au 1er janvier 2003, il y avait 36 678 communes en France.
SELECT ?insee ?commune ?nom ?inseeArrondissement ?arrondissement
WHERE {
  BIND ( "2003-01-01"^^xsd:date as ?dateRecherche ) # Au 1er janvier 2003
  ?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

    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 l'arrondissement
    OPTIONAL { ?P131nodeArrondissement pq:P582 ?dateFinArrondissement . } # date de l'arrondissement
      }  
  }   
    UNION { VALUES (?commune ?inseeDépartement ?inseeArrondissement ) {(wd:Q90 "75" "751")} } # Paris
    FILTER ( !BOUND(?dateCréation) || ?dateCréation <= ?dateRecherche ) # communes futures
    FILTER ( !BOUND(?dateDissolution) || ?dateDissolution > ?dateRecherche ) # communes passées 
    FILTER ( !BOUND(?dateDébutArrondissement) || ?dateDébutArrondissement <= ?dateRecherche ) # ancien arrondissement
    FILTER ( !BOUND(?dateFinArrondissement) || ?dateFinArrondissement > ?dateRecherche ) # futur arrondissement 

  ?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; v16("?P131nodeArrondissement") v18("?P1448node") v13("?P374node") v14("?arrondissement"):::projected v17("?commune"):::projected v9("?dateCréation") v8("?dateDissolution") v7("?dateDébutArrondissement") v11("?dateDébutCode") v4("?dateDébutNom") v6("?dateFinArrondissement") v10("?dateFinCode") v2("?dateFinNom") v12("?dateRecherche") v19("?dépréciationNom") v1("?insee"):::projected v18("?inseeArrondissement"):::projected v17("?inseeDépartement") v5("?nom"):::projected c7(["wd:Q484170"]):::iri f0[["(not bound(?dateFinNom) || ?dateFinNom > ?dateRecherche)"]] f0 --> v2 f0 --> v12 f1[["(not bound(?dateDébutNom) || ?dateDébutNom <= ?dateRecherche)"]] f1 --> v4 f1 --> v12 f2[["?nom = 'fr'"]] f2 --> v5 f3[["(not bound(?dateFinArrondissement) || ?dateFinArrondissement > ?dateRecherche)"]] f3 --> v6 f3 --> v12 f4[["(not bound(?dateDébutArrondissement) || ?dateDébutArrondissement <= ?dateRecherche)"]] f4 --> v7 f4 --> v12 f5[["(not bound(?dateDissolution) || ?dateDissolution > ?dateRecherche)"]] f5 --> v8 f5 --> v12 f6[["(not bound(?dateCréation) || ?dateCréation <= ?dateRecherche)"]] f6 --> v9 f6 --> v12 f7[["(not bound(?dateFinCode) || ?dateFinCode > ?dateRecherche)"]] f7 --> v10 f7 --> v12 f8[["(not bound(?dateDébutCode) || ?dateDébutCode <= ?dateRecherche)"]] f8 --> v11 f8 --> v12 bind9[/"'2003-01-01^^xsd:date'"/] bind9 --as--o v12 v17 --"p:P374"--> v13 v13 --"p:statement/P374"--> v1 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v13 -."p:qualifier/P580".-> v11 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v13 -."p:qualifier/P582".-> v10 end subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; bind10[/VALUES ?commune ?inseeArrondissement ?inseeDépartement/] bind10-->v17 bind10-->v17 bind10-->v18 bind100(["wd:Q90"]) bind100 --> bind10 bind101(["75"]) bind101 --> bind10 bind102(["751"]) bind102 --> bind10 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v17 --"p:direct/P31"--> c7 subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v17 -."p:direct/P571".-> v9 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v17 -."p:direct/P576".-> v8 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v14 -."p:direct/P3423".-> v18 v17 --"p:P131"--> v16 v16 --"p:statement/P131"--> v14 subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v16 -."p:qualifier/P580".-> v7 end subgraph optional6["(optional)"] style optional6 fill:#bbf,stroke-dasharray: 5 5; v16 -."p:qualifier/P582".-> v6 end end end union0r <== or ==> union0l end v17 --"p:P1448"--> v18 v18 --"p:statement/P1448"--> v5 subgraph minus11["MINUS"] style minus11 stroke-width:6px,fill:pink,stroke:red; v18 --"p:qualifier/P2241"--> v19 end subgraph optional7["(optional)"] style optional7 fill:#bbf,stroke-dasharray: 5 5; v18 -."p:qualifier/P580".-> v4 end subgraph optional8["(optional)"] style optional8 fill:#bbf,stroke-dasharray: 5 5; v18 -."p:qualifier/P582".-> v2 end