SHACL problems when using sh:Warning

I am trying to use sh:severity sh:Warning to add warnings to the SHACL validation report. I noticed unexpected behaviour when a sh:Warning occurs within a node shape used by another node shape. For example if I use :AuthorNodeShape with a :PersonShape that uses sh:Warning, then the :AuthorNodeShape is reported having a sh:Violation (sh:resultMessage “Value does not have shape http://example.com/books/PersonShape“) instead of the sh:Warning.

I would expect a sh:Warning to be shown in the report for the Author.

This makes using sh:Warnings practically useless because all my data graphs fail even when there should only be warnings. Is there a way around this ?

You can reproduce this on https://shacl.org/playground/

Shape graph

@prefix : <http://example.com/books/> .
@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#> .

:AuthorNodeShape
     a sh:NodeShape ;
     sh:targetClass :Author ;
     sh:node :PersonShape .
:PersonShape
     a sh:NodeShape ;
     sh:description "Super shape for all things that are Persons"@en ;
     sh:targetClass :Person ;
     sh:property [ 
        sh:path :name ;
        sh:severity sh:Warning ;
        sh:minCount 1 ;
     ]  .

Data Graph (with missing author name should result in sh:Warnings).

@prefix : <http://example.com/books/> .
@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#> .

:Author rdfs:subClassOf :Person .
:JRRTolkien
    a :Author ;
    :born "1892-01-03"^^xsd:date .

Report

 [
 	a sh:ValidationResult ;
 	sh:resultSeverity sh:Violation ;
 	sh:sourceConstraintComponent sh:NodeConstraintComponent ;
 	sh:sourceShape <http://example.com/books/AuthorNodeShape> ;
 	sh:focusNode <http://example.com/books/JRRTolkien> ;
 	sh:value <http://example.com/books/JRRTolkien> ;
 	sh:resultMessage "Value does not have shape <http://example.com/books/PersonShape>" ;
  ] .
3 Likes

It seems like the implementation at SHACL Playground add a ValidationResult for all NodeShapes that the constraint touches into. I guess this differ from implementation to implementation.

Since your AuthorNodeShape does not contain a constraint on severity, the severity level of this node shape is set to sh:Violation by default. This overrules the severity level in the parent node shape.

I tried adding a dummy-class:

:B
 a sh:NodeShape ;
 sh:targetClass :B;
 sh:node :AuthorNodeShape .

And updated :JRRTolkien to be an instance of :B. This gave me 3 validation results, with two violations and one warning in SHACL Playground. Two NodeConstraintComponents with violation, and one MinCountConstraintComponent with warning.

Running the same example through RDF4J’s SHACL engine gave one validation result, MinCountConstraintComponent. However, this engine has no support for severity levels, so everything is a violation. (My point being the number of validation results for this check.)

Changing severity level to sh:Info or sh:Warning does not elimiate validation results where the instance data is breaking the constraint. It can be seen as a tool for categorizing validation results.

2 Likes

Thanks for looking into this. I really appreciate it. Your workshop has really inspired me to dive deep into SHACL and I am already using it on a project :slight_smile:

I found a reasonable workaround to my problem, which is to move the sh:minCount 1 contraint from the :PersonShape back into to the :AuthorNodeShape and this gives me the expected result of a sh:Warning on my :AuthorNodeShape.

Using the same data as above with this Shape Graph gives the expected result.

@prefix : <http://example.com/books/> .
@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#> .

:AuthorNodeShape
     a sh:NodeShape ;
     sh:targetClass :Author ;
     sh:property [ 
        sh:path :name ;
        sh:severity sh:Warning ;
        sh:minCount 1 ;
     ]  ;
     sh:node :PersonShape .

:PersonShape
     a sh:NodeShape ;
     sh:description "Super shape for all things that are Persons"@en ;
     sh:targetClass :Person ;
     sh:property [ 
        sh:path :name ;
        sh:minCount 0 ;
     ]  .

Report

[
	a sh:ValidationResult ;
	sh:resultSeverity sh:Warning ;
	sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
	sh:sourceShape _:n1134 ;
	sh:focusNode <http://example.com/books/JRRTolkien> ;
	sh:resultPath <http://example.com/books/name> ;
	sh:resultMessage "Less than 1 values" ;
] .
3 Likes