diff --git a/spec/index.html b/spec/index.html index 22b25e9..780eea1 100644 --- a/spec/index.html +++ b/spec/index.html @@ -1369,6 +1369,267 @@

rdf:type

+
+

Triple Terms

+

Within the object position of a triple pattern, + we can use a triple term + or another triple pattern. +

+

Such a triple pattern or nested triple pattern + is represented as a TripleTerm with + TripleTermSubject, + Verb, and + TripleTermObject, all + preceded by <<(, and + followed by )>>. + Note that triple terms and triple patterns + can be nested. +

+

The example below shows how a triple pattern + can be used in the object position of another triple pattern.

+
+              VERSION "1.2"
+              PREFIX : <http://example/>
+              PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+
+              SELECT ?person ?authority {
+                  ?person :familyName "Smith" .
+                  _:anno rdf:reifies <<( ?person :jobTitle "Designer" )>> .
+                  _:anno :accordingTo ?authority .
+              }
+        
+
+
+

Reifying Triples

+

Triple terms are mostly used + as the object of a triple + with a predicate of `rdf:reifies`. + Such a triple is called a reifying triple. + SPARQL also provides a shorthand notation for writing reifying triples + using the ReifiedTriple grammar production.

+

+

A ReifiedTriple + provides syntactic sugar to represent a reifying triple, + which defines a specific relationship between an + identifier (reifier) + and a triple term. + The identifier becomes a way to indirectly refer + to the triple term, which + may or may not be asserted within the query. +

+

Reification using triple terms is a concept distinct from the + Reification vocabulary originally + defined in RDF Semantics. + While both terms describe a representation of an RDF triple using components, + RDF 1.2 and SPARQL 1.2 uses the term to identify a triple term + using the `rdf:reifies` predicate. +

+

A reifying triple is represented using the + ReifiedTriple production + starting with <<, + followed by a ReifiedTripleSubject, + a Verb, and + a ReifiedTripleObject, + followed by an optional Reifier, + and ending with >>. + This Reifier is composed of a ~ + followed by an optional rVarOrReifierId production. + This rVarOrReifierId is composed of + a variable, an IRI, or a blank node; + for example, `<< :subject :predicate :object ~ :IRIREF >>`. + If no reifier is present, + or the ~ + is not immediately followed by variable, + an IRI, or a blank node — + as in `<< :subject :predicate :object >>`, + or `<< :subject :predicate :object ~ >>` — + a fresh RDF blank node is allocated. +

+

ReifiedTriple's may be nested, + like +
`<< ?subject1 :predicate1 << :subject2 :predicate2 :object2 >> ~ :IRIREF1 >>` + or
`<< :subject4 :predicate4 << :subject3 :predicate3 ?object3 ~ :IRIREF3 >> >>`. +

+

The example below shows a reifying triple with an implicit reifier.

+
+              VERSION "1.2"
+              PREFIX : <http://example/>
+              PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+
+              SELECT ?person ?authority {
+                  ?person :familyName "Smith" .
+                  << ?person :jobTitle "Designer" >> :accordingTo ?authority .
+              }
+        
+

The example below shows a reifying triple with an explicit reifier.

+
+              VERSION "1.2"
+              PREFIX : <http://example/>
+              PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+
+              SELECT ?person ?authority ?id {
+                  ?person :familyName "Smith" .
+                  << ?person :jobTitle "Designer" ~ ?id >> :accordingTo ?authority .
+              }
+        
+

The syntactic sugar of the example above expands to the following query:

+
+              VERSION "1.2"
+              PREFIX : <http://example/>
+              PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+
+              SELECT ?person ?authority ?id {
+                  ?person :familyName "Smith" .
+                  ?id rdf:reifies <<( ?person :jobTitle "Designer" )>> .
+                  ?id :accordingTo ?authority .
+              }
+        
+

Note the subtle difference in syntax between the syntactic sugar of + the ReifiedTriple (i.e., `<< ... >>`) + and the regular TripleTerm (i.e., `<<( ... )>>`).

+ +
+

Annotation Syntax

+

SPARQL also defines an annotation syntax + that both reifies and asserts a triple pattern, + which provides a convenient shortcut. + An annotation can be used to simultaneously assert a triple pattern, + via an explicit or implicit identifier, + and have that triple pattern be the + subject or + object of further triple patterns. + If explicitly identified, the same reifier can then be used as the + subject or + object of additional + triple patterns and/or triple terms. +

+

Like a ReifiedTriple, + the annotation syntax uses a reifier — written as either a + variable, an IRI, or a blank node, + preceded by a tilde (~) — + to identify the + triple term being reified. + However, while the + ReifiedTriple syntax + may contain at most one reifier, the annotation syntax may contain + any number of reifiers. Each reifier causes a corresponding + reifying triple to be produced. +

+

A reifier can be followed by an annotation block. + If a reifier is not followed by an annotation block, it is treated + analogously to a + ReifiedTriple + without additional annotations. + If an annotation block is not immediately preceded by a reifier, + a fresh RDF blank node is allocated to serve as the reifier of the + triple term. +

+

The annotation syntax is a syntactic shortcut in SPARQL. + The RDF Abstract Syntax [[RDF11-CONCEPTS]] does not + distinguish how the triples were written.

+

The example below shows an annotated triple pattern with an explicit reifier.

+
+                VERSION "1.2"
+                PREFIX : <http://example/>
+                PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+          
+                SELECT ?person ?authority {
+                    ?person :name "Alice" ~ :t {| :statedBy ?authority ; :recorded "2021-07-07"^^xsd:date |} .
+                }
+          
+

The syntactic sugar of the annotation syntax in the example above expands to the following query:

+
+                VERSION "1.2"
+                PREFIX : <http://example/>
+                PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+          
+                SELECT ?person ?authority {
+                    ?person :name "Alice" .
+                    << ?person :name "Alice" ~ :t >> :statedBy ?authority ;
+                                                    :recorded "2021-07-07"^^xsd:date .
+                }
+          
+

If we fully expand this query to use TripleTerm's instead of reifiers, + the query is expanded to the following:

+
+                VERSION "1.2"
+                PREFIX : <http://example/>
+                PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+          
+                SELECT ?person ?authority {
+                    ?person :name "Alice" .
+                    :t rdf:reifies <<( ?person :name "Alice" )>> .
+                    :t :statedBy ?authority .
+                    :t :recorded "2021-07-07"^^xsd:date .
+                }
+          
+

The example below shows an annotated triple pattern with an implicit reifier, for which a fresh blank node is allocated.

+
+                VERSION "1.2"
+                PREFIX : <http://example/>
+                PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+          
+                SELECT ?person ?authority {
+                    ?person :name "Alice" ~ :t {| :statedBy ?authority ; :recorded "2021-07-07"^^xsd:date |} .
+                }
+          
+

An Annotation + may include any number of annotation blocks. If such blocks are not + immediately preceded by explicit reifiers, each block is associated + with a fresh blank node allocated as its reifier, as seen in the example below.

+
+                VERSION "1.2"
+                PREFIX : <http://example/>
+                PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+          
+                SELECT ?person ?authority1 ?authority2 {
+                    ?person :name "Alice" 
+                      {| :statedBy ?authority1 ; :recorded "2021-02-01"^^xsd:date |}
+                      {| :statedBy ?authority2 ; :recorded "2021-07-07"^^xsd:date |} .
+                }
+          
+

The query above will be fully expanded to the query below, where _:b0 and _:b1 stand for fresh RDF blank nodes.

+
+                VERSION "1.2"
+                PREFIX : <http://example/>
+                PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+          
+                SELECT ?person ?authority1 ?authority2 {
+                    ?person :name "Alice" .
+                    _:b0 rdf:reifies <<( ?person :name "Alice" )>> .
+                    _:b0 :statedBy ?authority1 .
+                    _:b0 :recorded "2021-02-01"^^xsd:date .
+                    _:b1 rdf:reifies <<( ?person :name "Alice" )>> .
+                    _:b1 :statedBy ?authority2 .
+                    _:b1 :recorded "2021-07-07"^^xsd:date .
+                }
+          
+

The annotation syntax may also contain multiple explicit + reifiers without annotation blocks, as shown in the example below. Each such reifier + causes a corresponding reifying triple to be produced.

+
+                VERSION "1.2"
+                PREFIX : <http://example/>
+                PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+          
+                SELECT ?person {
+                    ?person :name "Alice" ~ :stmt1 ~ stmt2 .
+                }
+          
+

The query above will be fully expanded to the query below.

+
+                VERSION "1.2"
+                PREFIX : <http://example/>
+                PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+          
+                SELECT ?person {
+                    ?person :name "Alice" .
+                    :stmt1 rdf:reifies <<( ?person :name "Alice" )>> .
+                    :stmt2 rdf:reifies <<( ?person :name "Alice" )>> .
+                }
+          
+
+

Version Announcement

To cope with the language evolution of SPARQL, @@ -13034,7 +13295,9 @@

Changes between SPARQL 1.1 Query Language and SPARQL 1.2 Query Language

Normative changes: