-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathSPARQL (Basic).txt
115 lines (92 loc) · 4.04 KB
/
SPARQL (Basic).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
/* SPARQL Questionnaire (Basic) Provide the SPARQL query and the result for the following queries expressed in natural language. */
/* 1. Get all the classes */
SELECT DISTINCT ?class
WHERE {
?class a rdfs:Class.
}
/* 2. Get all the subclasses of the class Establishment */
PREFIX url: <http://GP-onto.fi.upm.es/exercise2#>
SELECT ?subclass
WHERE{
?subclass rdfs:subClassOf url:Establishment.
}
/* 3. Get all instances of the class City
PREFIX url: <http://GP-onto.fi.upm.es/exercise2#>
SELECT ?city
WHERE{
?city a url:City.
}
/* 4. Get the number of inhabitants of Santiago de Compostela */
PREFIX url: <http://GP-onto.fi.upm.es/exercise2#>
SELECT ?inhabitant
WHERE{
url:Santiago_de_Compostela url:hasInhabitantNumber ?inhabitant.
}
/* 5. Get the number of inhabitants of Santiago de Compostela and Arzua */
PREFIX url: <http://GP-onto.fi.upm.es/exercise2#>
SELECT ?inhabitantS ?inhabitantA
WHERE{
url:Santiago_de_Compostela url:hasInhabitantNumber ?inhabitantS.
url:Arzua url:hasInhabitantNumber ?inhabitantA.
}
/* 6. Get all places, together with the number of inhabitants, ordered by the place name (ascending) */
PREFIX url: <http://GP-onto.fi.upm.es/exercise2#>
SELECT ?place ?inhabitant
WHERE{
?place url:hasInhabitantNumber ?inhabitant.
}
ORDER BY ASC(?place)
/* 7. Get all instances of Locality together with their number of inhabitants (if this information exists) */
PREFIX url: <http://GP-onto.fi.upm.es/exercise2#>
SELECT ?locality ?inhabitant
WHERE{
?loc a ?subclass.
?subclass rdfs:subClassOf url:Locality.
OPTIONAL {?locality url:hasInhabitantNumber ?inhabitant.}
}
/* 8. Get all places with more than 200.000 inhabitants */
/* 9. Get postal address data for Pazo_Breogan (street, number, locality, province) */
/* 10. Get all subclasses of class Location */
/* 11. Get all instances of class Locality */
/* 12. Describe the resource with rdfs:label "Madrid” */
/* 13. Construct a graph that relates directly all touristic places with their provinces, using a new property called ”isIn” */
/* 14. Check whether there is any instance of Town */
SPARQL Questionnaire (Advanced) Provide the SPARQL query and the result for the following queries expressed in natural language. The endpoint that you can use for this exercise is: http://es.dbpedia.org/sparql
/* A1. Dame todas las propiedades aplicables a las instancias de la clase Politician (http://dbpedia.org/ontology/Politician) */
SELECT DISTINCT ?p
WHERE {
?x a <http://dbpedia.org/ontology/Politician>.
?x ?p ?y
}
/* A2. Dame todas las propiedades, exceptuando rdf:type, aplicables a las instancias de la clase Politician (http://dbpedia.org/ontology/Politician) */
SELECT DISTINCT ?p
WHERE {
?x a <http://dbpedia.org/ontology/Politician>.
?x ?p ?y
FILTER(?p!=rdf:type)
}
/* A3. ¿Cuántos valores distintos se pueden encontrar para las propiedades, exceptuando rdf:type, de las instancias de la clase Politician (http://dbpedia.org/ontology/Politician)? */
SELECT COUNT DISTINCT ?p
WHERE {
?x a <http://dbpedia.org/ontology/Politician>.
?x ?p ?y
FILTER(?p!=rdf:type)
}
/* A4. Para cada una de las propiedades, exceptuando rdf:type, aplicables a las instancias de la clase Politician (http://dbpedia.org/ontology/Politician), dime cuántos valores distintos toman en dichas instancias */
SELECT COUNT DISTINCT ?p ?c
WHERE {
?x a <http://dbpedia.org/ontology/Politician> .
?x ?p ?y .
?y a ?c
FILTER (?p!=rdf:type)
}
/* A5. Para cada una de las propiedades, exceptuando rdf:type, aplicables a las instancias de la clase Politician (http://dbpedia.org/ontology/Politician), dime la media de valores distintos que toman en dichas instancias. */
/* A6. Para cada una de las propiedades, exceptuando rdf:type, aplicables a las instancias de la clase Politician (http://dbpedia.org/ontology/Politician), dime el máximo número de valores distintos que toman entre todas sus instancias, ordenado de mayor a menor */
SELECT DISTINCT ?p (count(*) as ?count)
WHERE {
?x a <http://dbpedia.org/ontology/Politician> .
?x ?p ?y .
?y a ?c
FILTER (?p!=rdf:type)
}
ORDER BY DESC(?count)