Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
274 changes: 273 additions & 1 deletion spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,276 @@ <h4>rdf:type</h4>
</pre>
</section>
</section>
<section id="syntaxNestedTriplePatterns">
<h3>Nested Triple Patterns</h3>
<p> <a href="#defn_TriplePattern">Triple patterns</a> can be nested; that is, their subject or object can be
another <a href="#defn_TriplePattern">triple pattern</a>.
Such nested triple patterns are meant to match triples that contain <a data-cite="RDF12-CONCEPTS#dfn-triple-term">triple terms</a>.
</p>
<p>To write a nested <a href="#defn_TriplePattern">triple pattern</a>
the triple pattern that it contains must be
preceded by <code>&lt;&lt;(</code>, and
followed by <code>)&gt;&gt;</code>.
</p>
<p>The example below illustrates how a <a href="#defn_TriplePattern">triple pattern</a>
can be used in the object position of another <a href="#defn_TriplePattern">triple pattern</a>.</p>
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;

SELECT ?person ?authority {
?person :familyName "Smith" .
_:anno rdf:reifies &lt;&lt;( ?person :jobTitle "Designer" )&gt;&gt; .
_:anno :accordingTo ?authority .
}
</pre>
<section id="syntaxReifyingTriples">
<h3>Shorthand to Match Reifying Triples</h3>
<p><a data-cite="RDF12-CONCEPTS#dfn-triple-term">Triple terms</a> are used
as the <a data-cite="RDF12-CONCEPTS#dfn-object">object</a> of a <a data-cite="RDF12-CONCEPTS#dfn-rdf-triple">triple</a>
with a <a data-cite="RDF12-CONCEPTS#dfn-predicate">predicate</a> of `rdf:reifies`.
Such a triple is called a <a data-cite="RDF12-CONCEPTS#dfn-reifying-triple">reifying triple</a>.
SPARQL provides a shorthand notation for writing triple patterns that are meant to match such <a data-cite="RDF12-CONCEPTS#dfn-reifying-triple">reifying triples</a>.</p>
</p>
<p class="note">Reification using triple terms is a concept distinct from the
<a data-cite="RDF12-SEMANTICS#Reif">Reification vocabulary</a> originally
defined in <a data-cite="RDF-MT#Reif">RDF Semantics</a>.
While both concepts describe a representation of an RDF triple using components,
RDF 1.2 and SPARQL 1.2 have a dedicated <a data-cite="RDF12-CONCEPTS#dfn-triple-term">triple term</a>,
which can be used with the `rdf:reifies` predicate.
</p>
<p>The example below matches reifying triples.</p>
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;

SELECT ?person ?authority {
?person :familyName "Smith" .
&lt;&lt; ?person :jobTitle "Designer" &gt;&gt; :accordingTo ?authority .
}
</pre>
<p>The syntactic sugar of the example above expands to the following query:</p>
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;

SELECT ?person ?authority ?id {
?person :familyName "Smith" .
_:id rdf:reifies &lt;&lt;( ?person :jobTitle "Designer" )&gt;&gt; .
_:id :accordingTo ?authority .
}
</pre>
<p>This shorthand notation for matching reifying triples
also allows the <a data-cite="RDF12-CONCEPTS#dfn-reifier">reifier</a>
of these reifying triples to be matched. This is done by placing
a variable, IRI, or blank node after a tilde (<code title="tilde">~</code>).
As shown in the example above; if no reifier is explicitly mentioned,
then a new blank node is minted for as reifier within the scope of this query.
</p>
<p class="note"><a href="#rReifiedTriple"><code>ReifiedTriple</code>'s</a> may be nested,
like
<br/>`&lt;&lt; ?subject1 :predicate1 &lt;&lt; :subject2 :predicate2 :object2 &gt;&gt; ~ :IRIREF1 &gt;&gt;`<br/>
or <br/>`&lt;&lt; :subject4 :predicate4 &lt;&lt; :subject3 :predicate3 ?object3 ~ :IRIREF3 &gt;&gt; &gt;&gt;`.
</p>
<p>The example below matches reifying triples with a variable to match the reifier.</p>
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;

SELECT ?person ?authority ?id {
?person :familyName "Smith" .
&lt;&lt; ?person :jobTitle "Designer" ~ ?id &gt;&gt; :accordingTo ?authority .
}
</pre>
<p>The syntactic sugar of the example above expands to the following query:</p>
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;

SELECT ?person ?authority ?id {
?person :familyName "Smith" .
?id rdf:reifies &lt;&lt;( ?person :jobTitle "Designer" )&gt;&gt; .
?id :accordingTo ?authority .
}
</pre>
<p class="note">Note the subtle difference in syntax between the syntactic sugar of
the <a href="#rReifiedTriple"><code>ReifiedTriple</code></a> (i.e., `&lt;&lt; ... >>`)
and the regular <a href="#rTripleTerm"><code>TripleTerm</code></a> (i.e., `&lt;&lt;( ... )>>`).</p>
</section>
<section id="syntaxAnnotation">
<h3>Annotation Syntax</h3>
<p>SPARQL also defines <dfn data-lt="annotation-syntax">annotation syntax</dfn>
as a shortcut form for matching both reified and asserted triples with a
<a href="#defn_TriplePattern">triple pattern</a>.
An annotation can be used to simultaneously match an asserted triple,
via an explicit or implicit identifier,
and have that triple pattern be the
<a data-cite="RDF12-CONCEPTS#dfn-subject">subject</a> or
<a data-cite="RDF12-CONCEPTS#dfn-object">object</a> of further triple patterns.
If explicitly identified, the same <a data-cite="RDF12-CONCEPTS#dfn-reifier">reifier</a> can then be used as the
<a data-cite="RDF12-CONCEPTS#dfn-subject">subject</a> or
<a data-cite="RDF12-CONCEPTS#dfn-object">object</a> of additional
triple patterns and/or <a data-cite="RDF12-CONCEPTS#dfn-triple-term">triple terms</a>.
</p>
<p>Like a <a href="#rReifiedTriple"><code>ReifiedTriple</code></a>,
the annotation syntax uses a <a data-cite="RDF12-CONCEPTS#dfn-reifier">reifier</a> — written as either a
<a href="#rVar">variable</a>, an <a href="#riri">IRI</a>, or a <a href="#rBlankNode">blank node</a>,
preceded by a tilde (<code title="tilde">~</code>) —
to identify the
<a data-cite="RDF12-CONCEPTS#dfn-triple-term">triple term</a> being reified.
However, while the
<a href="#rReifiedTriple"><code>ReifiedTriple</code></a> syntax
may contain at most one <a data-cite="RDF12-CONCEPTS#dfn-reifier">reifier</a>, the annotation syntax may contain
any number of <a data-cite="RDF12-CONCEPTS#dfn-reifier">reifiers</a>. Each <a data-cite="RDF12-CONCEPTS#dfn-reifier">reifier</a> causes a corresponding
reifying triple to be produced.
</p>
<p>A <a data-cite="RDF12-CONCEPTS#dfn-reifier">reifier</a> can be followed by an annotation block.
If a <a data-cite="RDF12-CONCEPTS#dfn-reifier">reifier</a> is not followed by an annotation block, it is treated
analogously to a
<a href="#rReifiedTriple"><code>ReifiedTriple</code></a>
without additional annotations.
If an annotation block is not immediately preceded by a <a data-cite="RDF12-CONCEPTS#dfn-reifier">reifier</a>,
a fresh RDF blank node is allocated to serve as the <a data-cite="RDF12-CONCEPTS#dfn-reifier">reifier</a> of the
<a data-cite="RDF12-CONCEPTS#dfn-triple-term">triple term</a>.
</p>
<p class="note">The annotation syntax is a syntactic shortcut in SPARQL.
The RDF Abstract Syntax [[RDF11-CONCEPTS]] does not
distinguish how the triples were written.</p>
<p>The example below shows an annotated triple pattern with an explicit reifier.</p>
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;

SELECT ?person ?authority {
?person :name "Alice" ~ :t {| :statedBy ?authority ; :recorded "2021-07-07"^^xsd:date |} .
}
</pre>
<p>The syntactic sugar of the annotation syntax in the example above expands to the following query:</p>
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;

SELECT ?person ?authority {
?person :name "Alice" .
&lt;&lt; ?person :name "Alice" ~ :t &gt;&gt; :statedBy ?authority ;
:recorded "2021-07-07"^^xsd:date .
}
</pre>
<p>If we fully expand this query to use <a href="#rTripleTerm"><code>TripleTerm</code>'s</a> instead of reifiers,
the query is expanded to the following:</p>
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;

SELECT ?person ?authority {
?person :name "Alice" .
:t rdf:reifies &lt;&lt;( ?person :name "Alice" )&gt;&gt; .
:t :statedBy ?authority .
:t :recorded "2021-07-07"^^xsd:date .
}
</pre>
<p>The example below shows an annotated triple pattern with an implicit reifier, for which a fresh blank node is allocated.</p>
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;

SELECT ?person ?authority {
?person :name "Alice" {| :statedBy ?authority ; :recorded "2021-07-07"^^xsd:date |} .
}
Comment thread
rubensworks marked this conversation as resolved.
</pre>
<p>An <a href="#rAnnotation"><code>Annotation</code></a>
may include any number of annotation blocks. If such blocks are not
immediately preceded by explicit <a data-cite="RDF12-CONCEPTS#dfn-reifier">reifiers</a>, each block is associated
with a fresh blank node allocated as its <a data-cite="RDF12-CONCEPTS#dfn-reifier">reifier</a>, as seen in the example below.</p>
Comment thread
rubensworks marked this conversation as resolved.
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;

SELECT ?person ?authority1 ?authority2 {
?person :name "Alice"
{| :statedBy ?authority1 ; :recorded "2021-02-01"^^xsd:date |}
{| :statedBy ?authority2 ; :recorded "2021-07-07"^^xsd:date |} .
}
</pre>
<p>The query above will be fully expanded to the query below, where <code>_:b0</code> and <code>_:b1</code> stand for fresh RDF blank nodes.</p>
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;

SELECT ?person ?authority1 ?authority2 {
?person :name "Alice" .
_:b0 rdf:reifies &lt;&lt;( ?person :name "Alice" )&gt;&gt; .
_:b0 :statedBy ?authority1 .
_:b0 :recorded "2021-02-01"^^xsd:date .
_:b1 rdf:reifies &lt;&lt;( ?person :name "Alice" )&gt;&gt; .
_:b1 :statedBy ?authority2 .
_:b1 :recorded "2021-07-07"^^xsd:date .
}
</pre>
<p>The annotation syntax may also contain multiple explicit
<a data-cite="RDF12-CONCEPTS#dfn-reifier">reifiers</a> without annotation blocks, as shown in the example below. Each such <a data-cite="RDF12-CONCEPTS#dfn-reifier">reifier</a>
causes a corresponding reifying triple to be produced.</p>
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;

SELECT ?person {
?person :name "Alice" ~ :stmt1 ~ :stmt2 .
}
</pre>
<p>The query above will be fully expanded to the query below.</p>
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;

SELECT ?person {
?person :name "Alice" .
:stmt1 rdf:reifies &lt;&lt;( ?person :name "Alice" )&gt;&gt; .
:stmt2 rdf:reifies &lt;&lt;( ?person :name "Alice" )&gt;&gt; .
}
</pre>
<p>The annotation syntax could also contain multiple explicit
<a data-cite="RDF12-CONCEPTS#dfn-reifier">reifiers</a> with annotation blocks, as shown in the example below.</p>
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;

SELECT ?person {
?person :name "Alice"
~ :stmt1 {| :statedBy ?authority1 |}
~ :stmt2 {| :statedBy ?authority2 |} .
}
</pre>
<p>The query above will be fully expanded to the query below.</p>
<pre class="query nohighlight">
VERSION "1.2"
PREFIX : &lt;http://example/&gt;
PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;

SELECT ?person {
?person :name "Alice" .
:stmt1 rdf:reifies &lt;&lt;( ?person :name "Alice" )&gt;&gt; .
:stmt1 :statedBy ?authority1 .
:stmt2 rdf:reifies &lt;&lt;( ?person :name "Alice" )&gt;&gt; .
:stmt2 :statedBy ?authority2 .
}
</pre>
</section>
</section>
<section id="syntaxVersionAnnouncement">
<h3>Version Announcement</h3>
<p>To cope with the language evolution of SPARQL,
Expand Down Expand Up @@ -13034,7 +13304,9 @@ <h2>Changes between SPARQL 1.1 Query Language and SPARQL 1.2 Query Language</h2>
Normative changes:
<ul>
<li>Update grammar for triple terms, reifiers, reified triples, annotation syntax, and triple term functions
in <a href="#sparqlGrammar" class="sectionRef"></a></li>
in <a href="#sparqlGrammar" class="sectionRef"></a> and explain them
in <a href="#syntaxNestedTriplePatterns" class="sectionRef"></a>
and <a href="#syntaxReifyingTriples" class="sectionRef"></a></li>
<li>Add functions related to <a data-cite="RDF12-CONCEPTS#dfn-triple-term">triple terms</a> to
<a href="#func-triple-terms" class="sectionRef"></a>:
`TRIPLE`, `isTRIPLE`, `SUBJECT`, `PREDICATE`, `OBJECT`</li>
Expand Down
Loading