Skip to content

Commit d0b478f

Browse files
HolgerKnublauchYoucTaghTallTed
authored
#357: Added sh:expression (#360)
* #357: Added sh:expression I had to make the definition of Deep Copy stand-alone so that I could reuse it in multiple places. I didn't add an example as Core doesn't define interesting enough node expression types. The test case shows the syntax. * Update shacl12-core/index.html Co-authored-by: Yousouf Taghzouti <[email protected]> * #357: Clarify that reification is not included in deep copy * Apply suggestions from code review Co-authored-by: Ted Thibodeau Jr <[email protected]> --------- Co-authored-by: Yousouf Taghzouti <[email protected]> Co-authored-by: Ted Thibodeau Jr <[email protected]>
1 parent 307916a commit d0b478f

File tree

3 files changed

+110
-4
lines changed

3 files changed

+110
-4
lines changed

shacl12-core/index.html

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,18 @@ <h3>Terminology</h3>
575575
if one of the <a>SHACL types</a> of <code>n</code> in <code>G</code> is <code>C</code>.
576576
</div>
577577
</div>
578+
<div class="def">
579+
<div class="term-def-header">Deep Copy</div>
580+
<div>
581+
For a <a>node</a> <code>n</code> in a <a>graph</a> <code>sourceGraph</code>,
582+
the <dfn data-lt="deep copy">deep copy</dfn> of <code>n</code> in a <a>graph</a> <code>targetGraph</code>
583+
is <code>n</code> in <code>targetGraph</code> plus, if <code>n</code> is a <a>blank node</a>,
584+
any <a>triples</a> from <code>sourceGraph</code> that can be reached by transitively traversing
585+
the <a>blank nodes</a> that appear in the <a>object</a> position of a triple that can be reached
586+
starting with <code>n</code> as the <a>subject</a>. This is similar to
587+
the <a href="https://www.w3.org/submissions/CBD/">Concise Bounded Description</a>, but without reification.
588+
</div>
589+
</div>
578590

579591
</section>
580592

@@ -2378,6 +2390,7 @@ <h2>Node Expressions</h2>
23782390
<ul>
23792391
<li>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>
23802392
<li>At <a href="#targetNode"><code>sh:targetNode</code></a> to dynamically compute the targets of a shape.</li>
2393+
<li>At <a href="#ExpressionConstraintComponent"><code>sh:expression</code></a> to validate nodes against a condition.</li>
23812394
<li>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, see ISSUE 311.</span></li>
23822395
<li>At <a href="#deactivated"><code>sh:deactivated</code></a> to deactivate certain shapes under specific conditions. <span class="todo">TODO: This change needs to be made still, see ISSUE 338.</span></li>
23832396
</ul>
@@ -2823,10 +2836,7 @@ <h4>Path (sh:resultPath)</h4>
28232836
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>.
28242837
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,
28252838
unless stated otherwise. <!-- sh:closed is an exception -->
2826-
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"
2827-
of <code>p</code> and any <a>triples</a> that can be reached by transitively traversing the <a>blank nodes</a>
2828-
that appear in the <a>object</a> position of these triples.
2829-
See the <a href="https://www.w3.org/submissions/CBD/">Concise Bounded Description</a>.
2839+
If the <code>sh:path</code> <code>p</code> is a <a>blank node</a>, then the <code>sh:resultPath</code> is a <a>deep copy</a> of <code>p</code> in the results graph.
28302840
</p>
28312841
</section>
28322842
<section id="results-value">
@@ -5982,6 +5992,52 @@ <h4>sh:in</h4>
59825992
</div>
59835993
</aside>
59845994
</section>
5995+
5996+
<section id="ExpressionConstraintComponent">
5997+
<h4>sh:expression</h4>
5998+
<p>
5999+
Based on <a>node expressions</a>, this section introduces a <a>constraint component</a> called
6000+
<dfn data-lt="expression constraint">expression constraints</dfn>.
6001+
Expression constraints can be used in any <a>shape</a> to declare the condition that the
6002+
<a>node expression</a> specified via <code>sh:expression</code> has <code>true</code> as one of its output nodes.
6003+
The evaluation of these node expressions is repeated for all <a>value nodes</a> of the <a>shape</a>
6004+
as the <a>focus node</a>.
6005+
</p>
6006+
<p>
6007+
<span class="component-class">Constraint Component IRI</span>: <code>sh:ExpressionConstraintComponent</code>
6008+
</p>
6009+
6010+
<div class="parameters">Parameters:</div>
6011+
<table class="term-table">
6012+
<tr>
6013+
<th>Property</th>
6014+
<th>Summary and Syntax Rules</th>
6015+
</tr>
6016+
<tr>
6017+
<td><code>sh:expression</code></td>
6018+
<td>
6019+
The <a>node expression</a> that must return <code>true</code>.
6020+
<span data-syntax-rule="expression-scope">The <a>values</a> of <code>sh:expression</code> at a
6021+
<a>shape</a> must be well-formed <a>node expressions</a>.</span>
6022+
</td>
6023+
</tr>
6024+
</table>
6025+
<div class="def def-text">
6026+
<div class="def-header">TEXTUAL DEFINITION</div>
6027+
<div class="def-text-body" data-validator="Expression">
6028+
Let <code>expr</code> be the <a>value</a> of <code>sh:expression</code>.
6029+
For each <a>value node</a> <code>v</code>
6030+
and <code>scope</code> contains <code>v</code> as the value of <code>focusNode</code>
6031+
where <code>evalExpr(expr, activeGraph, scope)</code>
6032+
does not return <code>true</code> as one of its <a>output nodes</a>,
6033+
there is a <a>validation result</a> that has <code>v</code> as its <code>sh:value</code>
6034+
and a <a>deep copy</a> of <code>expr</code> in the results graph as its <code>sh:sourceConstraint</code>.
6035+
If the <code>expr</code> has <a>values</a> for <code>sh:message</code> in the <a>shapes graph</a>,
6036+
then these <a>values</a> become the (only) values for <code>sh:resultMessage</code> in the
6037+
<a>validation result</a>.
6038+
</div>
6039+
</div>
6040+
</section>
59856041
</section>
59866042
</section>
59876043

@@ -6479,6 +6535,7 @@ <h2>Changes between SHACL 1.0 Core and SHACL 1.2 Core</h2>
64796535
<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>
64806536
<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>
64816537
<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>
6538+
<li>Added the new constraint component <a href="#ExpressionConstraintComponent"><code>sh:expression</code></a>, see <a href="https://github.com/w3c/data-shapes/issues/357">Issue 357</a></li>
64826539
</ul>
64836540
</section>
64846541
</body>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@prefix dash: <http://datashapes.org/dash#> .
2+
@prefix ex: <http://datashapes.org/sh/tests/core/node/expression-001.test#> .
3+
@prefix mf: <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#> .
4+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
5+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
6+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
7+
@prefix sh: <http://www.w3.org/ns/shacl#> .
8+
@prefix sht: <http://www.w3.org/ns/shacl-test#> .
9+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
10+
11+
ex:InvalidInstance
12+
rdf:type ex:TestShape ;
13+
rdfs:label "Invalid instance" ;
14+
.
15+
ex:TestShape
16+
rdf:type rdfs:Class ;
17+
rdf:type sh:NodeShape ;
18+
rdfs:label "Test shape" ;
19+
sh:expression false ; # Only using constant false here because Core doesn't define interesting node expressions
20+
.
21+
<>
22+
rdf:type mf:Manifest ;
23+
mf:entries (
24+
<expression-001>
25+
) ;
26+
.
27+
<expression-001>
28+
rdf:type sht:Validate ;
29+
rdfs:label "Test of sh:expression at node shape 001" ;
30+
mf:action [
31+
sht:dataGraph <> ;
32+
sht:shapesGraph <> ;
33+
] ;
34+
mf:result [
35+
rdf:type sh:ValidationReport ;
36+
sh:conforms "false"^^xsd:boolean ;
37+
sh:result [
38+
rdf:type sh:ValidationResult ;
39+
sh:focusNode ex:InvalidInstance ;
40+
sh:resultSeverity sh:Violation ;
41+
sh:sourceConstraint false ;
42+
sh:sourceConstraintComponent sh:ExpressionConstraintComponent ;
43+
sh:sourceShape ex:TestShape ;
44+
sh:value ex:InvalidInstance ;
45+
] ;
46+
] ;
47+
mf:status sht:approved ;
48+
.

shacl12-test-suite/tests/core/node/manifest.ttl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
mf:include <datatype-002.ttl> ;
1717
mf:include <disjoint-001.ttl> ;
1818
mf:include <equals-001.ttl> ;
19+
mf:include <expression-001.ttl> ;
1920
mf:include <hasValue-001.ttl> ;
2021
mf:include <in-001.ttl> ;
2122
mf:include <languageIn-001.ttl> ;

0 commit comments

Comments
 (0)