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 94f29b3b2e4..81688cafebd 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 @@ -290,22 +290,30 @@ public String buildSparqlValidNodes(String targetVar) { @Override public Stream 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 allSubjectsObjects; + + if (hasOwnPath()) { + 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") + ); + + allSubjectsObjects = Stream.of(subject, object); + } else { + allSubjectsObjects = Stream.empty(); + } Stream statementPatternStream = and.stream() .flatMap(Collection::stream) .flatMap(PropertyShape::getStatementPatterns); - return Stream.concat(statementPatternStream, Stream.of(subject, object)); + return Stream.concat(statementPatternStream, allSubjectsObjects); } } 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 c714fbd76af..b2acd7d2ad3 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 @@ -362,22 +362,30 @@ public String buildSparqlValidNodes(String targetVar) { @Override public Stream 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 allSubjectsObjects; + + if (hasOwnPath()) { + 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") + ); + + allSubjectsObjects = Stream.of(subject, object); + } else { + allSubjectsObjects = Stream.empty(); + } Stream statementPatternStream = or.stream() .flatMap(Collection::stream) .flatMap(PropertyShape::getStatementPatterns); - return Stream.concat(statementPatternStream, Stream.of(subject, object)); + return Stream.concat(statementPatternStream, allSubjectsObjects); } }