Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#171: closed validator now iterates over value nodes instead of focus… #172

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,20 @@ public void executeConstraint(Constraint constraint, ValidationEngine engine, Co
if(closed) {
long startTime = System.currentTimeMillis();
for(RDFNode focusNode : focusNodes) {
if(focusNode instanceof Resource) {
Iterator<Statement> it = ((Resource)focusNode).listProperties();
while(it.hasNext()) {
Statement s = it.next();
if(!allowedProperties.contains(s.getPredicate())) {
Resource result = engine.createValidationResult(constraint, focusNode, s.getObject(), () -> "Predicate " + engine.getLabelFunction().apply(s.getPredicate()) + " is not allowed (closed shape)");
result.removeAll(SH.resultPath);
result.addProperty(SH.resultPath, s.getPredicate());
for(RDFNode valueNode : engine.getValueNodes(constraint, focusNode)) {
if(valueNode instanceof Resource) {
Iterator<Statement> it = ((Resource)valueNode).listProperties();
while(it.hasNext()) {
Statement s = it.next();
if(!allowedProperties.contains(s.getPredicate())) {
Resource result = engine.createValidationResult(constraint, valueNode, s.getObject(), () -> "Predicate " + engine.getLabelFunction().apply(s.getPredicate()) + " is not allowed (closed shape)");
result.removeAll(SH.resultPath);
result.addProperty(SH.resultPath, s.getPredicate());
}
}
engine.checkCanceled();
}
}
engine.checkCanceled();
}
addStatistics(engine, constraint, startTime, focusNodes.size(), focusNodes.size());
}
Expand Down
39 changes: 39 additions & 0 deletions src/test/resources/sh/tests/core/property/closed-001.test.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# baseURI: http://datashapes.org/sh/tests/core/property/closed-001.test
# prefix: ex

@prefix dash: <http://datashapes.org/dash#> .
@prefix ex: <http://datashapes.org/sh/tests/core/property/closed-001.test#> .
@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#> .

<http://datashapes.org/sh/tests/core/property/closed-001.test>
rdf:type owl:Ontology ;
rdfs:label "Test of sh:closed at property shape 001" ;
owl:imports <http://datashapes.org/dash> ;
.
ex:GraphValidationTestCase
rdf:type dash:GraphValidationTestCase ;
dash:expectedResult [
rdf:type sh:ValidationReport ;
sh:conforms "true"^^xsd:boolean ;
] ;
.
ex:Person
a rdfs:Class, sh:NodeShape ;
sh:property [
sh:path ex:knows ;
sh:closed true;
sh:property
[
sh:path ex:name ;
];

] .
ex:validPerson1 a ex:Person ;
ex:knows
[
ex:name "John" ;
] .