Formal Definitions from SPARQL Query Language for RDF

in section Abstract

in section Status of This document

in section Table of Contents

in section Appendices

in section Introduction

in section Document Conventions

in section Making Simple Queries

in section Writing a Simple Query

in section Syntax of IRI Terms

in section Syntax of Literal Terms

in section Syntax of Variables

in section Syntax of Triple Patterns

in section Examples of Query Syntax

in section Data descriptions used in this document

in section Result Descriptions used in this document

in section Initial Definitions

Definition: RDF Term

let 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 union RDF-L union RDF-B.

Definition: Query Variable

A query variable is a member of the set V where V is infinite and disjoint from RDF-T.

Definition: Graph Pattern

A Graph Pattern is one of:

Definition: SPARQL Query

A SPARQL query is a tuple (GP, DS, SM, R) where:

The graph pattern of a query is called the query pattern.

Definition: Triple Pattern

A triple pattern is member of the set:
    (RDF-T union V) x (I union V) x (RDF-T union V)

in section Pattern Solutions

Definition: Pattern Solution

Let W = V union RDF-B, the set of all variables and blank nodes.

A pattern solution is a substitution function from a subset of W to the set of RDF terms, RDF-T.

The result of replacing every member v of W in a graph pattern P by S(v) is written S(P).

If v is not in the domain of S then S(v) is defined to be v.

Definition: Query Solution

Given query Q = (GP, DS, SM, R) then S is a query solution of Q if S is a pattern solution for GP matching dataset DS.

in section Basic Graph Patterns

Definition: Basic Graph Pattern

A Basic Graph Pattern is a set of Triple Patterns.

A basic graph pattern matches on graph G with solution S if S(GP) is an RDF graph and is subgraph of G.

in section Multiple Matches

in section Blank Nodes

in section Blank Nodes and Queries

in section Blank Nodes and Query Results

in section Other Syntactic Forms

in section Predicate-Object Lists

in section Object Lists

in section Blank Nodes

in section RDF Collections

in section Other

in section Querying Reification Vocabulary

in section Working with RDF Literals

in section Matching RDF Literals

in section Matching Integers

in section Matching Arbitrary Datatypes

in section Matching Language Tags

in section Matching with RDF D-Entailment

in section Value Constraints

in section Value Constraints – Definition

Definition: Value Constraint

A value constraint is a boolean-valued expression of variables and RDF Terms.

For value constraint C, a solution S matches C if S(C) is true, where S(C) is the boolean-valued expression obtained by substitution of the variables mentioned in C.

in section Matching Values and RDF D-entailment

in section Graph Patterns

in section Group Graph Patterns

Definition: Group Graph Pattern

A group graph pattern GP is a set of graph patterns, GPi.

A solution of Group Graph Pattern GP on graph G is any solution S such that, for every element GPi of GP, S is a solution of GPi.

in section Unbound variables

in section Including Optional Values

in section Optional Pattern Matching

in section Constraints in Optional Pattern Matching

in section Multiple Optional Graph Patterns

in section Optional Matching – Formal Definition

Definition: Optional Graph Pattern

An optional graph pattern is a combination of a pair of graph patterns. The second pattern modifies pattern solutions of the first pattern but does not fail matching of the overall optional graph pattern.

If Opt(A, B) is an optional graph pattern, where A and B are graph patterns, then S is a solution of optional graph pattern if S is a pattern solution of A and of B otherwise if S is a solution to A, but not to A and B.

in section Nested Optional Graph Patterns

in section Matching Alternatives

in section Joining Patterns with UNION

in section Union Matching – Formal Definition

Definition: Union Graph Pattern

A union graph pattern is a set of graph patterns GPi.

A union graph pattern matches a graph G with solution S if there is some GPi such that GPi matches G with solution S.

in section RDF Dataset

Definition: RDF Dataset

An 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.

There may be no named graphs.

A graph pattern P, where P is not an RDF Dataset Graph Pattern, matches an RDF dataset DS with solution S if P matches G (the default graph of DS) with solution S.

Definition: RDF Dataset Graph Pattern

If D is a dataset {G, (<u1>, G1), ...}, and P is a graph pattern then S is a pattern solution of RDF Dataset Graph Pattern GRAPH(g, P) if either of:

  1. g is an IRI where g = <ui> for some i, and S is pattern solution of P on dataset {Gi, (<u1>, G1), ...}
  2. g is a variable, S maps the variable g to <ui> and S is a pattern solution of P on {Gi, (<u1>, G1), ...}

in section Examples of RDF Datasets

in section Querying the Dataset

in section Accessing Graph Names

in section Restricting by Graph IRI

in section Restricting by Bound Variables

in section Named and Default Graphs

in section Specifying RDF Datasets

in section Specifying the Default Graph

in section Specifying Named Graphs

in section Combining FROM and FROM NAMED

in section Query Result Forms

in section Solution Sequences and Result Forms

Definition: Solution Sequence

A solution sequence S is a list of solutions.

    S = ( S1, S2, . . . , Sn)

The solution sequence from matching the query pattern is an unordered collection formed from the solutions of the query pattern.

Definition: Solution Sequence Modifier

A solution sequence modifier is one of:

If SM is set of modifiers, and QS is the collection of solutions of a query, we write SM(QS) for the sequence formed by applying SM to the solution sequence formed from QS.

Definition: Result Forms

The result form of a query is one of

in section Projection

Definition: Projection

The projection of solution QS over a set of variables VS is the solution
      project(QS, VS) = { (v, QS(v)) | v in VS }

For a solution sequence S = ( S1, S2, . . . , Sn) and a finite set of variables VS,
    project(S, VS) = { (project(Si, VS) | i = 1,2, . . . n }

in section DISTINCT

Definition: Distinct Solution Sequence

A Distinct Solution Sequence has no two solutions the same.

For a solution sequence S = ( S1, S2, . . . , Sn), then write set(S) for the set of solution sequences in S.

    distinct(S) = (Si | Si != Sj for all i != j) and set(distinct(S)) = set(S)

in section ORDER BY

Definition: Ordered Solution Sequence

A ordered solution sequence is a solution sequence where the sequence is partially ordered with respect to some ordering condition.

A solution sequence S = ( S1, S2, . . . , Sn) is ordered with respect to an ordering condition C if, for Si, SJ, then i < j if C orders Si before Sj.

in section LIMIT

Definition: Limited Solution Sequence

A Limited Solution Sequence has at most a given, fixed number of members.

The limit of solution sequence S = (S1, S2, . . . , Sn) is

limit(S,m) =
        (S1, S2, . . . , Sm) if n > m
        (S1, S2, . . . , Sn) if n <= m

in section OFFSET

Definition: Offset Solution Sequence

An Offset Solution Sequence with respect to another solution sequence S, is one which starts at a given index of S.

For solution sequence S = (S1, S2, . . . , Sn), the offset solution sequence
offset(S, k), k >= 0  is
     (Sk, Sk+1, . . ., Sn) if n >= k
     (), the empty sequence, if k > n

in section Selecting Variables

Definition: SELECT

Given Q = (GP, DS, SM, SELECT VS) where

then, if QS is the set of solutions formed by matching dataset DS with graph pattern GP, the SELECT result is project(SM(QS), VS)

in section Constructing an Output Graph

in section Templates with Blank Nodes

in section Accessing Graphs in the RDF Dataset

Definition: Graph Template

A graph template is a set of triple patterns.

If T = { tj | j = 1,2 ... m } is a graph template and S is a solution then S(tj) is an RDF triple if all variables in tj are in the domain of S. S(tj) is empty otherwise.

Write S(T) for the union of S(tj).

Definition: CONSTRUCT

Let Q = (GP, DS, SM, CONSTRUCT T) where

then, if QS is the set of solutions formed by matching dataset DS with graph pattern GP, then write SM(QS) = { Si | i = 1,2 ... n }.

The CONSTRUCT result is the RDF graph formed by the RDF merge of each Si(T).

in section Solution Modifiers and CONSTRUCT

in section Descriptions of Resources

in section Explicit IRIs

in section Identifying Resources

in section Descriptions of Resources

Definition: DESCRIBE

Let Q = (GP, DS, SM, DESCRIBE V) where

then, if QS is the set of solutions formed by matching dataset DS with graph pattern GP, the DESCRIBE result is an RDF graph formed by information relating elements of
U union project(SM(QS), VS).

This definition intentionally does not proscribe the nature of the relevant information.

in section Asking "yes or no" questions

Definition: ASK

Let Q = (GP, DS, SM, ASK) where

and QS is the set of solutions formed by matching dataset DS with graph pattern GP then the ASK result is true if SM(QS) is not empty, otherwise it is false.

in section Testing Values

in section Operand Data Types

in section Type Promotion

in section SPARQL Functions and Operators

in section Invocation

in section Effective Boolean Value

in section Operator Mapping

in section Operators introduced in SPARQL

in section SPARQL Constructor Functions

in section Extensible Value Testing

in section A. SPARQL Grammar

in section IRI References

in section White Space

in section Keywords

in section Comments

in section Escape sequences in strings

in section Escape sequences in IRI references, prefixed names and variable names

in section B Conformance (DanC)

in section C. Security Considerations

in section E. Internet Media Type, File Extension and Macintosh File Type (Normative)

in section F. References

in section G. Acknowledgements

in section H. Change Log

$Revision: 1.4 $ of $Date: 2005/11/23 22:48:50 $
generated from $Id: Overview.html,v 1.564 2005/11/22 23:43:12 eric Exp $
via defns.xsl$Id: defns.xsl,v 1.13 2005/07/21 17:41:27 connolly Exp $

See also the editor's draft and the live transformation.