query-ab32c45c26950c92451ab83adb7cf1c1

rq turtle/ttl

TODO

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/>
SELECT ?insee ?commune 
WHERE {
  BIND ( "2017-01-01"^^xsd:date as ?dateRecherche )        # date recherchée
  ?commune p:P374 ?P374node .                 # recherche code INSEE
  ?P374node ps:P374 ?insee .                  # valeur code INSEE
  optional {?P374node pq:P580 ?start .  }  # may have a start date
  optional {?P374node pq:P582 ?end .  }  # may have an end date
  filter (!bound(?start) || ?start <= ?dateRecherche)
  filter (!bound(?end) || ?end >= ?dateRecherche)
  ?commune p:P31 ?nature.
  {?nature ps:P31 wd:Q484170.}                           # commune de France
  UNION { ?nature ps:P31 wd:Q22927616. }                   # commune française à statut particulier
  OPTIONAL { ?commune wdt:P571 ?dateCréation. }                  # date création
  OPTIONAL { ?commune wdt:P576 ?dateDissolution. }                    # date dissolution
  FILTER ( !BOUND(?dateCréation)|| ?dateCréation <= ?dateRecherche ) # communes futures
  FILTER ( !BOUND(?dateDissolution)|| ?dateDissolution > ?dateRecherche )      # communes passées
  FILTER ( !STRSTARTS(?insee, "98") )                      # - Polynésie
  FILTER ( !STRSTARTS(?insee, "975") )                     # - Saint-Pierre et Miquelon
}
ORDER BY (?insee)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v8("?P374node") v7("?commune"):::projected v4("?dateCréation") v2("?dateDissolution") v7("?dateRecherche") v5("?end") v1("?insee"):::projected v9("?nature") v6("?start") c10(["wd:Q22927616"]):::iri c9(["wd:Q484170"]):::iri f0[["not starts-with(?insee,'975')"]] f0 --> v1 f1[["not starts-with(?insee,'98')"]] f1 --> v1 f2[["(not bound(?dateDissolution) || ?dateDissolution > ?dateRecherche)"]] f2 --> v2 f2 --> v7 f3[["(not bound(?dateCréation) || ?dateCréation <= ?dateRecherche)"]] f3 --> v4 f3 --> v7 f4[["(not bound(?end) || ?end >= ?dateRecherche)"]] f4 --> v5 f4 --> v7 f5[["(not bound(?start) || ?start <= ?dateRecherche)"]] f5 --> v6 f5 --> v7 bind6[/"'2017-01-01^^xsd:date'"/] bind6 --as--o v7 v7 --"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 v7 --"p:P31"--> v9 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v9 --"p:statement/P31"--> c10 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v9 --"p:statement/P31"--> c9 end union0r <== or ==> union0l end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v7 -."p:direct/P571".-> v4 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v7 -."p:direct/P576".-> v2 end