USING OPERATORS
(FILTER and related operators MINUS, OPTIONAL, UNION)
107
?artistName is English
?albumName is English
108
109
110
111
112
113
reference: http://www.w3.org/TR/rdf-sparql-query/
114
115
116
Result:
?first
?last
?instrument
"Craig"
"Ellis"
" trumpet"
"Richard"
"Mutt"
sax
117
118
119
Result:
?first
?last
"Cindy"
"Marshall"
"Richard"
"Mutt"
?workNum
120
FILTER OPERATOR
QUIZZES
DBpedia SPARQL Endpoint
121
Quiz (1)
1.1 Using DBpedia SPARQL Endpoint, find albums produced by
122
Answer (1)
SELECT ?albumName
WHERE {
?album dbo:producer <http://DBpedia.org/resource/Timbaland> .
?album rdfs:label ?albumName .
}
SELECT ?albumName
WHERE {
?album dbo:producer <http://DBpedia.org/resource/Timbaland> .
?album rdfs:label ?albumName .
FILTER (lang(?albumName) = en)
}
123
Quiz (2)
Using DBpedia SPARQL Endpoint, find albums produced by
124
Answer (2)
SELECT ?album ?rdate
WHERE {
?album dbo:producer <http://DBpedia.org/resource/Timbaland>;
dbp:released ?rdate.
filter (datatype(?rdate)= xsd:date).
}
125
Quiz (3)
Find American universities in which the number of students >
20,000 (xsd:integer).
126
Answer (3)
select ?univ
where{
?univ a dbo:University.
?univ dbo:country dbr:United_States.
?univ dbo:numberOfStudents ?number.
filter (?number >= "20000"^^xsd:integer)
}
127
Quiz (4)
Find California-based companies which deal in software or
hardware.
128
Answer (4)
select distinct ?firm
where{
?firm a dbo:Company.
?firm dbo:industry ?industry.
filter (?industry IN (dbr:Software, dbr:Computer_hardware))
?firm dbo:locationCity ?location.
filter (?location = dbr:California)
}
129
Quiz (5)
5.1 Find public companies in which the number of employees >
300,000 (xsd:integer).
5.2 Show the number of employees for each company.
130
Answer (5)
SELECT distinct ?s ?Employees
WHERE
{
?s dbo:type dbr:Public_company.
?s dbo:numberOfEmployees ?Employees.
FILTER(?Employees>"300000"^^xsd:integer).
}
131
Quiz (6)
6.1 Using DBpedia SPARQL Endpoint, find albums produced by
132
Answer (6)
SELECT ?album ?rdate
WHERE {
?album dbo:producer <http://DBpedia.org/resource/Timbaland>;
dbp:released ?rdate.
filter regex(?album, "Who")
filter (datatype(?rdate)= xsd:date)
filter (?rdate >="1990-01-01"^^xsd:date
&& ?rdate <= "1999-12-31" ^^xsd:date).
}
133
Quiz (7)
Find movie directors (yago:FilmDirector110088200) who have
134
Answer (7)
SELECT ?movieDirector ?date
WHERE
{
?movieDirector rdf:type yago:FilmDirector110088200.
OPTIONAL {?movieDirector dbo:activeYearsStartYear ?date.}
FILTER (!bound(?date))
}
135
Quiz (8)
Find California-based companies with no thumbnail
(dbo:thumbnail).
136
Answer (8)
select ?c
where {
?c a dbo:Company.
?c dbo:locationCity dbr:California.
optional {?c dbo:thumbnail ?thumbnail}.
filter (!bound(?thumbnail))
}
137
Quiz (9)
Find American universities with no information on the state
138
Answer (9)
select ?univ ?state ?city
where{
?univ a dbo:University.
?univ dbo:country dbr:United_States.
Optional {?univ dbo:state ?state}
Optional {?univ dbo:city ?city}
filter (!bound(?state))
filter (!bound(?city))
}
139
Quiz (10)
10.1 Find basketball players (dbo:BasketballPlayer) who were in
140
Answer (10)
select ?univ ?state ?city
where{
?univ a dbo:University.
?univ dbo:country dbr:United_States.
Optional {?univ dbo:state ?state}
Optional {?univ dbo:city ?city}
filter (!bound(?state))
filter (!bound(?city))
}
141
Quiz (11)
Using NOT EXISTS, find American professional wrestlers
142
Answer (11)
SELECT ?ProfWr
WHERE
{
?ProfWr rdf:type
yago:WikicatAmericanProfessionalWrestlers.
FILTER NOT EXISTS{?ProfWr dbo:debut ?Ddate.}
}
143
Quiz (12)
Using NOT EXISTS, find California-based companies that do
144
Answer (12)
select ?c
where {
?c a dbo:Company.
?c dbo:locationCity dbr:California.
filter not exists {?c dbo:thumbnail ?thumbnail.}
}
145
Quiz (13)
Using NOT EXISTS, find American universities with no
146
Answer (13)
select ?univ
where{
?univ a dbo:University.
?univ dbo:country dbr:United_States.
filter not exists {?univ dbo:state ?state}
filter not exists {?univ dbo:city ?city}
}
147
Quiz (14)
Find Michael Jackson albums produced by Quincy Jones
(dbr:Quincy_Jones).
148
Answer (14)
SELECT ?albumname
WHERE
{
?albumname dbo:artist dbr:Michael_Jackson;
rdf:type dbo:Album;
dbp:producer ?producer.
FILTER (?producer = dbr:Quincy_Jones).
}
149
Quiz (15)
Find universities with the term California in their name.
150
Answer (15)
select ?univ
where{
?univ a dbo:University.
filter regex(?univ, California")
}
151
Quiz (16)
Without differentiating between upper and lowercase letters,
find James Brown albums with the term funky in the title.
152
Answer (16)
SELECT ?funkyAlbum
WHERE
{
?funkyAlbum dbo:artist dbr:James_Brown;
rdf:type dbo:Album.
FILTER regex(?funkyAlbum,"funky","i")
}
153
Quiz (17)
Find songs with lyrics written by Freddie Mercury
154
Answer (17)
SELECT ?QLsong
WHERE
{
?QLsong dbo:writer <http://DBpedia.org/
resource/Freddie_Mercury>.
FILTER regex(?QLsong,"love","i")
}
155
Quiz (18)
Find universities which use veritas or truth as their
motto.
156
Answer (18)
select ?s ?motto
where
{
?s rdf:type dbo:University;
dbo:motto ?motto.
FILTER(?motto IN("Veritas","Truth")).
}
157
Quiz (19)
Find actors (umbel-rc:Actor) who have married Brad Pitt.
158
Answer (19)
select ?s
where
{
?s rdf:type umbel-rc:Actor;
dbp:spouse ?spouse.
FILTER regex(?spouse, "Brad_Pitt").
}
159
160
161
Result:
?first
?last
"Cindy"
"Marshall"
"Richard"
"Mutt"
?workNum
162
Quiz (1)
Find South Korean soccer players who have never been on the
163
Answer (1)
SELECT ?Kplayer
WHERE
{
?Kplayer rdf:type dbo:SoccerPlayer;
dbo:birthPlace dbr:South_Korea.
MINUS{?Kplayer dbp:nationalteam ?national.}
}
164
Quiz (2)
Find South Korean baseball players without a specified position.
165
Answer (2)
SELECT ?name
WHERE
{
?name a dbo:BaseballPlayer;
dbp:birthPlace dbr:South_Korea.
MINUS {?name dbp:position ?p}
}
166
167
168
Result:
?first
?last
?worktel
"Craig"
"Ellis"
"(245) 315-5486"
169
170
Result:
?first
?last
?worktel
"Craig"
"Ellis"
"(245) 315-5486"
"Cindy"
"Marshall"
"Richard"
"Mutt"
171
172
Result:
?first
?last
"Craig"
"Ellis"
"Cindy"
"Marshall"
"Richard"
"Mutt"
?worktel
?nick
173
174
Result:
?last
?worktel
"Ellis"
"(245)
315-5486"
"Cindy"
"Marshall"
"Richard"
"Mutt"
?nick
Dick
175
Quiz (1)
Find all Steven Spielberg films and specify their budgets where
176
Answer (1)
SELECT ?movie ?budget
WHERE
{
?movie dbo:director <http://DBpedia.org/resource/Steven_Spielberg>.
OPTIONAL {?movie dbo:budget ?budget}
}
177
Quiz (2)
2.1 Find soccer players born in South Korea or in your home
country using http://DBpedia.org/sparql
2.2 Find additional information about their height (dbo:height).
Should there be no height information available, leave this result
blank.
178
Answer (2)
select distinct ?s ?height
where {
?s a dbo:SoccerPlayer ;
dbp:birthPlace dbr:South_Korea .
OPTIONAL
{?s dbo:height ?height}
} order by ASC(?s)
179
180
181
Result:
?first
?last
?instrument
"Craig"
"Ellis"
" trumpet"
"Richard"
"Mutt"
sax
"Richard"
"Mutt"
clarinet
182
Result:
?first
?last
?instrument
"Craig"
"Ellis"
" trumpet"
"Richard"
"Mutt"
sax
"Richard"
"Mutt"
clarinet
183
Quiz (1)
1.1 Find soccer players who were born in Seoul (dbr:Seoul)
using DBpedia.org/sparql and display the results alongside the
citys population.
1.2 Sort results in ascending order.
184
Answer (1)
select distinct ?s ?birthplace ?population
where {
{
?s a dbo:SoccerPlayer ;
dbp:birthPlace dbr:Seoul ;
dbp:birthPlace ?birthplace.
}
UNION
{
dbr:Seoul dbo:populationTotal ?population.
}
} order by ASC(?s)
185
Quiz (2)
2.1 Find soccer players who were born in Seoul (dbr:Seoul)
using DBpedia.org/sparql.
2.2 Show soccer players who were born in Incheon
(dbr:Incheon) using the UNION keyword.
2.3 Sorts results in descending order.
186
Answer (2)
select distinct ?s ?birthplace
where {
{
?s a dbo:SoccerPlayer ;
dbp:birthPlace dbr:Seoul ;
dbp:birthPlace ?birthplace.
}
UNION
{
?s a dbo:SoccerPlayer ;
dbp:birthPlace dbr:Incheon ;
dbp:birthPlace ?birthplace.
}
} order by DESC(?s)
187
Quiz (3)
Find all American rappers and indicate those from New York
and California.
188
Answer (3)
SELECT ?MC ?bornIn
WHERE
{
?MC a yago:Rapper110507482;
a yago:WikicatAmericanPeople.
?MC dbo:birthPlace ?bornIn.
{?MC dbo:birthPlace dbr:New_York.}
UNION
{?MC dbo:birthPlace dbr:California.}
}
189
Quiz (4)
Find American and British universities and display their name
and country.
190
Answer (4)
select ?USuniv ?UKuniv
where{
{?USuniv a dbo:University.
?USuniv dbo:country dbr:United_States.
?USuniv dbo:country ?country.}
union
{?UKuniv a dbo:University.
?UKuniv dbo:country dbr:England.
?UKuniv dbo:country ?country.}
}
191
Quiz (5)
Find writers who graduated from Harvard or Yale Law School
192
Answer (5)
select ?s ?university
where
{
{?s dbo:almaMater dbr:Harvard_University;
dbo:almaMater ?university;
a dbo:Writer.}
UNION
{?s dbo:almaMater dbr:Yale_Law_School;
dbo:almaMater ?university;
a dbo:Writer.}
} order by ASC(?s)