O'Reilly logo

Semantic Web Programming by Mike Dean, Andrew Perez-Lopez, Ryan Blace, Matthew Fisher, John Hebeler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix D. SPARQL

SPARQL is a recursive acronym for the SPARQL Protocol and RDF Query Language. This appendix contains several examples of the SPARQL query language and details, in alphabetical order, the operators and keywords that are part of the SPARQL recommendation. In the case of keywords, we give a short description. We list page numbers if a keyword or example is described in finer detail in the book. Also, we provide a reference URL to additional information in the W3C reference.

SPARQL Examples

The following examples can also be found in Chapter 6, "Discovering Information."

# George Washington's Namesakes
SELECT ?location
WHERE {
     ?person <http://www.w3.org/2000/01/rdf-schema#label>
         "George Washington"@en.
     ?location <http://dbpedia.org/property/namedFor> ?person
     }
# George Washington's Namesakes using prefixes PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dbprop: <http://dbpedia.org/property/> SELECT ?location WHERE { ?person rdfs:label "George Washington"@en. ?location dbprop:namedFor ?person } # A sorted query for information on George Washington PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dbprop: <http://dbpedia.org/property/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?job ?birthLoc ?picture WHERE { ?person rdfs:label "George Washington"@en; dbprop:occupation ?job; dbprop:birthPlace ?birthLoc; foaf:img ?picture } ORDER BY ?birthLoc DESC(?job) # Information about Tim Berners-Lee's FOAF friends PREFIX tbl: <http://www.w3.org/People/Berners-Lee/card#> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required