TopQuadrant / shacl

SHACL API in Java based on Apache Jena
Apache License 2.0
215 stars 61 forks source link

Different validation results in EU engine vs. CLI #147

Closed rmfranken closed 1 year ago

rmfranken commented 1 year ago

Hi!

I've been a happy user of the SHACL CLI for some time now, but I have a small curious question. If I use the following shapes in the CLI (version 1.4.2):

Shapesfile:

:myshape a sh:NodeShape;
sh:property [sh:path :myprop ;
                    sh:class :mypropclass ;] ;
sh:targetClass :something.

:somevalueclass a :mypropclass.

Instance Data file("the file to be validated") :

:mything a :something ;
:myprop :somevalueclass.

I will get a result:

[ rdf:type     sh:ValidationReport ;
  sh:conforms  false ;
  sh:result    [ rdf:type                      sh:ValidationResult ;
                 sh:focusNode                  :mything ;
                 sh:resultMessage              "Value must be an instance of :mypropclass" ;
                 sh:resultPath                 :myprop ;
                 sh:resultSeverity             sh:Violation ;
                 sh:sourceConstraintComponent  sh:ClassConstraintComponent ;
                 sh:sourceShape                []  ;
                 sh:value                      :somevalueclass

This in itsself makes sense to me: The instance data graph did not contain the triple which states that :somevalueclass is an instance of :mypropclass. This triple was only found in the shapesfile.

However, uploading the same 2 files in the european shacl validator (https://www.itb.ec.europa.eu/shacl/any/upload), which I understand to be using the same SHACL engine, I don't get this result. It's almost as if the instance data file and the shapes file are merged, and only then validated against the shapes file. (this also happens to be how I solve this problem in the SHACL CLI, I just copy and paste my ontology under my instance data triples).

The reason this matters is because domain values/enumeration values are often captured in the ontology, so you can have "instance data" in your ontology, and by extension, shapes file.

Where lies the difference/inconsistency? And which one should be considered the truth? Is this a feature or a bug? :)

Kind regards, Robin

HolgerKnublauch commented 1 year ago

Hi Robin, this depends on what the europa validator does. Quite possibly it automatically adds the shapes graph into the data graph for validation purposes, as this is usually a good heuristics. If you don't think the europa tool should do that, maybe contact them. If you want the same behaviour using the TopBraid SHACL API, you can control which graphs are sent to the validation engine using Java code.

rmfranken commented 1 year ago

Hi Holger, Thanks for the quick response. I see, I guess it's not a bug then at least :) I know enough for now, thank you! I'll close this issue!