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#> ...

Get Semantic Web Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.