w3c / data-shapes

RDF Data Shapes WG repo
87 stars 33 forks source link

Inconsistency regarding `sh:or` #152

Closed wouterbeek closed 5 months ago

wouterbeek commented 5 months ago

Observed

The SHACL standard contains the following example (Section 4.6.3) that is inconsistent with the rest of the standard:

ex:PersonAddressShape
    a sh:NodeShape ;
    sh:targetClass ex:Person ;
    sh:property [
        sh:path ex:address ;
        sh:or (
            [
                sh:datatype xsd:string ;
            ]
            [
                sh:class ex:Address ;
            ]
        )
    ] .

This example allows us to derive a contraction, by following this line of reasoning:

  1. For sh:or, the SHACL standard states: "A SHACL list of shapes to validate the value nodes against. Each value of sh:or in a shape is a SHACL list. Each member of such list must be a well-formed shape." (Section 4.6.3).
  2. The list members in the example are property shapes, e.g. they contain sh:datatype and sh:class assertions.
  3. Per (1) and (2), the list members in the example are required to be well-formed property shapes.
  4. The standard states that: "A property shape is a shape in the shapes graph that is the subject of a triple that has sh:path as its predicate." (Section 2.3)
  5. Since the list members in the example do not have a sh:path assertion, they cannot be property shapes.
  6. Contradiction from (3) and (5).

Expected

The example to be consistent with the rest of the standard.

HolgerKnublauch commented 5 months ago

Hi Wouter,

your statement 2. above is not correct. They are node shapes, and node shapes can also have sh:datatype and sh:class constraints. Where do you see evidence that they need to be property shapes for that?

wouterbeek commented 5 months ago

Thanks for looking into this @HolgerKnublauch !

I ran into issues when I wrote [ sh:minCount 1] instead of [ sh:datatype xsd:string ]. From a user perspective, "may not occur more than once" is a constraint on a property, similar to "may not have values that are not XSD strings".

For some reason, [ sh:minCount 1 ] was not allowed by the SHACL engine that was using, but [ sh:datatype xsd:string ] was allowed.

Do you know whether there is a different between sh:minCount and sh:maxCount on the one hand, and sh:class and sh:datatype on the other hand? Is this differences somewhere in the standard? Intuitively, I thought of these are similar property / usable in the same contexts.

HolgerKnublauch commented 5 months ago

sh:min/maxCount certainly don't make sense with node shapes, only property shapes. The number of value nodes for a node shape is always 1, so anything except 1 would cause a violation. Maybe some engines even outright reject those use cases, but they shouldn't really.

wouterbeek commented 5 months ago

Thanks for the feedback! I do not understand the use of sh:or then, but this is due to a lack of knowledge on my side. I'm closing this issue now, and my try to learn more on the use of sh:or later.