Exercise 1:
PREFIX foaf:
SELECT ?name WHERE { ?person foaf:name ?name . }
Exercise 2:
PREFIX db:
SELECT * WHERE { {?s onto:birthPlace db:Liverpool} UNION {?s onto:deathPlace db:Liverpool}
}
Exercise 3:
PREFIX rdfs:
Exercise 4:
PREFIX dbpedia-owl:
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:
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:
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:
ASK { dbpedia:Guardians_of_the_Galaxy_Vol._2 dbpedia-owl:starring dbpedia:Chris_Pratt . }
Exercise 8:
PREFIX prop:
Exercise 9:
PREFIX dbo:
ASK { res:Google dbo:numberOfEmployees ?numberGoogle . res:Facebook dbo:numberOfEmployees ?numberFacebook . FILTER(?numberGoogle > ?numberFacebook) }
Exercise 10: PREFIX dbo:
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 :
SELECT ?name, ?birthDate WHERE { ?nobel dcterms:subject dbc:Nobel_laureates_in_Physics . ?nobel dbo:birthDate ?birthDate . ?nobel dbp:name ?name . }
Exercise 11b:
PREFIX :
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 :
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:
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:
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:
SELECT ?label1 ?genre ?distributor WHERE { SERVICE
Exercise 16:
PREFIX owl:
SELECT ?label1 ?distributor ?countryMovie ?countryDistributor WHERE { SERVICE