README.md 1.83 KB
Newer Older
Jonas Waeber's avatar
Jonas Waeber committed
1 2 3 4 5 6
## Drupal Sync Service

Transforms json objects into RDF Resources.

### Canton Query

Jonas Waeber's avatar
Jonas Waeber committed
7 8
Here the codes were added manually and the names adjusted to exclude the word canton. Just kept the name.

Jonas Waeber's avatar
Jonas Waeber committed
9 10 11
https://query.wikidata.org/

```sparql
Jonas Waeber's avatar
Jonas Waeber committed
12
SELECT ?item ?de ?fr ?it
Jonas Waeber's avatar
Jonas Waeber committed
13 14 15
WHERE 
{
  ?item wdt:P31 wd:Q23058.
Jonas Waeber's avatar
Jonas Waeber committed
16 17
  ?item rdfs:label ?de .
  FILTER(LANG(?de) = "de")
Jonas Waeber's avatar
Jonas Waeber committed
18
  
Jonas Waeber's avatar
Jonas Waeber committed
19 20
  ?item rdfs:label ?fr .
  FILTER(LANG(?fr) = "fr")
Jonas Waeber's avatar
Jonas Waeber committed
21
  
Jonas Waeber's avatar
Jonas Waeber committed
22 23
  ?item rdfs:label ?it .
  FILTER(LANG(?it) = "it")
Jonas Waeber's avatar
Jonas Waeber committed
24 25 26 27 28 29 30
}
```

### Municipalities Query

https://query.wikidata.org/

Jonas Waeber's avatar
Jonas Waeber committed
31 32
```sparql
SELECT (GROUP_CONCAT(DISTINCT ?postalCode; SEPARATOR=",") as ?code) ?id (SAMPLE(?de) as ?de) (SAMPLE(?fr) as ?fr) (SAMPLE(?it) as ?it) 
Jonas Waeber's avatar
Jonas Waeber committed
33 34
WHERE 
{
Jonas Waeber's avatar
Jonas Waeber committed
35 36 37 38 39 40 41 42 43 44 45
  ?id wdt:P31 wd:Q70208. # swiss municipalities
  ?id wdt:P281 ?postalCode .
  
  ?id rdfs:label ?de .
  FILTER(LANG(?de) = "de")
  
  ?id rdfs:label ?fr .
  FILTER(LANG(?fr) = "fr")
  
  ?id rdfs:label ?it .
  FILTER(LANG(?it) = "it")
Jonas Waeber's avatar
Jonas Waeber committed
46
  
Jonas Waeber's avatar
Jonas Waeber committed
47
  MINUS {
Jonas Waeber's avatar
Jonas Waeber committed
48
    ?id wdt:P31 wd:Q685309 # removes former municipalities
Jonas Waeber's avatar
Jonas Waeber committed
49
  }
Jonas Waeber's avatar
Jonas Waeber committed
50 51
} 
GROUP BY ?id
Jonas Waeber's avatar
Jonas Waeber committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
```

### More Complete Query

```sql
SELECT ?item (GROUP_CONCAT(DISTINCT ?postalCode; SEPARATOR=",") as ?groupedPostalCode) ?canton ?labelDE ?labelFR ?labelIT (GROUP_CONCAT(DISTINCT ?coordinates; SEPARATOR=",") as ?groupedCoordinates)
WHERE 
{
  ?item wdt:P31 wd:Q70208. # swiss municipalities
  OPTIONAL { ?item wdt:P281 ?postalCode . }
  ?item wdt:P625 ?coordinates .
  OPTIONAL { 
    ?item wdt:P131 ?canton .
    ?canton wdt:P31 wd:Q23058 . # adminUnit is canton of switzerland 
  }
  OPTIONAL {
    ?item rdfs:label ?labelDE .
    FILTER(LANG(?labelDE) = "de")
  }

  OPTIONAL {
    ?item rdfs:label ?labelFR .
    FILTER(LANG(?labelFR) = "fr")
  }
  
  OPTIONAL {
    ?item rdfs:label ?labelIT .
    FILTER(LANG(?labelIT) = "it")
  }
Jonas Waeber's avatar
Jonas Waeber committed
81 82 83
  MINUS {
    ?item wdt:P31 wd:Q685309 # removes former municipalities
  }
Jonas Waeber's avatar
Jonas Waeber committed
84 85
  
}
Jonas Waeber's avatar
Jonas Waeber committed
86
GROUP BY ?item ?canton ?labelDE ?labelFR ?labelIT
Jonas Waeber's avatar
Jonas Waeber committed
87
```