Initial Definitions

RDF Terms

SPARQL is defined in terms of IRIs [Internationalized Resource Identifiers (IRIs)]. IRIs are a subset of RDF URI References that omits the use of spaces.

Definition: RDF TermLet I be the set of all IRIs.
Let RDF-L be the set of all RDF Literals
Let RDF-B be the set of all blank nodes in RDF graphs

The set of RDF Terms , RDF-T, is I ∪ RDF-L ∪ RDF-B.

This definition of RDF Term collects together several basic notions from the RDF data model, but updated to refer to IRIs rather than RDF URI references.

Simple Literal

Definition: Simple Literal

The set of Simple Literals is the set of all RDF Literals with no language tag or datatype IRI.

RDF Dataset

Definition: RDF DatasetAn RDF dataset is a set:
{ G, (<u1>, G1), (<u2>, G2), . . . (<un>, Gn) }
where G and each Gi are graphs, and each <ui> is an IRI. Each <ui> is distinct.

G is called the default graph. (<ui>, Gi) are called named graphs.

Definition: Active GraphThe active graph is the graph from the dataset used for basic graph pattern matching.

Definition: RDF Dataset Merge

Let DS1 = { G1, (<u11>, G11), (<u12>, G12), . . . (<u1n>, G1n) },
and DS2 = { G2, (<u21>, G21), (<u22>, G22), . . . (<u2m>, G2m) }

then we define the RDF Dataset Merge of DS1 and DS2 to be:
DS={ G, (<u1>, G1), (<u2>, G2), . . . (<uk>, Gk) }
where:

Write N1 for { <u1j> j = 1 to n }
Write N2 for { <u2j> j = 1 to m }

  • G is the merge of G1 and G2
  • (<ui>, Gi) where <ui> is in N1 but not in N2
  • (<ui>, Gi) where <ui> is in N2 but not in N1
  • (<ui>, Gi) where <ui> is equal to <uj> in N1 and equal to <uk> in N2 and Gi is the merge of G1j and G2k

Query Variables

Definition: Query VariableA query variable is a member of the set V where V is infinite and disjoint from RDF-T.

Triple Patterns

Definition: Triple PatternA triple pattern is member of the set:
(RDF-T ∪ V) x (I ∪ V) x (RDF-T ∪ V)

This definition of Triple Pattern includes literal subjects. This has been noted by RDF-core.

"[The RDF core Working Group] noted that it is aware of no reason why literals should
not be subjects and a future WG with a less restrictive charter may
extend the syntaxes to allow literals as the subjects of statements."

Because RDF graphs may not contain literal subjects, any SPARQL triple pattern with a literal as subject will fail to match on any RDF graph.

Basic Graph Patterns

Definition: Basic Graph PatternA Basic Graph Pattern is a set of Triple Patterns.

The empty graph pattern is a basic graph pattern which is the empty set.

Property Path Patterns

Definition: Property PathA Property Path is a sequence of triples, ti in sequence ST, with n = length(ST)-1, such that, for i=0 to n, the object of ti is the same term as the subject of ti+1.

We call the subject of t0 the start of the path.

We call the object of tn the end of the path.

A Property Path is a path in graph G if each ti is a triple of G.

A property path does not span multiple graphs in a dataset.

Definition: Property Path ExpressionA property path expression is an expression using the property path forms described above .

Definition: Property Path PatternLet PP be the set of all property path expressions. A property path pattern is a member of the set:
(RDF-T ∪ V) x PP x (RDF-T ∪ V)

A Property Path Pattern is a generalization of a Triple Pattern to include a property path expression in the property position.

Solution Mapping

A solution mapping is a mapping from a set of variables to a set of RDF terms. We use the term 'solution' where it is clear.

Definition: Solution MappingA solution mapping, μ, is a partial function μ : V -> RDF-T.

The domain of μ, dom(μ), is the subset of V where μ is defined.

Definition: Solution SequenceA solution sequence is a list of solutions, possibly unordered.

Write expr(μ) for the value of the expression expr, using the terms for variables given by μ. Evaluation may result in an error.

Solution Sequence Modifiers

Definition: Solution Sequence ModifierA solution sequence modifier is one of:

  • Order By modifier: put the solutions in order
  • Projection modifier: choose certain variables
  • Distinct modifier: ensure solutions in the sequence are unique
  • Reduced modifier: permit any non-distinct solutions to be eliminated
  • Offset modifier: control where the solutions start from in the overall sequence of solutions
  • Limit modifier: restrict the number of solutions

18.1.10 SPARQL Query

Definition: SPARQL QueryA SPARQL Abstract Query is a tuple (E, DS, QF) where:

Definition: Query LevelA query level is a graph pattern, a set of group and aggregation, and a set of solution modifiers.

A query is a tree of "query levels", where each subquery forms one query level in the tree.