Skip to content

Commit f9fcfcf

Browse files
HolgerKnublauchajnelson-nistTallTedtpluscode
authored
#301: sh:values and sh:defaultValue (#310)
* #288: Added sh:SelectExpression, with test cases and TTL changes * #222, #288: Update SHACL-SHACL for general NodeExpression and SelectExpression Signed-off-by: Alex Nelson <alexander.nelson@nist.gov> * #222, #288: Undo update SHACL-SHACL for general NodeExpression and SelectExpression This patch undoes commit 8632a3e. This was done manually instead of with `git revert`. Signed-off-by: Alex Nelson <alexander.nelson@nist.gov> * Update shacl12-vocabularies/shacl.ttl Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com> * #301: Switched node expressions from sh:path to sh:values and sh:defaultValue * Update shacl12-core/index.html Co-authored-by: Tomasz Pluskiewicz <tpluscode@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com> * Update shacl12-core/index.html Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com> * Update shacl12-core/index.html Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com> * Update shacl12-sparql/index.html Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com> * Update shacl12-core/index.html Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com> * Update shacl12-core/index.html Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com> * Update shacl12-core/index.html Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com> * Moved example to after the evaluation part * Attempted to clarify that the "or" is not either-or * Update shacl12-core/index.html Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com> --------- Signed-off-by: Alex Nelson <alexander.nelson@nist.gov> Co-authored-by: Alex Nelson <alexander.nelson@nist.gov> Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com> Co-authored-by: Tomasz Pluskiewicz <tpluscode@users.noreply.github.com>
1 parent 9272a74 commit f9fcfcf

File tree

3 files changed

+62
-75
lines changed

3 files changed

+62
-75
lines changed

shacl12-core/index.html

Lines changed: 56 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ <h2>Shapes and Constraints</h2>
851851
<div class="diagram-class-properties-section">
852852
<div><a href="#name">sh:name</a> : xsd:string or rdf:langString</div>
853853
<div><a href="#description">sh:description</a> : xsd:string or rdf:langString</div>
854-
<div><a href="#defaultValue">sh:defaultValue</a> : any</div>
854+
<div><a href="#syntax-rule-path-defaultValue">sh:defaultValue</a> : any</div>
855855
<div><a href="#group">sh:group</a> : sh:PropertyGroup</div>
856856
</div>
857857
<div class="diagram-class-properties-section">
@@ -1447,25 +1447,24 @@ <h3>Property Shapes</h3>
14471447
<span data-syntax-rule="PropertyShape">A <dfn data-lt="property shapes">property shape</dfn> is a <a>shape</a> in the <a>shapes graph</a>
14481448
that is the <a>subject</a> of a <a>triple</a> that has <code>sh:path</code> as its <a>predicate</a>.</span>
14491449
<span data-syntax-rule="path-maxCount">A shape has at most one <a>value</a> for <code>sh:path</code>.</span>
1450-
<br/><br/>
1451-
<span data-syntax-rule="path-node">The <a>value</a> of <code>sh:path</code> in a property shape is either a <a>well-formed</a>
1452-
<a>SHACL property path</a> or a <a>well-formed</a> <a>node expression</a>.</span>
1453-
<span data-syntax-rule="path-expr-order">The syntax rules for <a>SHACL property paths</a> take precedence over <a>node expressions</a>;
1454-
for example, this means that an <a>IRI</a> will be interpreted as a <a>predicate path</a> instead of an <a>IRI expression</a>.</span>
1455-
<span data-syntax-rule="path-not-literal">The <a>value</a> of <code>sh:path</code> cannot be a <a>literal</a>.</span>
1450+
<span data-syntax-rule="path-node">The <a>value</a> of <code>sh:path</code> in a property shape is a <a>well-formed</a>
1451+
<a>SHACL property path</a>.</span>
14561452
<br/><br/>
14571453
It is recommended, but not required, for a <a>property shape</a> to be declared as a <a>SHACL instance</a> of <code>sh:PropertyShape</code>.
14581454
<span data-syntax-rule="PropertyShape-path-minCount"><a>SHACL instances</a> of <code>sh:PropertyShape</code> have one <a>value</a> for the property <code>sh:path</code>.</span>
1455+
<br/><br/>
1456+
<span data-syntax-rule="path-values">A <a>property shape</a> has at most one <a>value</a> for the property <code>sh:values</code> and this <a>value</a> is a <a>well-formed</a> <a>node expression</a>.</span>
1457+
<span data-syntax-rule="path-defaultValue">A <a>property shape</a> has at most one <a>value</a> for the property <code>sh:defaultValue</code> and this <a>value</a> is a <a>well-formed</a> <a>node expression</a>.</span>
1458+
<span data-syntax-rule="path-values-iri">A <a>property shape</a> can only have <a>values</a> for <code>sh:values</code> and/or <code>sh:defaultValue</code> when its <a>value</a> for <code>sh:path</code> is a <a href="#property-path-predicate">Predicate Path</a>.</span>
14591459
</p>
14601460
<p>
14611461
Informally, property shapes specify constraints that need to be met with respect to <a>nodes</a> that can be reached from the
1462-
<a>focus node</a> either by directly following a given property (specified as an <a>IRI</a>) or any other <a>SHACL property path</a>,
1463-
specified using <code>sh:path</code>.
1462+
<a>focus node</a> by either (a) directly following a given property (specified as an <a>IRI</a>), (b) directly following any other <a>SHACL property path</a>
1463+
(specified using <code>sh:path</code>), (c) evaluating the node expression (specified using <code>sh:values</code>),
1464+
or, (d) if no other values exist, evaluating the node expression (specified using <code>sh:defaultValue</code>).
14641465
</p>
14651466
<p>
1466-
If the <code>sh:path</code> is not a <a>well-formed</a> property path, it must be a <a>node expression</a>
1467-
and the constraints will be validated against the <a>output nodes</a> of this node expression.
1468-
Note that support for node expressions is not required by SHACL Core,
1467+
Note that support for <code>sh:values</code> and <code>sh:defaultValue</code> is not required by SHACL Core,
14691468
but is necessary for extensions such as [[shacl12-sparql]].
14701469
</p>
14711470
<p>
@@ -1514,8 +1513,9 @@ <h2>SHACL Expressions</h2>
15141513
SHACL Core supports such expressions in the following features:
15151514
</p>
15161515
<ul>
1516+
<li>Property paths can be used at <a href="#property-shapes"><code>sh:path</code></a> to derive the value nodes of a property shape.</li>
1517+
<li>Node expressions can be used at <a href="#property-shapes"><code>sh:values</code> and <code>sh:defaultValue</code></a> to derive the value nodes of a property shape.</li>
15171518
<li>Node expressions can be used at <a href="#targetNode"><code>sh:targetNode</code></a> to dynamically compute the targets of a shape.</li>
1518-
<li>Property paths and node expressions can be used at <a href="#property-shapes"><code>sh:path</code></a> to derive the value nodes of a property shape.</li>
15191519
<li>Node expressions can be used as parameter values of most <a href="#core-components">constraint components</a> to represent constraints that may be different depending on each focus node. <span class="todo">TODO: This change needs to be made still.</span></li>
15201520
</ul>
15211521

@@ -1678,21 +1678,37 @@ <h3>Node Expressions</h3>
16781678
Each of these parameters has an <a>IRI</a>.
16791679
One of these parameters can be the <dfn>key parameter</dfn> that uniquely identifies the <a>function name</a>.
16801680
</div>
1681+
<div class="def" id="node-expression-evaluation">
1682+
<div class="def-header">EVALUATION OF NODE EXPRESSIONS</div>
1683+
The <dfn>evaluation</dfn> of a node expression is defined as a function <code>eval(expr, activeGraph, scope) -> outputNodes</code>
1684+
where
1685+
<ul>
1686+
<li><code>expr</code> is a <a>node expression</a> that is the <a>subject</a> of <a>triples</a> where the <a>predicates</a> are the <a>node expression parameters</a>,
1687+
optional for any but the <a>key parameter</a> unless stated otherwise in the definition of the node expression function.</li>
1688+
<li><code>activeGraph</code> is a <a>graph</a>, called the <dfn>active graph</dfn>.</li>
1689+
<li><code>scope</code> is a map from <a href="https://www.w3.org/TR/sparql12-query/#defn_QueryVariable">variable names</a> to individual <a>nodes</a>.
1690+
The value of the variable <code>focusNode</code> (if it exists) is called the <dfn>input focus node</dfn>.
1691+
</li>
1692+
</ul>
1693+
The result of the evaluation of a node expression is a list of <a>nodes</a> (possibly empty and with duplicates) called the <dfn>output nodes</dfn>.
1694+
The evaluation may also result in an <dfn>evaluation failure</dfn>.
1695+
</div>
16811696
<p>
1682-
The following example illustrates the syntax of a node expression, used as a blank node value of <code>sh:path</code>:
1697+
The following example illustrates the syntax of a node expression, used as a blank node value of <code>sh:values</code>:
16831698
</p>
16841699
<aside class="example" title="A dynamically computed property using a node expression based on a SPARQL query">
16851700
<p>
16861701
Here is an example use of a node expression based on <a data-cite="shacl12-sparql#SelectExpression">SHACL-SPARQL</a>, computing
1687-
the values of a property shape for the property "full name" as the concatenation of <code>ex:firstName</code>,
1688-
a space and the <code>ex:lastName</code>.
1702+
the values of a property shape for the property "full name" as the concatenation of the <code>ex:firstName</code>,
1703+
a space, and the <code>ex:lastName</code>.
16891704
</p>
16901705
<div class="shapes-graph">
16911706
<div class="turtle">
16921707
ex:Person-fullName
16931708
a sh:PropertyShape ;
16941709
sh:name "full name" ;
1695-
sh:path <b>[
1710+
sh:path ex:fullName ;
1711+
sh:values <b>[
16961712
sh:select """
16971713
PREFIX ex: &lt;http://example.org/ns#&gt;
16981714
SELECT ?fullName
@@ -1711,23 +1727,8 @@ <h3>Node Expressions</h3>
17111727
and the <a>function name</a> is (as defined by SHACL-SPARQL) is <code>sh:SelectExpression</code>.
17121728
</p>
17131729
</aside>
1714-
<div class="def" id="node-expression-evaluation">
1715-
<div class="def-header">EVALUATION OF NODE EXPRESSIONS</div>
1716-
The <dfn>evaluation</dfn> of a node expression is defined as a function <code>eval(expr, activeGraph, scope) -> outputNodes</code>
1717-
where
1718-
<ul>
1719-
<li><code>expr</code> is a <a>node expression</a> that is the <a>subject</a> of <a>triples</a> where the <a>predicates</a> are the <a>node expression parameters</a>,
1720-
optional for any but the <a>key parameter</a> unless stated otherwise in the definition of the node expression function.</li>
1721-
<li><code>activeGraph</code> is a <a>graph</a>, called the <dfn>active graph</dfn>.</li>
1722-
<li><code>scope</code> is a map from <a href="https://www.w3.org/TR/sparql12-query/#defn_QueryVariable">variable names</a> to individual <a>nodes</a>.
1723-
The value of the variable <code>focusNode</code> (if it exists) is called the <dfn>input focus node</dfn>.
1724-
</li>
1725-
</ul>
1726-
The result of the evaluation of a node expression is a list of <a>nodes</a> (possibly empty and with duplicates) called the <dfn>output nodes</dfn>.
1727-
The evaluation may also result in an <dfn>evaluation failure</dfn>.
1728-
</div>
17291730
<p>
1730-
This SHACL Core specification only defines exactly the <a>node expression functions</a> from the following two sections.
1731+
This SHACL Core specification only exactly defines the <a>node expression functions</a> from the following two subsections.
17311732
Other specifications such as [[shacl12-sparql]] introduce additional functions.
17321733
Therefore <a>node expressions</a> serve as an extension point of SHACL.
17331734
<span class="todo">TODO: Add link to shacl12-node-expr once that is stable.</span>
@@ -2089,10 +2090,13 @@ <h5>Focus node (sh:focusNode)</h5>
20892090
<section id="results-path">
20902091
<h4>Path (sh:resultPath)</h4>
20912092
<p>
2092-
Validation results may have a value for the property <code>sh:resultPath</code> pointing at a <a>well-formed</a> <a>SHACL property path</a>
2093-
or <a>node expression</a>.
2093+
Validation results may have a value for the property <code>sh:resultPath</code> pointing at a <a>well-formed</a> <a>SHACL property path</a>.
20942094
For results produced by a <a>property shape</a>, this <a>SHACL property path</a> is equivalent to the <a>value</a> of <code>sh:path</code> of the shape,
20952095
unless stated otherwise. <!-- sh:closed is an exception -->
2096+
If the <code>sh:path</code> <code>p</code> is a <a>blank node</a>, then the <code>sh:resultPath</code> is a "deep copy"
2097+
of <code>p</code> and any <a>triples</a> that can be reached by transitively traversing the <a>blank nodes</a>
2098+
that appear in the <a>object</a> position of these triples.
2099+
See the <a href="https://www.w3.org/submissions/CBD/">Concise Bounded Description</a>.
20962100
</p>
20972101
</section>
20982102
<section id="results-value">
@@ -2167,22 +2171,23 @@ <h4>Value Nodes of Node Shapes</h4>
21672171
<h4>Value Nodes of Property Shapes</h4>
21682172
<p>
21692173
For <a>property shapes</a> with a <a>value</a> for <code>sh:path</code> <code>p</code> the
2170-
<a>value nodes</a> are defined as follows.
2171-
</p>
2172-
<p>
2173-
If <code>p</code> is a <a>SHACL property path</a>, then its value nodes are the set of <a>nodes</a> in the <a>data graph</a>
2174-
that can be reached from the <a>focus node</a> with the <a>path mapping</a> of <code>p</code>.
2175-
</p>
2176-
<p>
2177-
If <code>p</code> is a <a>node expression</a>, then its value nodes are the set of <a>output nodes</a> of
2178-
<code>eval(p, <a>data graph</a>, scope)</code> where <code>scope</code> contains the <a>focus node</a> as value of the variable <code>focusNode</code>.
2179-
</p>
2180-
<p>
2181-
Unless stated otherwise, the value of <code>sh:resultPath</code> of each validation result is a "deep copy"
2182-
of <code>p</code> and any <a>triples</a> that can be reached by transitively traversing the <a>blank nodes</a>
2183-
that appear in the <a>object</a> position of these triples.
2184-
See the <a href="https://www.w3.org/submissions/CBD/">Concise Bounded Description</a>.
2174+
set of <a>value nodes</a> is produced by the following steps:
21852175
</p>
2176+
<ol>
2177+
<li>
2178+
Add all <a>nodes</a> in the <a>data graph</a> that can be reached from the <a>focus node</a> with the <a>path mapping</a> of <code>p</code>.
2179+
</li>
2180+
<li>
2181+
If <code>e</code> is the <a>value</a> of <code>sh:values</code> at the <a>property shape</a>,
2182+
then add the <a>output nodes</a> of <code>eval(e, <a>data graph</a>, scope)</code> where <code>scope</code>
2183+
contains the <a>focus node</a> as the value of the variable <code>focusNode</code>.
2184+
</li>
2185+
<li>
2186+
If the set is still empty and <code>d</code> is the <a>value</a> of <code>sh:defaultValue</code> at the <a>property shape</a>,
2187+
then add the <a>output nodes</a> of <code>eval(d, <a>data graph</a>, scope)</code> where <code>scope</code>
2188+
contains the <a>focus node</a> as the value of the variable <code>focusNode</code>.
2189+
</li>
2190+
</ol>
21862191
</section>
21872192
</section>
21882193
</section>
@@ -4158,16 +4163,6 @@ <h3>sh:group</h3>
41584163
Groups may also have an <code>sh:order</code> property to indicate
41594164
the relative ordering of groups within the same form.
41604165
</p>
4161-
</section>
4162-
<section id="defaultValue">
4163-
<h3>sh:defaultValue</h3>
4164-
<p>
4165-
Property shapes may have a single value for <code>sh:defaultValue</code>.
4166-
The default value does not have fixed semantics in SHACL,
4167-
but MAY be used by user interface tools to pre-populate input widgets.
4168-
The value type of the <code>sh:defaultValue</code> SHOULD align with
4169-
the specified <code>sh:datatype</code> or <code>sh:class</code> of the same shape.
4170-
</p>
41714166
<p>
41724167
The following example illustrates the use of these various features together.
41734168
</p>
@@ -4340,7 +4335,7 @@ <h2>Revision History</h2>
43404335
<section class="appendix informative" id="changes-12">
43414336
<h2>Changes between SHACL 1.0 Core and SHACL 1.2 Core</h2>
43424337
<ul>
4343-
<li>Introduced <a>node expressions</a> as an extension point to dynamically compute lists of nodes. Generalized <code>sh:targetNode</code> and <code>sh:path</code> to support node expressions.</li>
4338+
<li>Introduced <a>node expressions</a> as an extension point to dynamically compute lists of nodes. Generalized <code>sh:targetNode</code> and <code>sh:defaultValue</code>, and introduced <code>sh:values</code> to support node expressions.</li>
43444339
<li>Added the new constraint component <a href="#SingleLineConstraintComponent"><code>sh:singleLine</code></a>, see <a href="https://github.com/w3c/data-shapes/issues/177">Issue 177</a></li>
43454340
<li>Added the new class <a href="#ShapeClass"><code>sh:ShapeClass</code></a> for implicit class targets, see <a href="https://github.com/w3c/data-shapes/issues/212">Issue 212</a></li>
43464341
<li>Moved SPARQL-based validators from Core to an Appendix of SHACL-SPARQL, see <a href="https://github.com/w3c/data-shapes/issues/271">Issue 271</a></li>

shacl12-sparql/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,14 +1246,15 @@ <h3>Select Expressions</h3>
12461246
<aside class="example" title="A dynamically computed property using a node expression based on a SPARQL query">
12471247
<p>
12481248
Here is an example use of a <a>select expression</a>, computing the values of a property shape for the property
1249-
"full name" as the concatenation of <code>ex:firstName</code>, a space and the <code>ex:lastName</code>.
1249+
"full name" as the concatenation of the <code>ex:firstName</code>, a space, and the <code>ex:lastName</code>.
12501250
</p>
12511251
<div class="shapes-graph">
12521252
<div class="turtle">
12531253
ex:Person-fullName
12541254
a sh:PropertyShape ;
12551255
sh:name "full name" ;
1256-
sh:path <b>[
1256+
sh:path ex:fullName ;
1257+
sh:values <b>[
12571258
sh:prefixes &lt;http://example.org/ns&gt; ;
12581259
sh:select """
12591260
SELECT ?fullName

shacl12-test-suite/tests/sparql/property/property-select-001.ttl

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ ex:Person-fullName
1212
a sh:PropertyShape ;
1313
sh:targetClass ex:Person ;
1414
sh:name "full name" ;
15-
sh:path [
15+
sh:path ex:fullName ;
16+
sh:values [
1617
sh:prefixes <http://example.org/ns> ;
1718
sh:select """
1819
SELECT ?fullName
@@ -62,17 +63,7 @@ ex:JohnWayne
6263
sh:result [
6364
rdf:type sh:ValidationResult ;
6465
sh:focusNode ex:JohnWayne ;
65-
sh:resultPath [
66-
sh:prefixes <http://example.org/ns> ;
67-
sh:select """
68-
SELECT ?fullName
69-
WHERE {
70-
$this ex:firstName ?firstName .
71-
$this ex:lastName ?lastName .
72-
BIND (CONCAT(?firstName, " ", ?lastName) AS ?fullName) .
73-
}
74-
"""
75-
] ;
66+
sh:resultPath ex:fullName ;
7667
sh:resultSeverity sh:Violation ;
7768
sh:sourceConstraintComponent sh:HasValueConstraintComponent ;
7869
sh:sourceShape ex:Person-fullName ;

0 commit comments

Comments
 (0)