Skip to content

Commit 0ada76a

Browse files
#173: Support sh:message, sh:severity, and sh:deactivated per constraint triple (#396)
* #173: Added reification support for sh:deactivated * #173: sh:severity can now be set as reifier * #173: Support for sh:message using reification * #173: Removed domain from sh:severity * Update shacl12-core/index.html Co-authored-by: Thomas Bergwinkl <bergos@users.noreply.github.com> --------- Co-authored-by: Thomas Bergwinkl <bergos@users.noreply.github.com>
1 parent 4166cfb commit 0ada76a

File tree

6 files changed

+265
-15
lines changed

6 files changed

+265
-15
lines changed

shacl12-core/index.html

Lines changed: 129 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,10 +1724,10 @@ <h4>Objects-of targets (sh:targetObjectsOf)</h4>
17241724
</section>
17251725

17261726
<section id="severity">
1727-
<h4>Declaring the Severity of a Shape</h4>
1727+
<h4>Declaring the Severity of a Shape or Constraint</h4>
17281728
<p class="syntax">
17291729
<span data-syntax-rule="severity-maxCount">Shapes can specify one <a>value</a> for the property <code>sh:severity</code> in the <a>shapes graph</a>.</span>
1730-
<span data-syntax-rule="severity-nodeKind">Each value of <code>sh:severity</code> in a shape is an <a>IRI</a>.</span>
1730+
<span data-syntax-rule="severity-nodeKind">Each value of <code>sh:severity</code> is an <a>IRI</a>.</span>
17311731
</p>
17321732
<p>
17331733
The values of <code>sh:severity</code> are called <dfn data-lt="severity">severities</dfn>.
@@ -1752,6 +1752,17 @@ <h4>Declaring the Severity of a Shape</h4>
17521752
<td>A constraint violation.</td>
17531753
</tr>
17541754
</table>
1755+
<p>
1756+
In addition to declaring severities per shape, the property <code>sh:severity</code> can also be used
1757+
on a <a>reifier</a> for a triple where the <a>shape</a> is the <a>subject</a> and one of the <a>parameters</a>
1758+
of the <a>constraint</a> is the <a>predicate</a>.
1759+
</p>
1760+
<p class="syntax">
1761+
<span data-syntax-rule="severity-reifier-maxCount">
1762+
Let <code>T</code> be the set of <a>triples</a> that represent a <a>constraint</a> in a <a>shape</a>.
1763+
A <a>shapes graph</a> can specify at most one <a>value</a> for the property <code>sh:severity</code>
1764+
in the <a>reifiers</a> of the <a>triples</a> in <code>T</code>.
1765+
</p>
17551766
<p><em>The remainder of this section is informative.</em></p>
17561767
<p>
17571768
The specific values of <code>sh:severity</code> have no impact on the validation,
@@ -1761,7 +1772,7 @@ <h4>Declaring the Severity of a Shape</h4>
17611772
Any IRI can be used as a severity.
17621773
</p>
17631774
<p>
1764-
For every shape, <code>sh:Violation</code> is the default if <code>sh:severity</code> is unspecified.
1775+
For every shape and constraint, <code>sh:Violation</code> is the default if <code>sh:severity</code> is unspecified.
17651776
The following example illustrates this.
17661777
</p>
17671778
<aside class="example">
@@ -1938,35 +1949,96 @@ <h4>Declaring the Severity of a Shape</h4>
19381949
</div>
19391950
</div>
19401951
</aside>
1952+
<p>
1953+
The following example is a variation of the shapes graph above, but using reification to
1954+
specify the severity of individual constraints:
1955+
</p>
1956+
<aside class="example">
1957+
<div class="shapes-graph">
1958+
<div class="turtle">
1959+
ex:MyShape
1960+
a sh:NodeShape ;
1961+
<span class="target-can-be-skipped">sh:targetNode ex:MyInstance ;</span>
1962+
sh:property [ # _:b1
1963+
sh:path ex:myProperty ;
1964+
sh:minCount 1 {| sh:severity sh:Info |} ;
1965+
sh:datatype xsd:string {| sh:severity sh:Warning |} ;
1966+
] ;
1967+
sh:property [ # _:b2
1968+
# The default severity here is sh:Violation
1969+
sh:path ex:myProperty ;
1970+
sh:maxLength 10 ;
1971+
sh:message "Too many characters"@en ;
1972+
sh:message "Zu viele Zeichen"@de ;
1973+
] .
1974+
</div>
1975+
<div class="jsonld">
1976+
N/A
1977+
</div>
1978+
</div>
1979+
</aside>
19411980
</section>
19421981

19431982
<section id="message">
1944-
<h4>Declaring Messages for a Shape</h4>
1983+
<h4>Declaring Messages for a Shape or Constraint</h4>
19451984
<p class="syntax">
19461985
Shapes can have values for the property <code>sh:message</code>.
1947-
<span data-syntax-rule="message-datatype">The values of <code>sh:message</code> in a shape are either <code>xsd:string</code> literals or literals with a language tag.</span>
1948-
A shape should not have more than one value for <code>sh:message</code> with the same language tag.
1986+
<span data-syntax-rule="message-datatype">The values of <code>sh:message</code> are either <code>xsd:string</code> literals or literals with a language tag.</span>
1987+
A subject should not have more than one value for <code>sh:message</code> with the same language tag.
19491988
</p>
19501989
<p>
19511990
If a shape has at least one value for <code>sh:message</code> in the shapes graph, then
19521991
all <a>validation results</a> produced as a result of the shape will have exactly these messages
19531992
as their value of <code>sh:resultMessage</code>, i.e. the values will be copied from the shapes graph
19541993
into the results graph.
19551994
</p>
1995+
<p>
1996+
In addition to declaring messages per shape, the property <code>sh:message</code> can also be used
1997+
on a <a>reifier</a> for a triple where the <a>shape</a> is the <a>subject</a> and one of the <a>parameters</a>
1998+
of the <a>constraint</a> is the <a>predicate</a>.
1999+
</p>
2000+
<p class="syntax">
2001+
<span data-syntax-rule="message-reifier-maxCount">
2002+
Let <code>T</code> be the set of <a>triples</a> that represent a <a>constraint</a> in a <a>shape</a>.
2003+
A <a>shapes graph</a> can specify at most one <a>value</a> for the property <code>sh:message</code>
2004+
in the <a>reifiers</a> of the <a>triples</a> in <code>T</code>.
2005+
</p>
19562006
<p><em>The remainder of this section is informative.</em></p>
19572007
<p>
1958-
The example from the previous section uses this mechanism to supply the second validation result
1959-
with two messages.
19602008
See the <a href="#results-message">section on <code>sh:resultMessage</code> in the validation results</a>
19612009
on further details on how the values of <code>sh:resultMessage</code> are populated.
19622010
</p>
2011+
<p>
2012+
The example from the previous section uses this mechanism to supply the second validation result
2013+
with two messages.
2014+
The following example is a variation where the message is declared using reification.
2015+
</p>
2016+
<aside class="example">
2017+
<div class="shapes-graph">
2018+
<div class="turtle">
2019+
ex:MyShape
2020+
a sh:NodeShape ;
2021+
<span class="target-can-be-skipped">sh:targetNode ex:MyInstance ;</span>
2022+
sh:property [
2023+
sh:path ex:myProperty ;
2024+
sh:maxLength 10 {|
2025+
sh:message "Too many characters"@en ;
2026+
sh:message "Zu viele Zeichen"@de ;
2027+
|}
2028+
] .
2029+
</div>
2030+
<div class="jsonld">
2031+
N/A
2032+
</div>
2033+
</div>
2034+
</aside>
19632035
</section>
19642036

19652037
<section id="deactivated">
1966-
<h4>Deactivating a Shape</h4>
2038+
<h4>Deactivating Shapes and Constraints</h4>
19672039
<p class="syntax">
19682040
<span data-syntax-rule="deactivated-maxCount">Shapes can have at most one value for the property <code>sh:deactivated</code>.</span>
1969-
<span data-syntax-rule="deactivated-datatype">The value of <code>sh:deactivated</code> in a shape is a <a>node expression</a>
2041+
<span data-syntax-rule="deactivated-datatype">The value of <code>sh:deactivated</code> is a <a>node expression</a>
19702042
that must have either <code>true</code> or <code>false</code> as the (only) <a>output node</a>.</span>
19712043
</p>
19722044
<p>
@@ -1975,6 +2047,22 @@ <h4>Deactivating a Shape</h4>
19752047
<a>output node</a>, the shape is called <dfn data-lt="deactivate">deactivated</dfn>.
19762048
All RDF terms <a>conform</a> to a deactivated shape.
19772049
</p>
2050+
<p>
2051+
In addition to deactivating all constraints for a shape, it is also possible to deactivate individual constraints.
2052+
This is done using reification.
2053+
</p>
2054+
<p class="syntax">
2055+
<span data-syntax-rule="deactivated-reified-maxCount">A <a>triple</a> that has a <a>shape</a> as <a>subject</a>,
2056+
a <a>parameter</a> (such as <code>sh:minCount</code>) as <a>predicate</a> can have at most one
2057+
<a>reifier</a> with a <a>value</a> for the property <code>sh:deactivated</code>.</span>
2058+
</p>
2059+
<p>
2060+
Let <code>expr</code> be the <a>value</a> of <code>sh:deactivated</code> in a <a>reifier</a> on a <a>triple</a>
2061+
that has <a>shape</a> <a>subject</a> and a <a>parameter</a> as <a>predicate</a>.
2062+
If <code>evalExpr(expr, <a>data graph</a>, <a>focus node</a>, {})</code> produces <code>true</code> as its only
2063+
<a>output node</a>, the constraints that use the <a>triple</a> are called <dfn data-lt="deactivated constraint">deactivated constraints</dfn>.
2064+
Deactivated constraints do not produce any validation results.
2065+
</p>
19782066
<p><em>The remainder of this section is informative.</em></p>
19792067
<p>
19802068
In SHACL Core, the only valid values for <code>sh:deactivated</code> are the
@@ -1995,7 +2083,7 @@ <h4>Deactivating a Shape</h4>
19952083
The following example illustrates the use of <code>sh:deactivated</code> to deactivate a shape.
19962084
In cases where shapes are imported from other graphs, the <code>sh:deactivated true</code> triple would be in the importing graph.
19972085
</p>
1998-
<aside class="example">
2086+
<aside class="example" title="Deactivating a property shape">
19992087
<div class="shapes-graph">
20002088
<div class="turtle">
20012089
ex:PersonShape
@@ -2056,6 +2144,28 @@ <h4>Deactivating a Shape</h4>
20562144
</div>
20572145
</div>
20582146
</aside>
2147+
<p>
2148+
The following variation uses reification to deactivate just the <code>sh:minCount</code>
2149+
constraint without affecting other constraints at the same property shape.
2150+
</p>
2151+
<aside class="example" title="Deactivating individual constraints using reification">
2152+
<div class="shapes-graph">
2153+
<div class="turtle">
2154+
ex:PersonShape
2155+
a sh:NodeShape ;
2156+
<span class="target-can-be-skipped">sh:targetClass ex:Person ;</span>
2157+
sh:property ex:PersonShape-name .
2158+
2159+
ex:PersonShape-name
2160+
a sh:PropertyShape ;
2161+
sh:path ex:name ;
2162+
sh:minCount 1 {| sh:deactivated true |} ;
2163+
sh:maxCount 1 .
2164+
</div>
2165+
<div class="jsonld">
2166+
</div>
2167+
</div>
2168+
</aside>
20592169
</section>
20602170
</section>
20612171

@@ -2905,6 +3015,7 @@ <h4>Message (sh:resultMessage)</h4>
29053015
While <code>sh:resultMessage</code> may have multiple values, there should not be two values with the same language tag.
29063016
These values are produced by a validation engine based on the values of <code>sh:message</code> of the constraints
29073017
in the shapes graph, see <a href="#message">Declaring Messages for a Shape</a>.
3018+
Messages declared using reification have precedence over those declared at the surrounding shape.
29083019
In cases where a constraint does not have any values for <code>sh:message</code> in the shapes graph the
29093020
SHACL processor MAY automatically generate other values for <code>sh:resultMessage</code>.
29103021
</p>
@@ -2913,9 +3024,13 @@ <h4>Message (sh:resultMessage)</h4>
29133024
<h4>Severity (sh:resultSeverity)</h4>
29143025
<p>
29153026
Each validation result has exactly one <a>value</a> for the property <code>sh:resultSeverity</code>, and this value is an <a>IRI</a>.
2916-
The value is equal to the <a>value</a> of <a href="#severity"><code>sh:severity</code></a> of the <a>shape</a> in the <a>shapes graph</a> that caused the result,
2917-
defaulting to <code>sh:Violation</code> if no <code>sh:severity</code> has been specified for the shape.
3027+
The value is determined by the following rules (in order):
29183028
</p>
3029+
<ol>
3030+
<li>the <a>value</a> of <a href="#severity"><code>sh:severity</code></a> at a <a>reifier</a> of any of the <a>triples</a> containing the <a>parameters</a> of the <a>constraint</a> that caused the result</li>
3031+
<li>the <a>value</a> of <a href="#severity"><code>sh:severity</code></a> of the <a>shape</a> in the <a>shapes graph</a> that caused the result</li>
3032+
<li>defaulting to <code>sh:Violation</code> if no <code>sh:severity</code> has been specified for the shape or constraint.</li>
3033+
</ol>
29193034
</section>
29203035
</section>
29213036
</section>
@@ -6754,6 +6869,7 @@ <h2>Changes between SHACL 1.0 Core and SHACL 1.2 Core</h2>
67546869
<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>
67556870
<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>
67566871
<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>
6872+
<li>Values for <a href="#deactivated"><code>sh:deactivated</code></a>, <a href="#message"><code>sh:message</code></a> and <a href="#severity"><code>sh:severity</code></a> can now be specified using RDF 1.2 reification, see <a href="https://github.com/w3c/data-shapes/issues/173">Issue 173</a></li>
67576873
</ul>
67586874
</section>
67596875
</body>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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:InvalidResource
12+
rdf:type rdfs:Resource ;
13+
.
14+
ex:TestShape
15+
rdf:type sh:NodeShape ;
16+
sh:datatype xsd:boolean {| sh:deactivated true |} ;
17+
sh:property ex:TestShape2 {| sh:deactivated true |} ;
18+
sh:targetNode ex:InvalidResource ;
19+
.
20+
ex:TestShape2
21+
rdf:type sh:PropertyShape ;
22+
sh:path ex:property ;
23+
sh:minCount 1 ;
24+
.
25+
<>
26+
rdf:type mf:Manifest ;
27+
mf:entries (
28+
<deactivated-003>
29+
) ;
30+
.
31+
<deactivated-003>
32+
rdf:type sht:Validate ;
33+
rdfs:label "Test of sh:deactivated 003" ;
34+
mf:action [
35+
sht:dataGraph <> ;
36+
sht:shapesGraph <> ;
37+
] ;
38+
mf:result [
39+
rdf:type sh:ValidationReport ;
40+
sh:conforms "true"^^xsd:boolean ;
41+
] ;
42+
mf:status sht:approved ;
43+
.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
rdfs:label "Tests converted from http://datashapes.org/sh/tests/tests/core/misc" ;
88
mf:include <deactivated-001.ttl> ;
99
mf:include <deactivated-002.ttl> ;
10+
mf:include <deactivated-003.ttl> ;
1011
mf:include <message-001.ttl> ;
12+
mf:include <message-002.ttl> ;
1113
mf:include <severity-001.ttl> ;
1214
mf:include <severity-002.ttl> ;
15+
mf:include <severity-003.ttl> ;
1316
.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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:TestShape
12+
rdf:type sh:NodeShape ;
13+
sh:datatype xsd:integer {| sh:message "Test message"@en |} ;
14+
sh:targetNode ex:InvalidNode ;
15+
.
16+
<>
17+
rdf:type mf:Manifest ;
18+
mf:entries (
19+
<message-002>
20+
) ;
21+
.
22+
<message-002>
23+
rdf:type sht:Validate ;
24+
rdfs:label "Test of custom sh:message 002" ;
25+
rdfs:comment """
26+
Note: This test verifies that the sh:message is copied into sh:resultMessage.
27+
To pass this test, the test harness needs to preserve all sh:resultMessage triples
28+
that are mentioned in the 'expected' results graph.""" ;
29+
mf:action [
30+
sht:dataGraph <> ;
31+
sht:shapesGraph <> ;
32+
] ;
33+
mf:result [
34+
rdf:type sh:ValidationReport ;
35+
sh:conforms "false"^^xsd:boolean ;
36+
sh:result [
37+
rdf:type sh:ValidationResult ;
38+
sh:focusNode ex:InvalidNode ;
39+
sh:resultMessage "Test message"@en ;
40+
sh:resultSeverity sh:Violation ;
41+
sh:sourceConstraintComponent sh:DatatypeConstraintComponent ;
42+
sh:sourceShape ex:TestShape ;
43+
sh:value ex:InvalidNode ;
44+
] ;
45+
] ;
46+
mf:status sht:approved ;
47+
.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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:TestShape
12+
rdf:type sh:NodeShape ;
13+
sh:datatype xsd:integer {| sh:severity sh:Warning |} ;
14+
sh:targetNode "Hello" ;
15+
.
16+
<>
17+
rdf:type mf:Manifest ;
18+
mf:entries (
19+
<severity-003>
20+
) ;
21+
.
22+
<severity-003>
23+
rdf:type sht:Validate ;
24+
rdfs:label "Test of sh:severity 003" ;
25+
mf:action [
26+
sht:dataGraph <> ;
27+
sht:shapesGraph <> ;
28+
] ;
29+
mf:result [
30+
rdf:type sh:ValidationReport ;
31+
sh:conforms "false"^^xsd:boolean ;
32+
sh:result [
33+
rdf:type sh:ValidationResult ;
34+
sh:focusNode "Hello" ;
35+
sh:resultSeverity sh:Warning ;
36+
sh:sourceConstraintComponent sh:DatatypeConstraintComponent ;
37+
sh:sourceShape ex:TestShape ;
38+
sh:value "Hello" ;
39+
] ;
40+
] ;
41+
mf:status sht:approved ;
42+
.

shacl12-vocabularies/shacl.ttl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ sh:message
116116
sh:severity
117117
a rdf:Property ;
118118
rdfs:label "severity"@en ;
119-
rdfs:comment "Defines the severity that validation results produced by a shape must have. Defaults to sh:Violation."@en ;
120-
rdfs:domain sh:Shape ;
119+
rdfs:comment "Defines the severity that validation results produced by a shape or constraint must have. Defaults to sh:Violation."@en ;
121120
rdfs:range sh:Severity ;
122121
rdfs:isDefinedBy sh: .
123122

0 commit comments

Comments
 (0)