Skip to content

Commit

Permalink
Merge pull request #2633 from eclipse/GH-2632-rsx-sh_or-bug
Browse files Browse the repository at this point in the history
GH-2632 rsx:targetShape bug when using sh:or or sh:and
  • Loading branch information
hmottestad authored Nov 6, 2020
2 parents d2ae918 + 7d6fafb commit 6fe2494
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -288,9 +290,22 @@ public String buildSparqlValidNodes(String targetVar) {

@Override
public Stream<StatementPattern> 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<StatementPattern> statementPatternStream = and.stream()
.flatMap(Collection::stream)
.flatMap(PropertyShape::getStatementPatterns);

return Stream.concat(statementPatternStream, Stream.of(subject, object));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -360,6 +361,23 @@ public String buildSparqlValidNodes(String targetVar) {

@Override
public Stream<StatementPattern> 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<StatementPattern> statementPatternStream = or.stream()
.flatMap(Collection::stream)
.flatMap(PropertyShape::getStatementPatterns);

return Stream.concat(statementPatternStream, Stream.of(subject, object));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
/*
Expand All @@ -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()),
Expand Down Expand Up @@ -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;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

PREFIX ex: <http://example.com/ns#>
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#>

INSERT DATA {

ex:a ex:b ex:validPerson1 .

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

PREFIX ex: <http://example.com/ns#>
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#>

INSERT DATA {

ex:validPerson1 ex:a ex:b .

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

PREFIX ex: <http://example.com/ns#>
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#>

INSERT DATA {
ex:a ex:b ex:validPerson1 .
}

0 comments on commit 6fe2494

Please sign in to comment.