SPARQL tutorial
New to topics? Read the documentation here!
In this tutorial, we will use the Jena SPARQL hello world as a starting point. Tested on Apache Jena 4.10.0.
Basic query on rdf/vcard.ttl RDF Turtle data to find the person with full name "John Smith":Output:
sparql --data=rdf/vcard.ttl --query=<( printf '%s\n' 'SELECT ?x WHERE { ?x <http://www.w3.org/2001/vcard-rdf/3.0#FN> "John Smith" }')
---------------------------------
| x |
=================================
| <http://somewhere/JohnSmith/> |
---------------------------------
To avoid writing Output:
http://www.w3.org/2001/vcard-rdf/3.0#
a billion times as queries grow larger, we can use the PREFIX
syntax:sparql --data=rdf/vcard.ttl --query=<( printf '%s\n' '
PREFIX vc: <http://www.w3.org/2001/vcard-rdf/3.0#>
SELECT ?x
WHERE { ?x vc:FN "John Smith" }
')
---------------------------------
| x |
=================================
| <http://somewhere/JohnSmith/> |
---------------------------------
Bibliography:
- UniProt contains some amazing examples runnable on their servers: sparql.uniprot.org/.well-known/sparql-examples/