Sparql Examples
Q1: 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 . }
Q2: 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 . }
Q3: 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.w3.org/People/Berners-Lee/card#> SELECT ?homepage WHERE { card:i foaf:knows ?known . ?known foaf:homepage ?homepage . }
Q4: DBPedia http://dbpedia.org/snorql/ Prefix: PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX : <http://dbpedia.org/resource/> PREFIX dbpedia2: <http://dbpedia.org/property/> PREFIX dbpedia: <http://dbpedia.org/> PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
Q4: People who were born in Berlin before 1900 Query: 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
Q5: 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') . } }
Q6: German musicians who were born in Berlin Query: SELECT ?name ?birth ?description ?person WHERE { ?person a dbo:MusicalArtist . ?person dbo:birthPlace :Berlin . ?person dbo:birthDate ?birth . ?person foaf:name ?name . ?person rdfs:comment ?description . FILTER (LANG(?description) = 'en') . } ORDER BY ?name
Q7: 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 ?countryOfBirth ?team ?countryOfTeam ?stadiumcapacity { ?soccerplayer a dbo:SoccerPlayer ; dbo:position|dbp:position <http://dbpedia.org/resource/Goalkeeper_(association_football)> ; dbo:birthPlace/dbo:country* ?countryOfBirth ; #dbo:number 13 ; dbo:team ?team . ?team dbo:capacity ?stadiumcapacity ; dbo:ground ?countryOfTeam . ?countryOfBirth a dbo:Country ; dbo:populationTotal ?population . ?countryOfTeam a dbo:Country . FILTER (?countryOfTeam != ?countryOfBirth) FILTER (?stadiumcapacity > 30000) FILTER (?population > 10000000) } order by ?soccerplayer
Q8: 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) . }