Source: cirosantilli/sparql-tutorial

= SPARQL tutorial
{c}

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 \a[rdf/vcard.ttl] <RDF Turtle> data to find the person with full name "John Smith":
``
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" }')
``
Output:
``
---------------------------------
| x                             |
=================================
| <http://somewhere/JohnSmith/> |
---------------------------------
``

To avoid writing `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" }
')
``
Output:
``
---------------------------------
| x                             |
=================================
| <http://somewhere/JohnSmith/> |
---------------------------------
``

Bibliography:
* <UniProt> contains some amazing examples runnable on their servers: https://sparql.uniprot.org/.well-known/sparql-examples/