forked from zazuko/linked-data-training
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueries.rq
More file actions
331 lines (242 loc) · 9.51 KB
/
queries.rq
File metadata and controls
331 lines (242 loc) · 9.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#Aktuelle Trainings Texte: http://linked-data-training.zazuko.com/
#Die folgenden Queries basieren auf den Daten in jb3-2.ttl
#Return all triples:
SELECT ?subject ?predicate ?object
WHERE {
?subject a <http://schema.org/Person>
}
LIMIT 25
#Find only persons:
SELECT ?subject ?predicate ?object
WHERE {
?subject a <http://schema.org/Person>
}
LIMIT 25
#Add a base to all links:
BASE <http://schema.org/>
SELECT ?subject ?predicate ?object
WHERE {
?subject a <Person>
}
LIMIT 25
#Show all details of all persons:
PREFIX schema: <http://schema.org/>
SELECT ?subject ?predicate ?object
WHERE {
?subject a schema:Person .
?subject ?predicate ?object.
}
LIMIT 25
#Show givenName of all Persons:
PREFIX schema: <http://schema.org/>
SELECT *
WHERE {
?subject a schema:Person ;
schema:givenName ?givenName .
}
LIMIT 25
#Show givenName and familyName of all Persons:
PREFIX schema: <http://schema.org/>
SELECT *
WHERE {
?subject a schema:Person ;
schema:givenName ?givenName;
schema:familyName ?familyName.
}
#Additionally show phone number but also display Persons without phone:
PREFIX schema: <http://schema.org/>
SELECT *
WHERE {
?subject a schema:Person ;
schema:givenName ?givenName ;
schema:familyName ?familyName .
OPTIONAL {?subject schema:telephone ?telephone .}
}
#Additionally also show worlLocation if it is present:
PREFIX schema: <http://schema.org/>
SELECT *
WHERE {
?subject a schema:Person ;
schema:givenName ?givenName ;
schema:familyName ?familyName .
OPTIONAL {?subject schema:telephone ?telephone.}
OPTIONAL {?subject schema:workLocation ?workLocation .}
}
#Show givenName of a Person that a Person knows: Link to a different record and display its values:
PREFIX schema: <http://schema.org/>
SELECT *
WHERE {
?subject a schema:Person ;
schema:givenName ?givenName;
schema:knows ?someoneElse.
?someoneElse schema:givenName ?someoneElsesGivenName
}
#Filter givenname to match text that begins with a string (see string functions here: https://www.w3.org/TR/sparql11-query/#func-strings):
PREFIX schema: <http://schema.org/>
SELECT *
WHERE {
?subject a schema:Person ;
schema:givenName ?givenName.
FILTER regex(?givenName, '^jon', 'i').
}
#faster alternative (regex is slow):
PREFIX schema: <http://schema.org/>
SELECT ?givenName
WHERE {
?subject a schema:Person ;
schema:givenName ?givenName.
FILTER strstarts(?givenName, 'Jon').
}
#Ab jetzt machen wir queries auf LINDAS: http://data.admin.ch/sparql/
# Finde die Gemeinde Historie Einträge deiner Wohngemeinde:
PREFIX gont: <https://gont.ch/>
SELECT * WHERE {
?s a gont:MunicipalityVersion ;
gont:longName ?longName.
FILTER strstarts (?longName, "Bennwil").
}
LIMIT 10
#Beschreiben einer URL (analog der Zazuko-generierten Webpage dieser Entity):
DESCRIBE <http://classifications.data.admin.ch/municipalityversion/11919>
#Name von Gemeinde, District Kanton einer Gemeinde ausgeben:
PREFIX gont: <https://gont.ch/>
SELECT ?municipalityVersionlongName ?municipalityVersionlongName ?districtLongName ?cantonLongName
WHERE {
?s a gont:MunicipalityVersion ;
gont:longName ?municipalityVersionlongName;
gont:canton ?canton ;
gont:district ?district .
FILTER strstarts (?municipalityVersionlongName, "Bennwil").
?canton gont:longName ?cantonLongName.
?district gont:longName ?districtLongName.
}
ORDER BY DESC (?municipalityVersionlongName)
LIMIT 10
#Besser als Filtern nach Kantonsname: Filtern nach Kanton URI:
PREFIX gont: <https://gont.ch/>
SELECT ?municipalityVersionlongName ?municipalityVersionlongName ?districtLongName ?cantonLongName
WHERE {
?s a gont:MunicipalityVersion ;
gont:longName ?municipalityVersionlongName;
gont:canton ?canton ;
gont:district ?district .
FILTER strstarts (?municipalityVersionlongName, "Bennwil").
?s gont:canton <http://classifications.data.admin.ch/canton/BL>.
?canton gont:longName ?cantonLongName.
?district gont:longName ?districtLongName.
}
ORDER BY DESC (?municipalityVersionlongName)
LIMIT 10
#Gemeindenummer holen:
PREFIX gont: <https://gont.ch/>
SELECT * # ?municipalityVersionlongName ?municipalityVersionlongName ?districtLongName ?cantonLongName
WHERE {
?munVersion a gont:MunicipalityVersion ;
gont:longName ?municipalityVersionlongName;
gont:canton ?canton ;
gont:district ?district .
?mun gont:municipalityVersion ?munVersion;
a gont:Municipality;
<http://purl.org/dc/terms/identifier> ?munId.
FILTER strstarts (?municipalityVersionlongName, "Bennwil").
?s gont:canton <http://classifications.data.admin.ch/canton/BL>.
?canton gont:longName ?cantonLongName.
?district gont:longName ?districtLongName.
}
ORDER BY DESC (?municipalityVersionlongName)
LIMIT 10
#Shapes von Gemeinden im Kanton Jura anzeigen: Federierte Queries zwischen BFS und Swisstopo
#Siehe http://linked-data-training.zazuko.com/ (Sample Data and Queries)
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT * WHERE {
# Get data from bfs
SERVICE <http://data.admin.ch/query/> {
?munversion a <https://gont.ch/MunicipalityVersion> ;
<https://gont.ch/longName> ?longName ;
<https://gont.ch/district> ?districtUri ;
# Fix the URI for a specific canton to get only those results
<https://gont.ch/canton> <http://classifications.data.admin.ch/canton/JU> ;
# This makes sure we still get the URI from the canton as a variable, nice to have some times
<https://gont.ch/canton> ?cantonUri .
?districtUri <https://gont.ch/longName> ?district .
?cantonUri <https://gont.ch/longName> ?canton .
?mun a <https://gont.ch/Municipality> ;
<https://gont.ch/municipalityVersion> ?munversion ;
<http://purl.org/dc/terms/identifier> ?gdeNummer ;
# Get municipality Uri of swisstopo to be used in swisstopo sparql endpoint
<http://www.w3.org/2000/01/rdf-schema#seeAlso> ?geoMunicipalityUri .
#FILTER(STRSTARTS( ?longName, "C"))
# That is another way of filtering for a specific canton, but slower
# FILTER(STRSTARTS( ?canton, "Bern"))
}
# The subject is set to a specific URI for the start, fetch all ?version of it
?geoMunicipalityUri <http://purl.org/dc/terms/hasVersion> ?version .
# Set the version to 2018 and get ?geometry
?version <http://purl.org/dc/terms/issued> "2018-01-01"^^xsd:date ;
<http://www.opengis.net/ont/geosparql#hasGeometry> ?geometry .
# get WKT
?geometry <http://www.opengis.net/ont/geosparql#asWKT> ?wkt .
}
#Labels auf die Shapes plazieren mit Gemeindename und -nummer:
SELECT * WHERE {
# Get data from bfs
SERVICE <http://data.admin.ch/query/> {
?munversion a <https://gont.ch/MunicipalityVersion> ;
<https://gont.ch/longName> ?longName ;
<https://gont.ch/district> ?districtUri ;
# Fix the URI for a specific canton to get only those results
<https://gont.ch/canton> <http://classifications.data.admin.ch/canton/BL> ;
# This makes sure we still get the URI from the canton as a variable, nice to have some times
<https://gont.ch/canton> ?cantonUri .
?districtUri <https://gont.ch/longName> ?district .
?cantonUri <https://gont.ch/longName> ?canton .
?mun a <https://gont.ch/Municipality> ;
<https://gont.ch/municipalityVersion> ?munversion ;
<http://purl.org/dc/terms/identifier> ?gdeNummer ;
# Get municipality Uri of swisstopo to be used in swisstopo sparql endpoint
<http://www.w3.org/2000/01/rdf-schema#seeAlso> ?seeAlso .
#FILTER(STRSTARTS( ?longName, "C"))
# That is another way of filtering for a specific canton, but slower
# FILTER(STRSTARTS( ?canton, "Bern"))
}
# The subject is set to a specific URI for the start, fetch all ?version of it
?seeAlso <http://purl.org/dc/terms/hasVersion> ?version .
# Set the version to 2018 and get ?geometry
?version <http://purl.org/dc/terms/issued> "2018-01-01"^^xsd:date ;
<http://www.opengis.net/ont/geosparql#hasGeometry> ?geometry .
# get WKT
?geometry <http://www.opengis.net/ont/geosparql#asWKT> ?wkt .
# Add Labels to shapes
BIND(Concat(?longName, concat(' - ', ?gdeNummer)) as ?wktLabel)
}
#Stadtarchiv Uster: Hole Bilder, verorte sie auf einer Karte, erstelle ein Label mit Thumbnail und Link auf das Bild:
# https://test.lindas-data.ch/sparql-ui/#
PREFIX schema: <http://schema.org/>
PREFIX wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
WHERE { GRAPH ?g {
?s a schema:Photograph ;
schema:description ?description;
#schema:description ?wktLabel;
wgs:lat ?lat;
wgs:long ?long;
schema:thumbnailUrl ?thumbnailUrl;
schema:image ?imageUrl;
schema:publisher ?publisher.
BIND(concat("POINT (", str(?long), " ", str(?lat), ")") as ?point)
BIND(concat(?description, "<p/><a href='", str(?imageUrl), "' target='_blank'>", "<img src='", str(?thumbnailUrl), "'/>", "</a>")
as ?pointLabel)
}}
#Filtern nach Sprache: Name eines Trams in ch-de und de-de:
# http://lod.opentransportdata.swiss/sparql/
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT * WHERE {
<http://lod.opentransportdata.swiss/stationtype/Tram> ?p ?o .
FILTER langMatches( lang(?o), "de" )
}
LIMIT 10