w3c / shacl

SHACL Community Group (Post-REC activitities)
32 stars 5 forks source link

Support sh:message, sh:severity and sh:deactivated per constraint triple #27

Open HolgerKnublauch opened 9 months ago

HolgerKnublauch commented 9 months ago

RDF 1.2 will provide some syntax for attaching statements to other statements.

Currently, sh:message and sh:severity need to be placed in shapes. But shapes can contain multiple constraint triples, and not all of them should receive the same message and severity.

For example

ex:MyClass-myProperty
    a sh:PropertyShape ;
    sh:path ex:myProperty ;
    sh:maxCount 1 .

ex:MyClass-myProperty-minCount
    a sh:PropertyShape ;
    sh:path ex:myProperty ;
    sh:minCount 1 ;
    sh:severity sh:Warning ;
    sh:message "There SHOULD be at least one value here" .

It should become possible to use RDF 1.2 reification or quoted triples to do something like this

ex:MyClass-myProperty
    a sh:PropertyShape ;
    sh:path ex:myProperty ;
    sh:maxCount 1 ;
    sh:minCount 1 {| 
        sh:severity sh:Warning ;
        sh:message "There SHOULD be at least one value here" ;
    |} .

This would avoid having to introduce artificial shapes just to encapsulate warning or severity.

We have implemented this in TopBraid for several years now and didn't run into complaints from users.

The same mechanism would also be great for sh:deactivated (we didn't implement that yet).

bertvannuffelen commented 1 month ago

I personally am not sure if this can be allowed. Semantically this becomes a very tricky issue.

What is the meaning of

ex:MyClass-myProperty
    a sh:PropertyShape ;
    sh:path ex:myProperty ;
    sh:maxCount 1 ;
    sh:minCount 1 {| 
        sh:severity sh:Warning ;
        sh:message "There SHOULD be at least one value here" ;
    |} ; 
   sh:message "This a global error message" ;
   sh:severity sh:Violation.

but also why cannot I write it as follows

ex:MyClass-myProperty
    a sh:PropertyShape ;
    sh:path ex:myProperty {| 
        sh:minCount 1 ;
        sh:severity sh:Warning ;
        sh:message "There SHOULD be at least one value here" ;
    |} ; 
    sh:path ex:myProperty {| 
        sh:maxCount 1 ; 
        sh:message "another value" ;
    |} ; 
   sh:message "This a global error message" ;
   sh:severity sh:Violation.

where is the limit of using RDF 1.2 reification? Can it be applied to any property in the shape and how much nesting of this is allowed?

The semantics of sh:message is the "message associated with the Shape" (see diagram https://w3c.github.io/shacl/shacl-core/#constraints-section) not the "message associated with a RDF statement in a shape. That is a big difference.

Moreover, reification is limited to simple cases: otherwise this is ambiguous. In the next example sh:or has switched arguments. I assume that RDF 1.2. triple reification will be done on syntactic equivalence and not on semantic equivalence, and therefore RDF 1.2 reification cannot ensure equality here.

ex:MyClass1-myProperty
    a sh:PropertyShape ;
    sh:or (
        [
            sh:path ex:firstName ;
            sh:minCount 1 ;
        ]
        [
            sh:path ex:givenName ;
            sh:minCount 1 ;
        ]
    )  {|
        sh:severity sh:Warning ;
        sh:message "There SHOULD be at least one value here" ;
    |} .

ex:MyClass2-myProperty
    a sh:PropertyShape ;
    sh:or (
        [
            sh:path ex:givenName ;
            sh:minCount 1 ;
        ]
        [

                        sh:path ex:firstName ;
            sh:minCount 1 ;
        ]
    ) . {|
        sh:severity sh:Warning ;
        sh:message "There SHOULD be at least one value here" ;
    |} .
HolgerKnublauch commented 1 month ago

To your first question, if there is a reification on a constraint then this takes precedence over the values attached to the surrounding shape.

The second question, allowing reification at sh:path, doesn't look good to me as it would go too far.

On your reference to the spec, this would of course need to be updated in the 1.2 document as the 1.0 spec was written before RDF star was on a W3C process.

I agree that cases like sh:or are less pretty, if only for the rdf:List syntax. But those details can be worked out, e.g. by limiting this syntax to the simple cases such as sh:minCount.