Validation of sh:targetNode when the node is not present in the data #5140
-
Current BehaviorRDF4J Expected BehaviorI'm flagging it as a bug because I would expect that Steps To ReproduceCode sample: String shaclRules = "@prefix sh: <http://www.w3.org/ns/shacl#> .\n" +
"@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n\n" +
"<http://example.org/component/component-state-context>\n" +
" a sh:PropertyShape;\n" +
" sh:targetNode <http://example.org/component>;\n" +
" sh:path <https://saref.etsi.org/core/hasState>;\n" +
" sh:maxCount 1;\n" +
" sh:minCount 1;\n" +
" sh:hasValue \"ready\".";
ShaclSail shaclSail = new ShaclSail(new MemoryStore());
Repository repo = new SailRepository(shaclSail);
try (RepositoryConnection connection = repo.getConnection()) {
// add shapes
connection.begin();
connection.clear(RDF4J.SHACL_SHAPE_GRAPH);
connection.add(new StringReader(shaclRules), "", RDFFormat.TURTLE, RDF4J.SHACL_SHAPE_GRAPH);
connection.commit();
} catch (IOException e) {
throw new RuntimeException(e);
}
Exception:
Version5.0.2 Are you interested in contributing a solution yourself?None Anything else?No response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Our implementation is based on the premise that a target node doesn't actually have to exist for it to violate a shape. In your case you are saying that I'll check the specification and test cases to see if this is the correct interpretation or not. |
Beta Was this translation helpful? Give feedback.
-
Seems that it’s correct to validate the minCount constraint for a targetNode even if the target node is not present in the data. The spec isn't exactly very clear: https://www.w3.org/TR/shacl/#targetNode But there is a test case that is validated against the reference SHACL implementation:
There is also a test from the W3C SHACL test suite that tests for something similar: https://github.com/eclipse-rdf4j/rdf4j/blob/main/core/sail/shacl/src/test/resources/w3c/core/node/datatype-002.ttl An issue with that test though is that it doesn't seem to differentiate between what is data and what are shapes, so the nodes are definitely present in the data graph. |
Beta Was this translation helpful? Give feedback.
-
Thank you. I had misinterpreted the role of the SHACL rules upon committing them, assuming that the rules will not be violated if the target node does not exist. The |
Beta Was this translation helpful? Give feedback.
Seems that it’s correct to validate the minCount constraint for a targetNode even if the target node is not present in the data.
The spec isn't exactly very clear: https://www.w3.org/TR/shacl/#targetNode
But there is a test case that is validated against the reference SHACL implementation:
There is also a test from the W3C SHACL test suite that tests for something similar: https://github.com/eclipse-rdf4j/rdf4j/blob/main/core/sail/shacl…