sh:hasValue does not work inside sh:or
wouterbeek opened this issue ยท 4 comments
When I specify sh:hasValue
inside an sh:or
, I have correct data that does not validate.
The following Turtle snippet should validate successfully, but currently results in a violation. My reasoning is as follows:
id:a
has valueid:b
for propertydef:p
, sosh:hasValue id:b
should be satisfied forid:a
, sosh:or ( [ sh:hasValue id:b ] [ sh:hasValue id:c ] )
should be satisfied forid:a
.
prefix sh: <http://www.w3.org/ns/shacl#>
prefix def: <https://triplydb.com/Triply/sh/def/>
prefix id: <https://triplydb.com/Triply/sh/id/>
prefix shp: <https://triplydb.com/Triply/sh/model/shp/>
shp:A
sh:property shp:A_p;
sh:targetClass def:A.
shp:A_p
sh:or
( [ sh:hasValue id:b ]
[ sh:hasValue id:c ] );
sh:path def:p.
id:a
a def:A;
def:p id:b, id:d.
The following seems to work:
shp:A
sh:or
( [ sh:path def:p; sh:hasValue id:b ]
[ sh:path def:p; sh:hasValue id:c ] );
sh:targetClass def:A.
I need to investigate to understand why your example doesn't work.
I think I understand.
Your shape says each def:p
property must have either value id:b
or id:c
. Your instance id:a
doesn't conform because it has def:p id:d
, which doesn't conform to this definition.
As I understand it, is that the blankNodes in the sh:or
are of type sh:NodeShape
and not of type sh:propertyShape
source: (https://www.w3.org/TR/shacl/#dfn-node-shape). This changes the validation, as we are no longer validating the values in the context of the property def:p. But we are now validating the individual value nodes id:b
and id:d
for the sh:hasValue
. For node shapes the value nodes are also the individual focus nodes, forming a set with exactly one member (source: https://www.w3.org/TR/shacl/#dfn-value-nodes ). This would return a sh:Violation
as id:d
does neither match sh:hasValue id:b
or sh:hasValue id:c
. So this results in the violation.
Set out in bulletpoints the reasoning for it IMO should be as follows:
id:a
is targeted by nodeShapeshp:A_p
id:a
has propertydef:p
with valueid:b
andid:d
, so when we focus on nodeid:d
sh:hasValue id:b
would not be satisfied forid:d
, andsh:hasValue id:c
would not be satisfied forid:d
, sosh:or ( [ sh:hasValue id:b ] [ sh:hasValue id:c ] )
should not be satisfied forid:d
.
Thank you @martinmaillard and @thomasdegroot18 !
Especially the following sentence from the standard should be taken to heart:
A node shape is a shape in the shapes graph that is not the subject of a triple with sh:path as its predicate.
When an issue occurs we must first ask ourselves the question whether there is an explicit sh:path
. If this is not the case then we have a node shape and not a property shape. And then work from there.