TopQuadrant / shacl

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

Unexpected ClosedConstraintComponent Violation on valid property when using sh:or/sh:xor? #110

Closed sfontanel closed 3 years ago

sfontanel commented 3 years ago

I apologize in advance if I got something wrong in my examples but i am a shacl newbie :) . In my java project I'm using the library org.topbraid.shacl/1.3.2.

In my example I need to apply the following validation rules:

However it seems that when we introduce the sh: xor, the ex:birthPlace it is not recognized as a valid property for that target class

[ a sh:ValidationReport ; sh:conforms false ; sh:result [ a sh:ValidationResult ; sh:focusNode ex:Alice ; sh:resultMessage "Predicate ex:birthPlace is not allowed (closed shape)" ; sh:resultPath ex:birthPlace ; sh:resultSeverity sh:Violation ; sh:sourceConstraintComponent sh:ClosedConstraintComponent ; sh:sourceShape ex:OrConstraintExampleShape ; sh:value ex:italiancity-1 ] ; I have created a simple and fake example to reproduce my problem. or-example-data.ttl.txt or-example-shacl.ttl.txt

Hope it helps Thank you very much! Stefano

HolgerKnublauch commented 3 years ago

The engine will not walk into nested property shape declarations, i.e. sh:xor will be ignored. It will (as specified in the spec) only recognize the directly declared top-level properties. In your case, you could add a dummy property shape as sibling of the ex:firstName property shape to just declare the other property (even if it has no constraints beside the sh:path triple).

BTW your file has several violations on the schema level - the values of sh:minCount/minLength etc must all be xsd:integer not strings or xsd:int.

sfontanel commented 3 years ago

Hi Holger, thank you for your reply! I confirm that with the dummy property it works. As expected, I have a "downgrade" in the overall level of validation: for example I can connect an individual of "ex:MarsCity" and the validator replies sh:conforms=true.

But that's okay.. Could the use of SPARQL-based Constraints allow us to insert this missing validation as well?

Thank you too for reporting me those errors, I still have to read the specification carefully.

Stefano

sfontanel commented 3 years ago

I have read the SHACL specification and I have a last question on this discussion..

In chapter 4 I read that:

"This section defines the built-in SHACL Core constraint components that MUST be supported by all SHACL Core processors"

and in section 4.6 I see the logical operators mentioned. Moreover chapter 4.1 refers to the possibility of combining the OR operator with sh:class:

"The constraint components in this section have in common that they can be used to restrict the type of value nodes. Note that it is possible to represent multiple value type alternatives using sh:or. "

I saw that this library has already the full coverage of the test suite https://w3c.github.io/data-shapes/data-shapes-test-suite/#validate-rdf-data-tests Great :D

I don't see an explicit test on supporting sh:or. So maybe I didn't understand correctly what I mentioned from chapter 4 as the minimum elements that a shacl implementation must support ..

In other words: is the logical operators support a "MUST" requirement for a compliant shacl processor/validator? If it's a must requirement, may this library support it in the future?

Thank you very much for your support! Regards Stefano

HolgerKnublauch commented 3 years ago

The library does implement the whole spec and I am not aware of bugs related to sh:or. If you can construct a scenario where it is incorrect, let me know.

simonstey commented 3 years ago

I don't see an explicit test on supporting sh:or. So maybe I didn't understand correctly what I mentioned from chapter 4 as the minimum elements that a shacl implementation must support ..

There is image though..

https://github.com/w3c/data-shapes/blob/gh-pages/data-shapes-test-suite/tests/core/node/or-001.ttl

or do you mean something else, @sfontanel?

sfontanel commented 3 years ago

Thank you Simon! it was my mistake not to find it :|

Going back to @HolgerKnublauch 's first answer, I found the chapter of the specification he was referring to (not the one on sh:or that I was focusing on): https://www.w3.org/TR/shacl/#ClosedConstraintComponent; the library is compliant with the specification so we can close the issue.

Thank you for the support :) Have a nice day Stefano