SPARQL RDF Query Language Reference v1 . 8 or Blank Node
Available from www.dajobe.org
Page 1
SPARQL RDF Query Language Reference v1 . 8 or Blank Node
SPARQLRDFQuery Language Reference v1.8
Copyright © 2005, 2006 Dave Beckett.
Latest version: <http://www.dajobe.org/2005/04-sparql/>
Comments to: dave@dajobe.org
1. RDF Model and SPARQL RDF Terms Syntax
RDF Graph: A set of RDF Triples
RDFTriple: A triple (3-tuple) of:
Subject: IRI
or Blank Node
Predicate: IRI
Object: IRI or Blank Node
or Literal
URI: An absolute IRI which may include a # fragment.
<http://www.w3.org/>
<http://example.org/#fragment>
<abc.rdf> Relative IRI resolved against base IRI.
<> Base IRI, usually the query document IRI
ex:name IRI shorthand using XML-style prefix ex and local name.
Declared with PREFIX (SPARQL) or @prefix (Turtle)
RDF Literal: A Unicode string with an optional language tag.
hello bonjour @fr
RDFTyped Literal: A Unicode string and datatype IRI for encoding datatypes.
abc ^^<http://example.org/myDatatype>
abbreviated with an XML QName style as:
10 ^^xsd:integer
Short forms for several common datatypes:
-10 -10 ^^xsd:integer
1.2345 1.2345 ^^xsd:decimal
true true ^^xsd:boolean
Blank Node: A node in a graph with a local name. The scope of the name is the RDF graph.
_:node
2. Common RDF Namespaces and Prefixes
Namespace Common Prefix Namespace URI
RDF rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
Dublin Core dc: http://purl.org/dc/elements/1.1/
FOAF foaf: http://xmlns.com/foaf/0.1/
XML Schema Datatypes xsd: http://www.w3.org/2001/XMLSchema#
RDFS rdfs: http://www.w3.org/2000/01/rdf-schema#
OWL owl: http://www.w3.org/2002/07/owl#
3. SPARQL Query Language Reference
Based on SPARQL Query 23 Nov 2005 <http://www.w3.org/TR/2005/WD-rdf-sparql-query-20051123/>.
RDFTerm: A part of an RDF Triple. An IRI, Blank Node or a Literal.
<uri> _:b1 Literal @en abc123 ^^my:datatype
Query Variable: Identifiers for binding to RDF Terms in matches.
?a / $b or in lists: $name $title $place
Anonymous
Query Variable:
Blank Nodes in a graph pattern act as variables that cannot be SELECTed
_:abc
Triple Pattern: An RDF Triple with Query Variables or blank nodes allowed in each term:
<http://example.org/abc> ?x Hello
?subject ?predicate ?object
Turtle abbreviations can be used for Triple Patterns, see Section 4.
Graph Pattern: A block that matches part of the queried RDF graph.
Basic
Graph Pattern:
A set of Triple Patterns binding RDF Terms in the graph to variables.
Written as a {..} block with '.' separating the triple patterns:
{ <http://example.org/abc> ?y Hello .
?subject $predicate Literal }
Group
Graph Pattern:
A graph pattern containing multiple graph patterns which must all match
{ { ?person rdf:type foaf:Person }
{ ?person foaf:name Dave } }
Optional
Graph Pattern:
A graph pattern which may fail to match and provide bindings but not
cause the entire query to fail. Written with OPTIONAL before a graph
pattern.
OPTIONAL { ?person foaf:nick ?nick }
Union
Graph Pattern:
A pair of graph patterns any of which may match and bind the same
variables. Written with the UNION keyword between two graph patterns.
{ ?node ex:name ?name } UNION
{ ?node vcard:FN ?name }
Graph
Graph Pattern:
A keyword for specifying a graph name to use or to return a graph name as a
binding. Written with the GRAPH keyword before a graph pattern.
GRAPH <http://example.org/myfoaf>
{ ?person foaf:name ?name }
GRAPH ?graph { ?person foaf:name ?name }
Value Constraints: A boolean expression in a graph pattern over query variables that constrains
matched graph patterns.
{ ?item ex:size $size . FILTER ($size < 10 ) }
4. SPARQL Query Language Structure
Prologue (optional) BASE <iri>
PREFIX prefix: <iri> (repeatable)
Query Result forms (required, pick 1) SELECT (DISTINCT)sequence of ?variable
SELECT (DISTINCT)*
DESCRIBE sequence of ?variable or <iri>
DESCRIBE *
CONSTRUCT { graph pattern }
ASK
Query Dataset Sources (optional) Add triples to the background graph (repeatable):
FROM <iri>
Add a named graph (repeatable):
FROM NAMED <iri>
Graph Pattern (optional, required for ASK) WHERE { graph pattern [ FILTER expression ]}
Query Results Ordering (optional) ORDER BY ...
Query Results Selection (optional) LIMIT n, OFFSET m
Copyright © 2005, 2006 Dave Beckett.
Latest version: <http://www.dajobe.org/2005/04-sparql/>
Comments to: dave@dajobe.org
1. RDF Model and SPARQL RDF Terms Syntax
RDF Graph: A set of RDF Triples
RDFTriple: A triple (3-tuple) of:
Subject: IRI
or Blank Node
Predicate: IRI
Object: IRI or Blank Node
or Literal
URI: An absolute IRI which may include a # fragment.
<http://www.w3.org/>
<http://example.org/#fragment>
<abc.rdf> Relative IRI resolved against base IRI.
<> Base IRI, usually the query document IRI
ex:name IRI shorthand using XML-style prefix ex and local name.
Declared with PREFIX (SPARQL) or @prefix (Turtle)
RDF Literal: A Unicode string with an optional language tag.
hello bonjour @fr
RDFTyped Literal: A Unicode string and datatype IRI for encoding datatypes.
abc ^^<http://example.org/myDatatype>
abbreviated with an XML QName style as:
10 ^^xsd:integer
Short forms for several common datatypes:
-10 -10 ^^xsd:integer
1.2345 1.2345 ^^xsd:decimal
true true ^^xsd:boolean
Blank Node: A node in a graph with a local name. The scope of the name is the RDF graph.
_:node
2. Common RDF Namespaces and Prefixes
Namespace Common Prefix Namespace URI
RDF rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
Dublin Core dc: http://purl.org/dc/elements/1.1/
FOAF foaf: http://xmlns.com/foaf/0.1/
XML Schema Datatypes xsd: http://www.w3.org/2001/XMLSchema#
RDFS rdfs: http://www.w3.org/2000/01/rdf-schema#
OWL owl: http://www.w3.org/2002/07/owl#
3. SPARQL Query Language Reference
Based on SPARQL Query 23 Nov 2005 <http://www.w3.org/TR/2005/WD-rdf-sparql-query-20051123/>.
RDFTerm: A part of an RDF Triple. An IRI, Blank Node or a Literal.
<uri> _:b1 Literal @en abc123 ^^my:datatype
Query Variable: Identifiers for binding to RDF Terms in matches.
?a / $b or in lists: $name $title $place
Anonymous
Query Variable:
Blank Nodes in a graph pattern act as variables that cannot be SELECTed
_:abc
Triple Pattern: An RDF Triple with Query Variables or blank nodes allowed in each term:
<http://example.org/abc> ?x Hello
?subject ?predicate ?object
Turtle abbreviations can be used for Triple Patterns, see Section 4.
Graph Pattern: A block that matches part of the queried RDF graph.
Basic
Graph Pattern:
A set of Triple Patterns binding RDF Terms in the graph to variables.
Written as a {..} block with '.' separating the triple patterns:
{ <http://example.org/abc> ?y Hello .
?subject $predicate Literal }
Group
Graph Pattern:
A graph pattern containing multiple graph patterns which must all match
{ { ?person rdf:type foaf:Person }
{ ?person foaf:name Dave } }
Optional
Graph Pattern:
A graph pattern which may fail to match and provide bindings but not
cause the entire query to fail. Written with OPTIONAL before a graph
pattern.
OPTIONAL { ?person foaf:nick ?nick }
Union
Graph Pattern:
A pair of graph patterns any of which may match and bind the same
variables. Written with the UNION keyword between two graph patterns.
{ ?node ex:name ?name } UNION
{ ?node vcard:FN ?name }
Graph
Graph Pattern:
A keyword for specifying a graph name to use or to return a graph name as a
binding. Written with the GRAPH keyword before a graph pattern.
GRAPH <http://example.org/myfoaf>
{ ?person foaf:name ?name }
GRAPH ?graph { ?person foaf:name ?name }
Value Constraints: A boolean expression in a graph pattern over query variables that constrains
matched graph patterns.
{ ?item ex:size $size . FILTER ($size < 10 ) }
4. SPARQL Query Language Structure
Prologue (optional) BASE <iri>
PREFIX prefix: <iri> (repeatable)
Query Result forms (required, pick 1) SELECT (DISTINCT)sequence of ?variable
SELECT (DISTINCT)*
DESCRIBE sequence of ?variable or <iri>
DESCRIBE *
CONSTRUCT { graph pattern }
ASK
Query Dataset Sources (optional) Add triples to the background graph (repeatable):
FROM <iri>
Add a named graph (repeatable):
FROM NAMED <iri>
Graph Pattern (optional, required for ASK) WHERE { graph pattern [ FILTER expression ]}
Query Results Ordering (optional) ORDER BY ...
Query Results Selection (optional) LIMIT n, OFFSET m
Sign up today - FREE
Mendeley saves you time finding and organizing research. Learn more
- All your research in one place
- Add and import papers easily
- Access it anywhere, anytime
Start using Mendeley in seconds!
Readership Statistics
14 Readers on Mendeley
by Discipline
by Academic Status
36% Student (Master)
14% Ph.D. Student
14% Post Doc
by Country
29% United States
21% Germany
14% Switzerland


