diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/AndPropertyShape.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/AndPropertyShape.java index 248f9963667..94f29b3b2e4 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/AndPropertyShape.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/AndPropertyShape.java @@ -11,11 +11,13 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.query.algebra.StatementPattern; +import org.eclipse.rdf4j.query.algebra.Var; import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection; import org.eclipse.rdf4j.sail.SailConnection; import org.eclipse.rdf4j.sail.shacl.ConnectionsGroup; @@ -288,9 +290,22 @@ public String buildSparqlValidNodes(String targetVar) { @Override public Stream getStatementPatterns() { - return and - .stream() + StatementPattern subject = new StatementPattern( + new Var("?this"), + new Var(UUID.randomUUID().toString()), + new Var(UUID.randomUUID().toString()) + ); + + StatementPattern object = new StatementPattern( + new Var(UUID.randomUUID().toString()), + new Var(UUID.randomUUID().toString()), + new Var("?this") + ); + + Stream statementPatternStream = and.stream() .flatMap(Collection::stream) .flatMap(PropertyShape::getStatementPatterns); + + return Stream.concat(statementPatternStream, Stream.of(subject, object)); } } diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/OrPropertyShape.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/OrPropertyShape.java index 89976709314..c714fbd76af 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/OrPropertyShape.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/OrPropertyShape.java @@ -17,6 +17,7 @@ import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.query.algebra.StatementPattern; +import org.eclipse.rdf4j.query.algebra.Var; import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection; import org.eclipse.rdf4j.sail.SailConnection; import org.eclipse.rdf4j.sail.shacl.ConnectionsGroup; @@ -327,9 +328,9 @@ public String buildSparqlValidNodes(String targetVar) { String pathQuery2 = getPath().getQuery(targetVar, randomVariable(), null); query = "{\n" + AbstractBulkJoinPlanNode.VALUES_INJECTION_POINT + "\n " + query.replaceAll("(?m)^", "\t") - + " \n} UNION {\n\t" + AbstractBulkJoinPlanNode.VALUES_INJECTION_POINT + "\n\t" + targetVar + " " - + randomVariable() + " " - + randomVariable() + ".\n\tFILTER(NOT EXISTS {\n " + pathQuery2.replaceAll("(?m)^", "\t") + + " \n} UNION {\n\t" + AbstractBulkJoinPlanNode.VALUES_INJECTION_POINT + "\n" + + "\t" + targetVar + " " + randomVariable() + " " + randomVariable() + ".\n" + + "\tFILTER(NOT EXISTS {\n " + pathQuery2.replaceAll("(?m)^", "\t") + " \n})\n}"; return query; @@ -360,6 +361,23 @@ public String buildSparqlValidNodes(String targetVar) { @Override public Stream getStatementPatterns() { - return or.stream().flatMap(Collection::stream).flatMap(PropertyShape::getStatementPatterns); + + StatementPattern subject = new StatementPattern( + new Var("?this"), + new Var(UUID.randomUUID().toString()), + new Var(UUID.randomUUID().toString()) + ); + + StatementPattern object = new StatementPattern( + new Var(UUID.randomUUID().toString()), + new Var(UUID.randomUUID().toString()), + new Var("?this") + ); + + Stream statementPatternStream = or.stream() + .flatMap(Collection::stream) + .flatMap(PropertyShape::getStatementPatterns); + + return Stream.concat(statementPatternStream, Stream.of(subject, object)); } } diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/TargetShape.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/TargetShape.java index 531973e769e..e1c46b17b1b 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/TargetShape.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/TargetShape.java @@ -91,7 +91,7 @@ public PlanNode getPlanRemovedStatements(ConnectionsGroup connectionsGroup, } - private PlanNode getInnerPlanRemovedOrAdded(ConnectionsGroup connectionsGroup, SailConnection removedStatements) { + private PlanNode getInnerPlanRemovedOrAdded(ConnectionsGroup connectionsGroup, SailConnection connection) { // @formatter:off /* @@ -107,7 +107,7 @@ private PlanNode getInnerPlanRemovedOrAdded(ConnectionsGroup connectionsGroup, S PlanNode statementsThatMatchPattern = new TrimTuple( new UnorderedSelect( - removedStatements, + connection, null, ((IRI) statementPattern.getPredicateVar().getValue()), (statementPattern.getObjectVar().getValue()), @@ -140,7 +140,8 @@ public boolean requiresEvaluation(SailConnection addedStatements, SailConnection @Override public String getQuery(String subjectVariable, String objectVariable, RdfsSubClassOfReasoner rdfsSubClassOfReasoner) { - return targetShape.buildSparqlValidNodes(subjectVariable); + String s = targetShape.buildSparqlValidNodes(subjectVariable); + return s; } diff --git a/core/sail/shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/AbstractShaclTest.java b/core/sail/shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/AbstractShaclTest.java index 43e76df015b..4ac2237da5f 100644 --- a/core/sail/shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/AbstractShaclTest.java +++ b/core/sail/shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/AbstractShaclTest.java @@ -332,10 +332,6 @@ static void runTestCase(String shaclPath, String dataPath, ExpectedResult expect if (!(sailException.getCause() instanceof ShaclSailValidationException)) { throw sailException; } - exception = true; - logger.debug(sailException.getMessage()); - - printResults(sailException); } } diff --git a/core/sail/shacl/src/test/resources/test-cases/hasValue/targetShapeAnd/invalid/case4/query1.rq b/core/sail/shacl/src/test/resources/test-cases/hasValue/targetShapeAnd/invalid/case4/query1.rq new file mode 100644 index 00000000000..d96e894583c --- /dev/null +++ b/core/sail/shacl/src/test/resources/test-cases/hasValue/targetShapeAnd/invalid/case4/query1.rq @@ -0,0 +1,13 @@ + +PREFIX ex: +PREFIX owl: +PREFIX rdf: +PREFIX rdfs: +PREFIX sh: +PREFIX xsd: + +INSERT DATA { + +ex:a ex:b ex:validPerson1 . + +} diff --git a/core/sail/shacl/src/test/resources/test-cases/hasValueIn/targetShapeOr/invalid/case4/query1.rq b/core/sail/shacl/src/test/resources/test-cases/hasValueIn/targetShapeOr/invalid/case4/query1.rq new file mode 100644 index 00000000000..c33d6a2e9d5 --- /dev/null +++ b/core/sail/shacl/src/test/resources/test-cases/hasValueIn/targetShapeOr/invalid/case4/query1.rq @@ -0,0 +1,13 @@ + +PREFIX ex: +PREFIX owl: +PREFIX rdf: +PREFIX rdfs: +PREFIX sh: +PREFIX xsd: + +INSERT DATA { + +ex:validPerson1 ex:a ex:b . + +} diff --git a/core/sail/shacl/src/test/resources/test-cases/hasValueIn/targetShapeOr/invalid/case5/query1.rq b/core/sail/shacl/src/test/resources/test-cases/hasValueIn/targetShapeOr/invalid/case5/query1.rq new file mode 100644 index 00000000000..e60532079bb --- /dev/null +++ b/core/sail/shacl/src/test/resources/test-cases/hasValueIn/targetShapeOr/invalid/case5/query1.rq @@ -0,0 +1,11 @@ + +PREFIX ex: +PREFIX owl: +PREFIX rdf: +PREFIX rdfs: +PREFIX sh: +PREFIX xsd: + +INSERT DATA { + ex:a ex:b ex:validPerson1 . +}