After this part of the tutorial you should
In this section:
@prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name "Alice" . _:a foaf:mbox <mailto:alice@example.net> . _:b foaf:name "Bob" .
PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name WHERE { ?x foaf:name ?name }
----------- | name | =========== | "Bob" | | "Alice" | -----------
A set of triple patterns, all of which must be matched by a solution.
Definition: Pattern Solution of Basic Patterns
A Pattern Solution of Graph Pattern GP on graph G is any substitution S such that S(GP) is a subgraph of G.
@prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name "Alice" . _:a foaf:mbox <mailto:alice@example.net> . _:b foaf:name "Bob" .
PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name WHERE { ?person foaf:mbox <mailto:alice@example.net> . ?person foaf:name ?name . }
----------- | name | =========== | "Alice" | -----------
.
) separate patternsPREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name WHERE { ?person foaf:mbox <mailto:alice@example.net> ; foaf:name ?name . }
FILTER ?x < 3 .
FILTER regex(?name , "Smith") .
<
, >
, =
, <=
, >=
and
!=
for value comparison@prefix dc: <http://purl.org/dc/elements/1.1/> . @prefix stock: <http://example.org/stock#> . @prefix inv: <http://example.org/inventory#> . stock:book1 dc:title "SPARQL Query Language Tutorial" . stock:book1 inv:price 10 . stock:book1 inv:quantity 3 . stock:book2 dc:title "SPARQL Query Language (2nd ed)" . stock:book2 inv:price 20 ; inv:quantity 5 . stock:book3 dc:title "Moving from SQL to SPARQL" . stock:book3 inv:price 5 ; inv:quantity 0 . stock:book4 dc:title "Applying XQuery" . stock:book4 inv:price 20 ; inv:quantity 8 .
PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX stock: <http://example.org/stock#> PREFIX inv: <http://example.org/inventory#> SELECT ?book ?title WHERE { ?book dc:title ?title . ?book inv:price ?price . FILTER ?price < 15 . ?book inv:quantity ?num . FILTER ?num > 0 . }
-------------------------------------------------- | book | title | ================================================== | stock:book1 | "SPARQL Query Language Tutorial" | --------------------------------------------------
@prefix foaf: <http://xmlns.com/foaf/0.1/> . _:a foaf:name "Alice" . _:a foaf:nick "A-online" . _:b foaf:name "Bob" .
PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?nick WHERE { ?x foaf:name ?name . OPTIONAL {?x foaf:nick ?nick } }
------------------------ | name | nick | ======================== | "Alice" | "A-online" | | "Bob" | | ------------------------
@prefix dc10: <http://purl.org/dc/elements/1.0/> . @prefix dc11: <http://purl.org/dc/elements/1.1/> . _:a dc10:title "SPARQL Query Language Tutorial" . _:b dc11:title "SPARQL Query Language (2nd ed)" . _:c dc10:title "SPARQL" . _:c dc11:title "SPARQL" .
PREFIX dc10: <http://purl.org/dc/elements/1.0/> PREFIX dc11: <http://purl.org/dc/elements/1.1/> SELECT DISTINCT ?title WHERE { { ?book dc10:title ?title } UNION { ?book dc11:title ?title } }
------------------------------------ | title | ==================================== | "SPARQL Query Language Tutorial" | | "SPARQL" | | "SPARQL Query Language (2nd ed)" | ------------------------------------
@prefix dc10: <http://purl.org/dc/elements/1.0/> . @prefix dc11: <http://purl.org/dc/elements/1.1/> . _:a dc10:title "SPARQL Query Language Tutorial" . _:b dc11:title "SPARQL Query Language (2nd ed)" . _:c dc10:title "SPARQL" . _:c dc11:title "SPARQL" .
PREFIX dc10: <http://purl.org/dc/elements/1.0/> PREFIX dc11: <http://purl.org/dc/elements/1.1/> SELECT ?title_10 ?title_11 WHERE { { ?book dc10:title ?title_10 } UNION { ?book dc11:title ?title_11 } }
----------------------------------------------------------------------- | title_10 | title_11 | ======================================================================= | "SPARQL Query Language Tutorial" | | | "SPARQL" | | | | "SPARQL" | | | "SPARQL Query Language (2nd ed)" | -----------------------------------------------------------------------
SPARQL uses graph pattern matching
Values can be constrained by filters
Later, we will see matching over a set of graphs
Copyright 2005 Dave Beckett, Steve Harris, Eric Prud'hommeaux and Andy Seaborne. Terms of use are given on the main Introduction to RDF Query with SPARQL Tutorial page.