forked from FacultadInformatica-LinkedData/Curso2019-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathikirbank-RicardoGilMonteagudo.txt
260 lines (221 loc) · 6.92 KB
/
ikirbank-RicardoGilMonteagudo.txt
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
Ejercicios Obligatorios Assigment 3:
1.Get all the properties that can be applied to instances of
prefix schema: <http://dbpedia.org/ontology/>
select distinct ?p
where {
?x a schema:Politician .
?x ?p ?z.
}
2.Get all the properties, except rdf:type, that can be applied to instances of the Politician class
prefix schema: <http://dbpedia.org/ontology/>
select distinct ?p
where {
?x a schema:Politician .
?x ?p ?z .
filter (?p != rdf:type ).
} limit 100
3.Which different values exist for the properties, except rdf:type, of the instances of the Politician class?
prefix schema: <http://dbpedia.org/ontology/>
select distinct ?p ?value
where {
?x a schema:Politician .
?x ?p ?value .
filter (?p != rdf:type ).
} limit 100
4.For each of the properties, except rdf:type, that can be applied to instances of the Politician class, which different values do they take in those instances?
prefix schema: <http://dbpedia.org/ontology/>
select distinct ?x
where {
?x a schema:Politician .
?x ?p ?value .
filter (?p != rdf:type ).
} limit 100
5. For each of the properties, except rdf:type, that can be applied to instances of the Politician class, how many distinct values do they take in those instances?
prefix schema: <http://dbpedia.org/ontology/>
select distinct ?p (count(distinct ?x) as ?count)
where {
?x a schema:Politician .
?x ?p ?value .
filter (?p != rdf:type ).
} limit 100
prefix schema: <http://dbpedia.org/ontology/>
select distinct ?p (count (?x) as ?count)
where {
?x a schema:Politician .
?x ?p ?value .
filter (?p != rdf:type ).
} limit 100
#Ejercicios de clase (Transparencias) :
#ENDPOINT: http://sandbox.linkeddata.es/sparql y el grafo es : http://sandbox.linkeddata.es/Grado_20122013
#1: Get all the classes
#SOLUCION
select distinct ?clase
where {
?x a ?clase
}LIMIT 100
#SOLUCION que muestra todas las clases independientemante de si existen instancias de las mismas o no:
#2: Get all the subclasses of the class Establishment
#SOLUCION
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?clase
where {
?clase rdfs:subClassOf ex:Establishment
}LIMIT 100
#SOLUCION que a demás devuelve todos los hijos del grafo incluyendo aquellos de niveles inferiores ('+')
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?clase
where {
?clase rdfs:subClassOf+ ex:Establishment
}LIMIT 100
#3: Get all instances of the class City
#SOLUCION
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?x
where {
?x a ex:City
}LIMIT 100
#SOLUCION Si no esta activada la inferencia, para poder ver los elementos heredados (por inferencia) y para
#esta consulta en concreto podríamos hacer:
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?city
where {
?city a/rdfs:subClassOf* ex:City
}LIMIT 100
#4: Get the number of inhabitants of Santiago de Compostela
#First we get all the properties of the tripet:
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?p
where {
ex:Santiago_de_Compostela ?p ?z
}LIMIT 100
#if we want to show all information insted only the properties we go like this:
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?p ?z
where {
ex:Santiago_de_Compostela ?p ?z
}LIMIT 100
#Then we answer the question
#SOLUCION
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?z
where {
ex:Santiago_de_Compostela
ex:hasInhabitantNumber ?z
}LIMIT 100
#5: Get the number of inhabitants of Santiago de Compostela and Arzua
#SOLUCION
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?y ?z
where {
?y ex:hasInhabitantNumber ?z.
FILTER(?y IN (ex:Arzua , ex:Santiago_de_Compostela))
}LIMIT 100
#6: Get all places, together with the number of inhabitants, ordered by the place name (ascending)
#SOLUCION
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?y ?nombre ?z
where {
?y ex:hasInhabitantNumber ?z.
?y rdfs:label ?nombre
}order by ?nombre
#7: Get all instances of Locality together with their number of inhabitants (if this information exists)
#SOLUCION
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?y ?z
where {
?y a ex:Locality.
optional{?y ex:hasInhabitantNumber ?z}
}limit 100
#SOLUCION si además queremos usar inferencia para ver si sus hijos tienen alguna instancia de Locality
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?y ?z
where {
?y a/rdfs:subClassOf* ex:Locality.
optional{?y ex:hasInhabitantNumber?z}
}limit 100
#8: Get all places with more than 200.000 inhabitants
#SOLUCION Es necesario hacer un cast en la variable ?z pues los datos no están subidos como integer
Están subidos como String
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?y xsd:integer(?z) as ?hab
where {
?y ex:hasInhabitantNumber ?z.
filter(xsd:integer(?z)>200000)
}limit 100
#9: Get postal address data for Pazo_Breogan (street, number, locality, province)
#if we want to show the information of a property firt we check if the triplet has it:
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?y
where {
ex:Pazo_Breogan ?y ?p
}LIMIT 100
#Then we answer the question showing the information of the property: hasAddress
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?y ?p
where {
ex:GP_Santiago_Instance_85 ?y ?p
}LIMIT 100
#10: Get all subclasses of class Location
#SOLUCION
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?location
where {
?location rdfs:subClassOf ex:Location
}LIMIT 10
#SOLUCION que a demás devuelve todos los hijos del grafo incluyendo aquellos de niveles inferiores ('+')
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?location
where {
?location rdfs:subClassOf+ ex:Location
}LIMIT 100
#11: Get all instances of class Locality
#SOLUCION
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?x
where {
?x a ex:Locality
}LIMIT 100
#SOLUCION Si no esta activada la inferencia, para poder ver los elementos heredados (por inferencia) y para
#esta consulta en concreto podríamos hacer:
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?x
where {
?x a/rdfs:subClassOf* ex:Locality
}LIMIT 100
#12: Describe the resource with rdfs:label "Madrid”
#SOLUCION
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
describe ?x
where{
#ex:City.
?x rdfs:label "Madrid"
}
#Una alternativa sin usar el rdfs:label es:
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
describe ?y ?p
where {
ex:Madrid ?y ?p
}LIMIT 100
#13: Construct a graph that relates directly all touristic places with their provinces, using a new property
#called ”isIn”
#Fist we get all the cities that have the property inProvince:
#SOLUCION
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
select distinct ?y ?z
where {
?y ex:inProvince ?z.
}LIMIT 100
#SOLUCION una vez vemmos las propiedades hay que unirlas creando la nueva propiedad
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
construct {
?p ex:isIn ?q
}
where {
?p ex:isPlacedIn ?y.
?y ex:inProvince ?q
}
#14: Check whether there is any instance of Town
prefix ex:<http://GP-onto.fi.upm.es/exercise2#>
ask {
?x a ex:Town
}