shapes-ISSUE-95 (Template Simplifications): Proposed simplification and clean up of template mechanism [SHACL Spec]

shapes-ISSUE-95 (Template Simplifications): Proposed simplification and clean up of template mechanism [SHACL Spec]

Raised by: Holger Knublauch
On product: SHACL Spec

Based on recent discussions (e.g. about the unification of property constraints with node constraints, and the many AbstractXY classes in the Turtle file), I have carefully revised the template mechanism, leading to a cleaner and much more compact design.

I have described them on a branch of the spec [1] and this diff gives some impression of the changes [2].

In a nutshell, I am proposing two changes. Sorry they are very technical and may not be of interest to everyone here:

1) Cleaner template injection mechanism, instead of inheritance (see corresponding section in the Templates section).

In the previous version, if multiple templates were merged into one (such as sh:PropertyConstraint), then they would use rdfs:subClassOf.  In the new design I am using sh:scopeClass for that purpose, because this more cleanly separates argument inheritance from SPARQL body inheritance.

2) Replaced sh:validationFunction with sh:NodeValidationFunction, and allowing these functions to directly inject themselves into other templates such as sh:PropertyConstraint.

In the previous version, each validation function still needed to be backed by a separate template, even though this template was almost trivial and had basically the same arguments all over again.  In the new design, it is sufficient to declare the validation function and give it sh:scopeClass sh:PropertyConstraint.

The net result of these changes is that I was able to drop the vast majority of AbstractXY classes, and the same function code is reused for sh:property, sh:inverseProperty, sh:argument and (if approved) sh:constraint. I am pasting an example node validation function below - this is all that it takes to inject a new property into sh:property:

 a sh:NodeValidationFunction ;
 sh:scopeClass sh:PropertyConstraint ;
 sh:argument [
  sh:predicate ex:lang ;
  sh:datatype xsd:string ;
  rdfs:label "language" ;
  rdfs:comment "The language to match against, e.g. \"de\"." ;
 ] ;
 sh:sparql """
    ASK {
     FILTER (isLiteral($node) && langMatches(lang($node), $lang)) .
  """ .

which can then be used as a new property ex:lang as in

 a sh:Shape ;
 sh:scopeClass ex:Country ;
 sh:property [
  sh:predicate ex:germanLabel ;
  sh:maxCount 1 ;
  ex:lang "de" ;
 ] ; ...

I hope this proposed simplification is in everyone's best interest.


Received on Tuesday, 29 September 2015 00:55:43 UTC