RDFLib / pySHACL

A Python validator for SHACL
Apache License 2.0
241 stars 63 forks source link

`sh:severity` on shapes linked by `sh:node` #222

Closed ajnelson-nist closed 3 months ago

ajnelson-nist commented 4 months ago

I have a question that I suspect will be quick to confirm.

If I have a node shape that links another node shape with sh:node; the linking shape has no severity specified (so defaulting to sh:Violation); and the linked shape has a severity specified; should the linking node shape produce a validation result when the linked node shape does?

For example, given this ontology+data graph:

@prefix ex: <http://example.org/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:Class-A 
    a owl:Class ;
    .

ex:Class-B
    a owl:Class ;
    .

ex:Class-AB
    a owl:Class ;
    rdfs:subClassOf
        ex:Class-A ,
        ex:Class-B
        ;
    .

ex:Thing-1
    a ex:Class-A ;
    .

ex:Thing-2
    a ex:Class-B ;
    .

ex:Thing-3
    a
        ex:Class-A ,
        ex:Class-B
        ;
    .

ex:Thing-4
    a ex:Class-AB ;
    .

and given this shapes graph:

@prefix ex: <http://example.org/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:Bs-shape
    a sh:NodeShape ;
    sh:node ex:BsShouldBeAs-shape ;
    sh:targetClass ex:Class-B ;
    .

ex:BsShouldBeAs-shape
    a sh:NodeShape ;
    sh:class ex:Class-A ;
    sh:message "B things should also be A things."@en ;
    sh:severity sh:Info ;
    .

My naïve expectation yesterday was sh:node would behave like sh:property - i.e., if the linked property shape triggered a violation, the entire node shape wouldn't fail, and the only result that came back would have severity as specified in the property shape. So from the above ontology+data graph, I expected only a sh:Info result pertaining to ex:Thing-2.

My expectations ran into this result instead:

@prefix ex: <http://example.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

[] a sh:ValidationReport ;
    sh:conforms false ;
    sh:result [ a sh:ValidationResult ;
            sh:detail [ a sh:ValidationResult ;
                    sh:focusNode ex:Thing-2 ;
                    sh:resultMessage "B things should also be A things."@en ;
                    sh:resultSeverity sh:Info ;
                    sh:sourceConstraintComponent sh:ClassConstraintComponent ;
                    sh:sourceShape ex:BsShouldBeAs-shape ;
                    sh:value ex:Thing-2 ] ;
            sh:focusNode ex:Thing-2 ;
            sh:resultMessage "Value does not conform to Shape ex:BsShouldBeAs-shape. See details for more information." ;
            sh:resultSeverity sh:Violation ;
            sh:sourceConstraintComponent sh:NodeConstraintComponent ;
            sh:sourceShape ex:Bs-shape ;
            sh:value ex:Thing-2 ] .

On a fresh re-read, this seems consistent with the sh:node specification section.

If this does indeed seem consistent with the spec, please feel free to close this issue as resolved, no other action needed.

ashleysommer commented 3 months ago

Hi @ajnelson-nist Sorry I thought I already responded to this one.

You're right, this is intentional and it is consistent with the sh:node specification. It seems like the spec deliberately has different behaviour for sh:node than sh:property.

ajnelson-nist commented 3 months ago

Thank you for confirming.