Skip to content

Commit

Permalink
Suggested clean up for ISSUE-70, using sh:defaultValueType to drive l…
Browse files Browse the repository at this point in the history
…ight-weight inferencing
  • Loading branch information
HolgerKnublauch committed Aug 24, 2015
1 parent da1819e commit 310d85f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 35 deletions.
32 changes: 31 additions & 1 deletion shacl/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>Shapes Constraint Language (SHACL)</title>
<meta charset="utf-8">
<script src="http://www.w3.org/Tools/respec/respec-w3c-common" async class="remove"></script>
<script src="//www.w3.org/Tools/respec/respec-w3c-common" async class="remove"></script>
<script class="remove">
var respecConfig = {
edDraftURI: "http://w3c.github.io/data-shapes/shacl/",
Expand Down Expand Up @@ -140,6 +140,7 @@ <h4>Revision History</h4>
The detailed list of changes and their diffs can be found in the <a href="https://github.com/w3c/data-shapes/commits/gh-pages/shacl/index.html">Git repository</a>.
</p>
<ul>
<li><b>2015-08-24</b>: Added section on sh:defaultValueType (<a href="http://www.w3.org/2014/data-shapes/track/issues/70">ISSUE-70</a>)</li>
<li><b>2015-08-21</b>: Added support for validation functions (<a href="http://www.w3.org/2014/data-shapes/track/issues/79">ISSUE-79</a>)</li>
<li><b>2015-08-14</b>:
Added qualified cardinality restrictions (<a href="http://www.w3.org/2014/data-shapes/track/issues/72">ISSUE-72</a>),
Expand Down Expand Up @@ -2566,6 +2567,35 @@ <h3>executeFunction</h3>
</table>
</section>
</section>
<section id="defaultValueType">
<h2>Validation of shapes graphs and the sh:defaultValueType property</h2>
<div class="issue" data-number="70" title="Special treatment of blank node types">
This paragraph is one possible resolution to ISSUE-70.
The proposal has not been discussed in the WG yet.
</div>
<p>
The SHACL system vocabulary itself is using shapes, allowing SHACL constraint validation to be executed on shapes graphs, e.g. to validate the syntax of shape definitions.
However, some system properties such as <code>sh:property</code>, <code>sh:filterShape</code> and <code>sh:argument</code> may have untyped blank nodes as their values.
If, for example, a value of <code>sh:property</code> is a blank node that does not have any <code>rdf:type</code>, then the assumption is that the blank node has type <code>sh:PropertyConstraint</code>.
Unless these implicit triples are present in the query graph, constraint validation will not apply the constraints defined for <code>sh:PropertyConstraint</code>.
</p>
<p>
If an engine intends to validate the syntax of a SHACL shapes graph itself, it should (temporarily) add the missing <code>rdf:type</code> triples.
The SHACL system vocabulary includes some helper triples using the predicate <code>sh:defaultValueType</code> to specify the default <code>rdf:type</code> for certain properties.
For example, the default value type of <code>sh:property</code> is <code>sh:PropertyConstraint</code>.
These triples can be queried by a pre-processor to construct the missing type triples for the affected blank nodes.
SHACL includes a template <code>sh:DefaultValueTypeRule</code> which encapsulates a SPARQL query that can be used for that purpose:
</p>
<pre class="query">
CONSTRUCT {
?blankNode a ?defaultValueType .
}
WHERE {
?predicate sh:defaultValueType ?defaultValueType .
?anySubject ?predicate ?blankNode .
FILTER (isBlank(?blankNode) &amp;&amp; NOT EXISTS { ?blankNode a ?anyType }) .
}</pre>
</section>
</section>

<section id="functions">
Expand Down
73 changes: 39 additions & 34 deletions shacl/shacl.shacl.ttl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# baseURI: http://www.w3.org/ns/shacl

# SHACL - Shapes Constraint Language
# Draft last edited on 2015-08-21
# Draft last edited on 2015-08-24
# Created by the W3C RDF Data Shapes Working Group
# Editor: Holger Knublauch <holger@topquadrant.com>

Expand Down Expand Up @@ -33,35 +33,30 @@ sh:Shape
sh:property [
sh:predicate sh:constraint ;
sh:valueClass sh:Constraint ;
sh:defaultValueType sh:NativeConstraint ; # NativeConstraint bnodes do not require rdf:type
rdfs:label "constraint" ;
rdfs:comment "Defines arbitrary constraints on the matching resources. Use sh:property for structural property declarations." ;
] ;
sh:property [
sh:predicate sh:property ;
sh:valueClass sh:PropertyConstraint ;
sh:defaultValueType sh:PropertyConstraint ; # PropertyConstraint bnodes do not require rdf:type
rdfs:label "property" ;
rdfs:comment "Declares that a given property is relevant for matching resources." ;
] ;
sh:property [
sh:predicate sh:inverseProperty ;
sh:valueClass sh:InversePropertyConstraint ;
sh:defaultValueType sh:InversePropertyConstraint ; # InversePropertyConstraint bnodes do not require rdf:type
rdfs:label "inverse property" ;
rdfs:comment "Declares that a given incoming reference property is relevant for matching resources." ;
] ;
sh:property [
sh:predicate sh:filterShape ;
sh:valueClass sh:Shape ;
sh:defaultValueType sh:Shape ;
rdfs:label "filter shape" ;
rdfs:comment "Links a Shape to other Shapes that the tested nodes need to fulfill before the constraints of the shape are evaluated." ;
] ;
sh:property [
sh:predicate sh:scope ;
sh:valueClass sh:Scope ;
sh:defaultValueType sh:NativeScope ;
rdfs:label "scope" ;
rdfs:comment "Links a Shape to Scopes that produce the focus nodes that the shape applies to." ;
] ;
Expand Down Expand Up @@ -116,6 +111,13 @@ rdfs:Literal
rdfs:comment "The class of literal values, eg. textual strings and integers." ;
.

rdf:List
a rdfs:Class ;
rdfs:subClassOf rdfs:Resource ;
rdfs:label "List" ;
rdfs:comment "The class of RDF Lists." ;
.

rdf:Property
a rdfs:Class ;
rdfs:subClassOf rdfs:Resource ;
Expand Down Expand Up @@ -205,14 +207,13 @@ sh:Literal

sh:Macro
a sh:ShapeClass ;
rdfs:subClassOf rdfs:Class ;
rdfs:subClassOf sh:ShapeClass ;
rdfs:label "Macro" ;
rdfs:comment "Abstract superclass of macro components of a SHACL library, especially Functions and Templates. Macros can take arguments, which are constraints that are different from PropertyConstraints in that they can only have at most one value." ;
sh:abstract true;
sh:property [
sh:predicate sh:argument ;
sh:valueClass sh:Argument ;
sh:defaultValueType sh:Argument ; # Arguments do not require rdf:type
rdfs:label "argument" ;
rdfs:comment "Declares the argument(s) of this macro." ;
] ;
Expand Down Expand Up @@ -567,7 +568,6 @@ sh:Constraint
sh:property [
sh:predicate sh:filterShape ;
sh:valueClass sh:Shape ;
sh:defaultValueType sh:Shape ;
rdfs:label "filter shape" ;
rdfs:comment "Links a constraint to Shapes that the tested nodes need to fulfill before the constraint is evaluated." ;
] ;
Expand Down Expand Up @@ -977,7 +977,7 @@ sh:AbstractQualifiedValueShapePropertyConstraint
sh:predicate sh:qualifiedValueShape ;
sh:optionalWhenInherited true ;
sh:valueClass sh:Shape ;
rdfs:label "qualifier value shape" ;
rdfs:label "qualified value shape" ;
rdfs:comment "The shape that the values must have." ;
] ;
sh:argument [
Expand Down Expand Up @@ -1012,14 +1012,6 @@ sh:AbstractValueClassPropertyConstraint
rdfs:label "Abstract value class property constraint" ;
rdfs:comment "Enforces a constraint that all values of the property must be of a certain type. For resources this will accept instances of subclasses. Untyped blank nodes are allowed if a defaultValueType has been specified." ;
sh:abstract true ;
sh:argument [
# TODO: Maybe this is not needed and we just hard-code the three use cases of this property into the SPARQL query below
sh:predicate sh:defaultValueType ;
sh:optional true ;
sh:valueClass rdfs:Class ;
rdfs:label "default value shape" ;
rdfs:comment "If specified then blank nodes that have no rdf:type pass this constraint. The type of those resources is assumed to be ?defaultValueType." ;
] ;
sh:argument [
sh:predicate sh:valueClass ;
sh:optionalWhenInherited true ;
Expand Down Expand Up @@ -1354,7 +1346,6 @@ sh:NotConstraint
sh:argument [
sh:predicate sh:shape ;
sh:valueClass sh:Shape ;
sh:defaultValueType sh:Shape ;
rdfs:label "shape" ;
rdfs:comment "The shape to negate." ;
] ;
Expand Down Expand Up @@ -1652,15 +1643,6 @@ sh:hasValueClass
sh:valueClass rdfs:Class ;
rdfs:comment "The type that the node must have." ;
] ;
sh:argument [
# TODO: Maybe this is not needed and we just hard-code the three use cases of this property into the SPARQL query below
sh:index 2 ;
sh:predicate sh:defaultValueType ;
sh:optional true ;
sh:valueClass rdfs:Class ;
rdfs:label "default value shape" ;
rdfs:comment "If specified then blank nodes that have no rdf:type pass this constraint. The type of those resources is assumed to be ?defaultValueType." ;
] ;
sh:returnType xsd:boolean ;
sh:sparql """
ASK {
Expand All @@ -1681,11 +1663,6 @@ sh:hasValueClass
# Allow untyped blank nodes with rdf:first if expected type is rdf:List
FILTER (?valueClass = rdf:List && isBlank(?value) && EXISTS { ?value rdf:first ?any }) .
}
UNION
{
# Allow untyped blank nodes if ?defaultValueType is bound
FILTER (isBlank(?value) && bound(?defaultValueType) && NOT EXISTS { ?value a ?anyType }) .
}
}
""" ;
.
Expand Down Expand Up @@ -1899,7 +1876,35 @@ sh:walkShapesList
.


# System Property declarations (mainly for RDF compliance) --------------------
# Declarations of sh:defaultValueType -----------------------------------------

sh:argument sh:defaultValueType sh:Argument .
sh:constraint sh:defaultValueType sh:NativeConstraint .
sh:filterShape sh:defaultValueType sh:Shape .
sh:inverseProperty sh:defaultValueType sh:InversePropertyConstraint .
sh:property sh:defaultValueType sh:PropertyConstraint .
sh:qualifiedValueShape sh:defaultValueType sh:Shape .
sh:scope sh:defaultValueType sh:NativeScope .
sh:shape sh:defaultValueType sh:Shape .
sh:valueShape sh:defaultValueType sh:Shape .

sh:DefaultValueTypeRule
a sh:Template ;
rdfs:label "default value type inference rule" ;
rdfs:comment "A template encapsulating a query that can be used to construct rdf:type triples for certain untyped blank nodes that are an object in a triple where the predicate has a sh:defaultValueType. This can be used as a pre-processor for shape graphs before they are validated." ;
sh:sparql """
CONSTRUCT {
?blankNode a ?defaultValueType .
}
WHERE {
?predicate sh:defaultValueType ?defaultValueType .
?anySubject ?predicate ?blankNode .
FILTER (isBlank(?blankNode) && NOT EXISTS { ?blankNode a ?anyType }) .
}
""" ;
.

# System Property declarations ------------------------------------------------

# sh:nodeShape could alternatively be attached via sh:property to rdfs:Resource,
# if validation is required. However this would make it show up on all forms etc,
Expand Down

0 comments on commit 310d85f

Please sign in to comment.