zazuko / rdf-validate-shacl

Validate RDF data purely in JavaScript. An implementation of the W3C SHACL specification on top of the RDFJS stack.
MIT License
98 stars 13 forks source link

sh:hasValue does not work inside sh:or #70

Closed wouterbeek closed 3 years ago

wouterbeek commented 3 years ago

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:

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.
martinmaillard commented 3 years ago

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.

martinmaillard commented 3 years ago

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.

thomasdegroot18 commented 3 years ago

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:

wouterbeek commented 3 years ago

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.