Skip to content

Commit ab8abf1

Browse files
HolgerKnublauchbergosTallTed
authored
Issue 172: Support for sh:closed sh:ByTypes (#399)
* Parking unfinished work * #172: Support for sh:ByTypes, test cases * #172: Fixed test case number * Update shacl12-core/index.html Co-authored-by: Thomas Bergwinkl <[email protected]> * Apply suggestions from code review Co-authored-by: Ted Thibodeau Jr <[email protected]> * Removed unnecessary sh:ignoredProperties statement * Applied <pre class="text" as suggested by Ted * Replaced tabs with spaces --------- Co-authored-by: Thomas Bergwinkl <[email protected]> Co-authored-by: Ted Thibodeau Jr <[email protected]>
1 parent a932976 commit ab8abf1

File tree

5 files changed

+196
-7
lines changed

5 files changed

+196
-7
lines changed

shacl12-core/index.html

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ <h2>Shapes and Constraints</h2>
11131113
<div class="diagram-class-properties">
11141114
<div class="diagram-class-properties-start">
11151115
<div><b><a href="#constraints">Constraint parameters</a></b>, for example:</div>
1116-
<div><a href="#ClosedConstraintComponent">sh:closed</a> : xsd:boolean</div>
1116+
<div><a href="#ClosedConstraintComponent">sh:closed</a> : xsd:boolean or sh:ByTypes</div>
11171117
<div><a href="#OrConstraintComponent">sh:or</a> : rdf:List</div>
11181118
<div><a href="#NotConstraintComponent">sh:not</a> : sh:Shape</div>
11191119
<div><a href="#PropertyConstraintComponent">sh:property</a> : sh:PropertyShape</div>
@@ -6106,7 +6106,8 @@ <h3>sh:closed, sh:ignoredProperties</h3>
61066106
<td><code>sh:closed</code></td>
61076107
<td>
61086108
Set to <code>true</code> to close the shape.
6109-
<span data-syntax-rule="closed-datatype">The values of <code>sh:closed</code> in a shape are literals with datatype <code>xsd:boolean</code>.</span>
6109+
<span data-syntax-rule="closed-datatype">The values of <code>sh:closed</code> in a shape are literals with datatype <code>xsd:boolean</code>
6110+
or the <a>IRI</a> <code>sh:ByTypes</code>.</span>
61106111
</td>
61116112
</tr>
61126113
<tr>
@@ -6123,14 +6124,41 @@ <h3>sh:closed, sh:ignoredProperties</h3>
61236124
<div class="def-text-body" data-validator="Closed">
61246125
Let <code>$closed</code> be a <a>parameter value</a> for <code>sh:closed</code>.
61256126
Let <code>$ignoredProperties</code> be a <a>value</a> for <code>sh:ignoredProperties</code>.
6126-
If <code>$closed</code> is <code>true</code> then
6127-
there is a <a>validation result</a> for each <a>triple</a> that has a <a>value node</a> as its
6128-
<a>subject</a> and a <a>predicate</a> that is not explicitly enumerated as a <a>value</a> of <code>sh:path</code>
6129-
in any of the <a>property shapes</a> declared via <code>sh:property</code> at the current shape.
6127+
<br/><br/>
6128+
If <code>$closed</code> is <code>true</code> or <code>sh:ByTypes</code> and <code>P</code>
6129+
is the set of properties defined below,
6130+
then there is a <a>validation result</a> for each <a>triple</a> that has a <a>value node</a> as its
6131+
<a>subject</a> and a <a>predicate</a> that is not in <code>P</code>.
61306132
If <code>$ignoredProperties</code> has a value then the properties enumerated as <a>members</a> of this <a>SHACL list</a>
61316133
are also permitted for the <a>value node</a>.
61326134
The <a>validation result</a> MUST have the <a>predicate</a> of the triple as its <code>sh:resultPath</code>,
61336135
and the <a>object</a> of the triple as its <code>sh:value</code>.
6136+
<br/><br/>
6137+
If <code>$closed</code> is <code>true</code>, then <code>P</code> is the set of <a>IRI</a> properties
6138+
that can be reached from the current shape via the SPARQL path <code>sh:property/sh:path</code>.
6139+
<br/><br/>
6140+
If <code>$closed</code> is <code>sh:ByTypes</code>, then <code>P</code> is the set of <a>IRI</a> properties
6141+
that can be reached from the value node via the following algorithm, plus <code>rdf:type</code>:
6142+
<div style="margin: 20px">
6143+
<pre class="text">
6144+
function collectProperties(S)
6145+
add all IRI properties that can be reached from S via the SPARQL path
6146+
sh:property/sh:path
6147+
if S is a SHACL instance of rdfs:Class in the shapes graph {
6148+
for each triple in the shapes graph matching (S rdfs:subClassOf ?o)
6149+
collectProperties(?o)
6150+
for each triple in the shapes graph matching (?s sh:targetClass S)
6151+
collectProperties(?s)
6152+
}
6153+
if S is a SHACL instance of sh:NodeShape in the shapes graph
6154+
for each triple in the shapes graph matching (S sh:node ?o)
6155+
collectProperties(?o)
6156+
6157+
for each rdf:type T of the value node in the data graph
6158+
collectProperties(T)
6159+
</pre></div>
6160+
Note that implementations need to avoid infinite loops in the algorithm above by preventing
6161+
it from visiting the same `S` twice.
61346162
</div>
61356163
</div>
61366164
<p><em>The remainder of this section is informative.</em></p>
@@ -6218,6 +6246,15 @@ <h3>sh:closed, sh:ignoredProperties</h3>
62186246
</div>
62196247
</div>
62206248
</aside>
6249+
<p>
6250+
The use case for <code>sh:closed sh:ByTypes</code> includes properties that are declared
6251+
in superclasses of the types of the current value node (via <code>rdfs:subClassOf</code>),
6252+
as well as other shapes that are linked to those types via <code>sh:targetClass</code> and
6253+
the shapes that can be reached from one node shape to the other via <code>sh:node</code>.
6254+
Examples for <code>sh:ByTypes</code> can be found in the test case library:
6255+
<a href="../shacl12-test-suite/tests/core/node/closed-003.ttl">closed-003.ttl</a>,
6256+
<a href="../shacl12-test-suite/tests/core/node/closed-004.ttl">closed-004.ttl</a>.
6257+
</p>
62216258
</section>
62226259

62236260
<section id="HasValueConstraintComponent">
@@ -6938,6 +6975,7 @@ <h2>Changes between SHACL 1.0 Core and SHACL 1.2 Core</h2>
69386975
<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>
69396976
<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>
69406977
<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>
6978+
<li>Added the new value <code>sh:ByTypes</code> for <a href="#ClosedConstraintComponent"><code>sh:closed</code></a>; see <a href="https://github.com/w3c/data-shapes/issues/172">Issue 172</a></li>
69416979
<li>The values of <a href="#ClassConstraintComponent"><code>sh:class</code></a> and <a href="#DatatypeConstraintComponent"><code>sh:datatype</code></a> can now also be lists, indicating a union of choices; see <a href="https://github.com/w3c/data-shapes/issues/160">Issue 160</a></li>
69426980
</ul>
69436981
</section>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
@prefix dash: <http://datashapes.org/dash#> .
2+
@prefix ex: <http://example.com/ns#> .
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:RootClass
12+
a rdfs:Class, sh:NodeShape ;
13+
sh:property [ sh:path ex:rootClassProperty1 ] ;
14+
sh:closed sh:ByTypes ;
15+
.
16+
ex:SubClass
17+
a rdfs:Class, sh:NodeShape ;
18+
rdfs:subClassOf ex:RootClass ;
19+
sh:property [ sh:path ex:subClassProperty1 ] ;
20+
sh:property [ sh:path ex:subClassProperty2 ] ;
21+
sh:closed sh:ByTypes ;
22+
.
23+
24+
# Invalid because it uses ex:subClassProperty1 but it's not an instance of SubClass
25+
ex:InvalidInstance1
26+
a ex:RootClass ;
27+
ex:subClassProperty1 1 ;
28+
.
29+
ex:ValidInstance1
30+
a ex:RootClass ;
31+
ex:rootClassProperty1 1 ;
32+
.
33+
ex:ValidInstance2
34+
a ex:SubClass ;
35+
ex:rootClassProperty1 1 ;
36+
ex:subClassProperty1 3 ;
37+
ex:subClassProperty2 4 ;
38+
.
39+
<>
40+
rdf:type mf:Manifest ;
41+
mf:entries (
42+
<closed-003>
43+
) ;
44+
.
45+
<closed-003>
46+
rdf:type sht:Validate ;
47+
rdfs:label "Test of sh:closed at node shape 003" ;
48+
mf:action [
49+
sht:dataGraph <> ;
50+
sht:shapesGraph <> ;
51+
] ;
52+
mf:result [
53+
rdf:type sh:ValidationReport ;
54+
sh:conforms "false"^^xsd:boolean ;
55+
sh:result [
56+
rdf:type sh:ValidationResult ;
57+
sh:focusNode ex:InvalidInstance1 ;
58+
sh:resultPath ex:subClassProperty1 ;
59+
sh:resultSeverity sh:Violation ;
60+
sh:sourceConstraintComponent sh:ClosedConstraintComponent ;
61+
sh:sourceShape ex:RootClass ;
62+
sh:value 1 ;
63+
] ;
64+
] ;
65+
mf:status sht:approved ;
66+
.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
@prefix dash: <http://datashapes.org/dash#> .
2+
@prefix ex: <http://example.com/ns#> .
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:RootClass
12+
a rdfs:Class, sh:NodeShape ;
13+
sh:property [ sh:path ex:rootClassProperty1 ] ;
14+
sh:closed sh:ByTypes ;
15+
.
16+
ex:SubClass
17+
a rdfs:Class, sh:NodeShape ;
18+
rdfs:subClassOf ex:RootClass ;
19+
sh:property [ sh:path ex:subClassProperty1 ] ;
20+
sh:property [ sh:path ex:subClassProperty2 ] ;
21+
.
22+
ex:RootShape
23+
a sh:NodeShape ;
24+
sh:targetClass ex:RootClass ;
25+
sh:property [ sh:path ex:rootShapeProperty1 ] ;
26+
.
27+
ex:SubShape
28+
a sh:NodeShape ;
29+
sh:targetClass ex:SubClass ;
30+
sh:node ex:SuperShape ;
31+
sh:property [ sh:path ex:subShapeProperty1 ] ;
32+
.
33+
ex:SuperShape
34+
a sh:NodeShape ;
35+
sh:property [ sh:path ex:superShapeProperty1 ] ;
36+
.
37+
38+
# Invalid because it uses ex:subClassProperty1 but it's not an instance of SubClass
39+
ex:InvalidInstance1
40+
a ex:RootClass ;
41+
ex:subClassProperty1 1 ;
42+
.
43+
ex:ValidInstance1
44+
a ex:RootClass ;
45+
ex:rootClassProperty1 1 ;
46+
ex:rootShapeProperty1 2 ;
47+
.
48+
ex:ValidInstance2
49+
a ex:SubClass ;
50+
ex:rootClassProperty1 1 ;
51+
ex:rootShapeProperty1 2 ;
52+
ex:subClassProperty1 3 ;
53+
ex:subClassProperty2 4 ;
54+
ex:subShapeProperty1 5 ;
55+
ex:superShapeProperty1 6 ;
56+
.
57+
<>
58+
rdf:type mf:Manifest ;
59+
mf:entries (
60+
<closed-004>
61+
) ;
62+
.
63+
<closed-004>
64+
rdf:type sht:Validate ;
65+
rdfs:label "Test of sh:closed at node shape 004" ;
66+
mf:action [
67+
sht:dataGraph <> ;
68+
sht:shapesGraph <> ;
69+
] ;
70+
mf:result [
71+
rdf:type sh:ValidationReport ;
72+
sh:conforms "false"^^xsd:boolean ;
73+
sh:result [
74+
rdf:type sh:ValidationResult ;
75+
sh:focusNode ex:InvalidInstance1 ;
76+
sh:resultPath ex:subClassProperty1 ;
77+
sh:resultSeverity sh:Violation ;
78+
sh:sourceConstraintComponent sh:ClosedConstraintComponent ;
79+
sh:sourceShape ex:RootClass ;
80+
sh:value 1 ;
81+
] ;
82+
] ;
83+
mf:status sht:approved ;
84+
.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
mf:include <class-003.ttl> ;
1313
mf:include <closed-001.ttl> ;
1414
mf:include <closed-002.ttl> ;
15+
mf:include <closed-003.ttl> ;
16+
mf:include <closed-004.ttl> ;
1517
mf:include <datatype-001.ttl> ;
1618
mf:include <datatype-002.ttl> ;
1719
mf:include <datatype-003.ttl> ;

shacl12-vocabularies/shacl.ttl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,6 @@ sh:ClosedConstraintComponent
533533
sh:ClosedConstraintComponent-closed
534534
a sh:Parameter ;
535535
sh:path sh:closed ;
536-
sh:datatype xsd:boolean ;
537536
rdfs:isDefinedBy sh: .
538537

539538
sh:ClosedConstraintComponent-ignoredProperties

0 commit comments

Comments
 (0)