zazuko/rdf-validate-shacl

`sh:closed` with `sh:alternativePath`

sroze opened this issue · 4 comments

sroze commented

What's the issue?
When using a closed shape and properties with an alternative path, I always get a violation because the predicate is not allowed.

What's expected?
I am expecting predicates schema:ROLE_CAREGIVER to not be violations of the closed shape.

Example SHACL

schema:User a rdfs:Class, sh:NodeShape;
    sh:closed true;
    sh:property [ sh:path rdf:type; sh:hasValue schema:User ];
    sh:property [
      sh:path [ sh:alternativePath ( schema:ROLE_CAREGIVER schema:ROLE_CAREMANAGER ) ];
      sh:node schema:CareRecipient
    ];
.

Playground example
https://s.zazuko.com/JrT3P


Is that a real bug or am I misunderstanding SHACL? Either way, would you have any direction as to which part of the code should I change and PR or how might I be able to tackle this (without redeclaring each property one by one, hopefully)? Thank you!

It appears to behave the same in the original playground, which could mean it's by-design (cc @HolgerKnublauch)

As a workaround, you can add sh:ignoredProperties to your shape

sh:ignoredProperties ( schema:ROLE_CAREGIVER schema:ROLE_CAREMANAGER ) ;

Yes this is by design. sh:closed is really simplistic and only looks at the named properties that are the values of sh:path of the directly associated property shapes. See https://www.w3.org/TR/shacl/#ClosedConstraintComponent (which is very brief, like many specifications are). Path expressions are not evaluated.

There are other limitations of sh:closed, which is why we have added http://datashapes.org/constraints.html#ClosedByTypesConstraintComponent using SHACL-SPARQL.

sroze commented

As a workaround, you can add sh:ignoredProperties to your shape

@tpluscode this would mean that the sh:node wouldn't be validated though if I understand correctly.

There are other limitations of sh:closed, which is why we have added http://datashapes.org/constraints.html#ClosedByTypesConstraintComponent using SHACL-SPARQL.

@HolgerKnublauch Oh interesting, I didn't know. My understanding is that this isn't supported by this validator though but great to know!

@tpluscode this would mean that the sh:node wouldn't be validated though if I understand correctly.

Wasn't sure, but apparently it will: https://s.zazuko.com/25pXUe :)