-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathqueries.sparql
More file actions
126 lines (103 loc) · 3.23 KB
/
Copy pathqueries.sparql
File metadata and controls
126 lines (103 loc) · 3.23 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
// Ismael Ayat Ortiz - w140334 - Ismmael
///// 1.) How many accidents were there in Madrid in 2013?
PREFIX mv: <http://example.org/myVocabulary#>
PREFIX qb: <http://purl.org/linked-data/cube#>
SELECT (SUM(?x) AS ?numberOfAccidents) WHERE {
?obs a qb:Observation ;
mv:numberOfAccidents ?x .
}
// Resultado: 11749
///// 2.) Give me the number of accidens in Usera for each type of accident
PREFIX mv: <http://example.org/myVocabulary#>
PREFIX qb: <http://purl.org/linked-data/cube#>
SELECT ?accidentType xsd:integer(?numberAccidents) AS ?number WHERE {
?obs a qb:Observation ;
mv:relatedDistrict "USERA";
mv:hasAccidentType ?accidentType ;
mv:numberOfAccidents ?numberAccidents
}
// Resultado:
// http://example.org/myVocabulary#DoubleCollision 204
// http://example.org/myVocabulary#MultipleCollision 28
// http://example.org/myVocabulary#CollisionWithObject 70
// http://example.org/myVocabulary#RunOver 59
// http://example.org/myVocabulary#Overturn 2
// http://example.org/myVocabulary#MotorcycleFall 13
// http://example.org/myVocabulary#MopedFall 5
// http://example.org/myVocabulary#BicycleFall 1
// http://example.org/myVocabulary#BusPassengerFall 3
// http://example.org/myVocabulary#OtherCause 2
///// 3.) Give me the number of multiple collisions for each district
PREFIX mv: <http://example.org/myVocabulary#>
PREFIX qb: <http://purl.org/linked-data/cube#>
SELECT ?x AS ?district xsd:integer(?y) AS ?collisionsNumber WHERE{
?obs a qb:Observation ;
mv:relatedDistrict ?x ;
mv:hasAccidentType mv:MultipleCollision ;
mv:numberOfAccidents ?y .
}
// Resultado:
// BARAJAS 4
// VICALVARO 4
// VILLA DE VALLECAS 4
// VILLAVERDE 11
// MORATALAZ 14
// SAN BLAS 16
// HORTALEZA 18
// USERA 28
// LATINA 29
// CHAMBERI 30
// CENTRO 33
// TETUAN 35
// PUENTE DE VALLECAS 37
// CARABANCHEL 40
// FUENCARRAL-EL PARDO 42
// ARGANZUELA 50
// CIUDAD LINEAL 52
// RETIRO 59
// MONCLOA-ARAVACA 65
// SALAMANCA 70
// CHAMARTIN 82
///// 4.) Which is the district were the number of bicycle falls was higher in 2013?
PREFIX mv: <http://example.org/myVocabulary#>
PREFIX qb: <http://purl.org/linked-data/cube#>
SELECT ?x AS ?district xsd:integer(MAX(?y)) AS ?numberAccidents WHERE {
?obs a qb:Observation ;
mv:relatedDistrict ?x ;
mv:numberOfAccidents ?y;
mv:hasAccidentType mv:BicycleFall .
}
ORDER BY DESC(?y)
// En este caso se elige el primer elemento de la lista (puesto que la última línea de la query ordena los elementos en orden descendente.
// En este caso hay tres distritos que son FUENCARRAL, MONCLOA y SAN BLAS con 13 cada uno.
///// 5.) Give me the districts with more than 500 accidents in 2013
PREFIX mv: <http://example.org/myVocabulary#>
PREFIX qb: <http://purl.org/linked-data/cube#>
SELECT ?x AS ?district ?y AS ?accidentNumber
WHERE {
{
SELECT ?x SUM(xsd:integer(?z)) AS ?y
WHERE
{
?obs a qb:Observation ;
mv:relatedDistrict ?x ;
mv:numberOfAccidents ?z .
}
}
}
HAVING(?y > 500)
//Resultado:
// TETUAN 594
// CENTRO 926
// CHAMBERI 715
// PUENTE DE VALLECAS 651
// RETIRO 593
// SAN BLAS 518
// ARGANZUELA 631
// CHAMARTIN 844
// FUENCARRAL-EL PARDO 682
// SALAMANCA 982
// CARABANCHEL 709
// CIUDAD LINEAL 750
// LATINA 530
// MONCLOA-ARAVACA 702