Sparql Examples Q 1 Querying BernersLees FOAF data
Sparql Examples
Q 1: Querying Berners-Lee’s FOAF data • Redland Rasqal RDF Query Demonstration • http: //librdf. org/2005/sparqling • Data: http: //dig. csail. mit. edu/2008/webdav/timbl/foaf. rdf • Query: PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> SELECT ? name WHERE { ? person foaf: name ? name. }
Q 2: Querying Berners-Lee’s FOAF data • Redland Rasqal RDF Query Demonstration • http: //librdf. org/2005/sparqling • Data: http: //dig. csail. mit. edu/2008/webdav/timbl/foaf. rdf • Query: PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> SELECT * WHERE { ? person foaf: name ? name. ? person foaf: mbox ? email. }
Q 3: Querying Berners-Lee’s FOAF data • Redland Rasqal RDF Query Demonstration • http: //librdf. org/2005/sparqling • Data: http: //dig. csail. mit. edu/2008/webdav/timbl/foaf. rdf • Query: PREFIX foaf: <http: //xmlns. com/foaf/0. 1/> PREFIX card: <http: //www. w 3. org/People/Berners-Lee/card#> SELECT ? homepage WHERE { card: i foaf: knows ? known foaf: homepage ? homepage. }
Q 4: DBPedia • http: //dbpedia. org/snorql/ • Prefix: PREFIX ns#> PREFIX PREFIX owl: <http: //www. w 3. org/2002/07/owl#> xsd: <http: //www. w 3. org/2001/XMLSchema#> rdfs: <http: //www. w 3. org/2000/01/rdf-schema#> rdf: <http: //www. w 3. org/1999/02/22 -rdf-syntaxfoaf: <http: //xmlns. com/foaf/0. 1/> dc: <http: //purl. org/dc/elements/1. 1/> : <http: //dbpedia. org/resource/> dbpedia 2: <http: //dbpedia. org/property/> dbpedia: <http: //dbpedia. org/> skos: <http: //www. w 3. org/2004/02/skos/core#>
Q 4: People who were born in Berlin before 1900 • Query: SELECT ? name ? birth ? death ? person WHERE { ? person dbo: birth. Place : Berlin. ? person dbo: birth. Date ? birth. ? person foaf: name ? name. ? person dbo: death. Date ? death. FILTER (? birth < "1900 -01 -01"^^xsd: date). } ORDER BY ? name
Q 5: German musicians with German and English descriptions • Query: SELECT ? name ? description_en ? description_de ? musician WHERE {? musician foaf: name ? name. OPTIONAL { ? musician rdfs: comment ? description_en. FILTER (LANG(? description_en) = 'en'). OPTIONAL { ? musician rdfs: comment ? description_de. FILTER (LANG(? description_de) = 'de'). } } }
Q 6: German musicians who were born in Berlin • Query: SELECT ? name ? birth ? description ? person WHERE { ? person a dbo: Musical. Artist. ? person dbo: birth. Place : Berlin. ? person dbo: birth. Date ? birth. ? person foaf: name ? name. ? person rdfs: comment ? description. FILTER (LANG(? description) = 'en'). } ORDER BY ? name
Q 7: Soccer players who are born in a country with more than 10 million inhabitants, who played as goalkeeper for a club that has a stadium with more than 30, 000 seats and the club country is different from the birth country • Query: SELECT distinct ? soccerplayer ? country. Of. Birth ? team ? country. Of. Team ? stadiumcapacity { ? soccerplayer a dbo: Soccer. Player ; dbo: position|dbp: position <http: //dbpedia. org/resource/Goalkeeper_(association_football)> ; dbo: birth. Place/dbo: country* ? country. Of. Birth ; #dbo: number 13 ; dbo: team ? team dbo: capacity ? stadiumcapacity ; dbo: ground ? country. Of. Team. ? country. Of. Birth a dbo: Country ; dbo: population. Total ? population. ? country. Of. Team a dbo: Country. FILTER (? country. Of. Team != ? country. Of. Birth) FILTER (? stadiumcapacity > 30000) FILTER (? population > 10000000) } order by ? soccerplayer
Q 8: Is Amazon river longer than Nile • Sparql Endpoint: • http: //dbpedia. org/sparql • Data: http: //dbpedia. org • Query: PREFIX prop: <http: //dbpedia. org/property/> ASK { <http: //dbpedia. org/resource/Amazon_River> prop: length ? amazon. <http: //dbpedia. org/resource/Nile> prop: length ? nile. FILTER(? amazon > ? nile). }
- Slides: 11