Exercise 1:

PREFIX foaf:

SELECT ?name WHERE { ?person foaf:name ?name . }

Exercise 2:

PREFIX db: PREFIX onto:

SELECT * WHERE { {?s onto:birthPlace db:Liverpool} UNION {?s onto:deathPlace db:Liverpool}

}

Exercise 3:

PREFIX rdfs: SELECT ?label WHERE { ?movie a . ?movie rdfs:label ?label . FILTER (lang(?label) = 'en') } LIMIT 10

Exercise 4:

PREFIX dbpedia-owl: PREFIX dbpprop:

SELECT DISTINCT ?country ?cnt WHERE { ?country a dbpedia-owl:Country . ?country dbpprop:populationCensus ?cnt } ORDER BY DESC(?cnt) LIMIT 5 [NOTE: we have empirically verified that using the „population“ property instead of „populationCensus“ gives meaningless results; even worst if we look for resources that are „PopulatedPlace“, and we look for their „populationTotal“]

Exercise 5:

PREFIX s: PREFIX dbp: PREFIX dbo: PREFIX dbr:

SELECT * WHERE { ?hotel a s:Hotel . {?hotel dbo:location dbr:Milan} UNION {?hotel dbo:location dbr:Venice} . OPTIONAL { ?hotel dbp:website ?website } } [NOTE: using dbo:Hotel gives poor results]

Exercise 6:

PREFIX rdfs: PREFIX dbpedia: PREFIX dbo: PREFIX dbc: PREFIX dcterms:

SELECT ?c WHERE { ?s dcterms:subject dbc:States_of_the_United_States . ?s dbo:capital ?c . } ORDER BY asc(?c) [NOTE: another reasonable possibility would seem to be using the resource http://dbpedia.org/ontology/Capital (subclass of dbo:City), but unfortunately it seems that there are no instances therein]

Exercise 7:

PREFIX dbpedia: PREFIX dbpedia-owl:

ASK { dbpedia:Guardians_of_the_Galaxy_Vol._2 dbpedia-owl:starring dbpedia:Chris_Pratt . }

Exercise 8:

PREFIX prop: ASK { prop:length ?amazon . prop:length ?nile . FILTER(?amazon > ?nile) . }

Exercise 9:

PREFIX dbo: PREFIX res:

ASK { res:Google dbo:numberOfEmployees ?numberGoogle . res: dbo:numberOfEmployees ?numberFacebook . FILTER(?numberGoogle > ?numberFacebook) }

Exercise 10: PREFIX dbo: PREFIX res:

ASK { res:Google dbo:locationCity ?location . res:Google dbo:numberOfEmployees ?numberGoogle . ?company dbo:locationCity ?location . ?company dbo:numberOfEmployees ?numberCompany . FILTER(?numberCompany > ?numberGoogle) }

Exercise 11a:

PREFIX : PREFIX dbo: PREFIX dbc: PREFIX dcterms: PREFIX dbp:

SELECT ?name, ?birthDate WHERE { ?nobel dcterms:subject dbc:Nobel_laureates_in_Physics . ?nobel dbo:birthDate ?birthDate . ?nobel dbp:name ?name . }

Exercise 11b:

PREFIX : PREFIX dbo: PREFIX dbc: PREFIX dcterms: PREFIX dbp:

SELECT ?name, ?birthDate, ?deathDate WHERE { ?nobel dcterms:subject dbc:Nobel_laureates_in_Physics . ?nobel dbo:birthDate ?birthDate . ?nobel dbo:deathDate ?deathDate . ?nobel dbp:name ?name . } ORDER BY asc(?birthDate)

Exercise 11c:

PREFIX : PREFIX dbo: PREFIX dbc: PREFIX dcterms: PREFIX dbp:

SELECT ?nobel, ?name, ?birthDate, ?deathDate WHERE { ?nobel dcterms:subject dbc:Nobel_laureates_in_Physics . ?nobel dbo:birthDate ?birthDate . ?nobel dbp:name ?name . OPTIONAL { ?nobel dbo:deathDate ?deathDate } } ORDER BY asc(?birthDate)

Exercise 12:

PREFIX xsd: PREFIX foaf: PREFIX :

SELECT ?name ?birth ?death ?person WHERE { ?person dbo:birthPlace :Berlin . ?person dbo:birthDate ?birth . ?person foaf:name ?name . ?person dbo:deathDate ?death . FILTER (?birth < "1900-01-01"^^xsd:date) . } ORDER BY ?name [NOTE: better also converting ?birth into xsd:date, since in some triples it's something different, leading to wrong results]

Exercise 13:

PREFIX dbo: PREFIX res:

CONSTRUCT { ?company1 dbo:biggerThan ?company2 . ?company2 dbo:smallerThan ?company1 . } WHERE { ?company1 dbo:numberOfEmployees ?employees1. ?company2 dbo:numberOfEmployees ?employees2 . FILTER(?employees1 > ?employees2) } LIMIT 100

Exercise 14:

…………

Exercise 15:

PREFIX owl: PREFIX rdfs: PREFIX movie: PREFIX dcterms: PREFIX rdf: PREFIX dbo:

SELECT ?label1 ?genre ?distributor WHERE { SERVICE { SELECT DISTINCT ?label1 ?genre WHERE{ ?movie1 rdf:type movie:film . ?movie1 rdfs:label ?label1 . ?movie1 movie:genre ?genre . ?genre movie:film_genre_name ?genreName . FILTER(?genreName = "Action") } LIMIT 10 } SERVICE { SELECT DISTINCT ?label2 ?distributor WHERE{ ?movie2 a . ?movie2 rdfs:label ?label2 . OPTIONAL {?movie2 dbo:distributor ?distributor} } LIMIT 10 } FILTER(?label1 = ?label2) }

Exercise 16:

PREFIX owl: PREFIX rdfs: PREFIX movie: PREFIX dcterms: PREFIX rdf: PREFIX dbo: PREFIX foaf:

SELECT ?label1 ?distributor ?countryMovie ?countryDistributor WHERE { SERVICE { SELECT DISTINCT ?label1 ?countryMovie WHERE{ ?movie1 rdf:type movie:film . ?movie1 rdfs:label ?label1 . ?movie1 movie:country ?country . ?country movie:country_name ?countryMovie . } LIMIT 10 } SERVICE { SELECT DISTINCT ?label2 ?distributor ?countryDistributor WHERE{ ?movie2 a . ?movie2 rdfs:label ?label2 . ?movie2 dbo:distributor ?distributor . ?distributor dbo:location ?location . ?location foaf:name ?countryDistributor } LIMIT 10 } FILTER(?label1 = ?label2 && ?countryMovie = ?countryDistributor) }