Skip to content

Commit

Permalink
zeroOrMorePath is mostly implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad committed Sep 24, 2024
1 parent a60dae4 commit e08f9aa
Show file tree
Hide file tree
Showing 24 changed files with 157 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ static PlanNode getAllTargetsIncludingThoseAddedByPath(ConnectionsGroup connecti
null);

allTargets = UnionNode.getInstance(connectionsGroup, addedTargets.getPlanNode(), addedByPath);

allTargets = Unique.getInstance(new TrimToTarget(allTargets, connectionsGroup), false, connectionsGroup);

return allTargets;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[]

}

return Unique.getInstance(allTargetsPlan, false, connectionsGroup);
return Unique.getInstance(new TrimToTarget(allTargetsPlan, connectionsGroup), false, connectionsGroup);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.rdf4j.sail.shacl.ast.ValidationApproach;
import org.eclipse.rdf4j.sail.shacl.ast.ValidationQuery;
import org.eclipse.rdf4j.sail.shacl.ast.paths.Path;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AbstractBulkJoinPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AllTargetsPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BufferedPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalInnerJoin;
Expand Down Expand Up @@ -135,7 +136,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
connectionsGroup.getPreviousStateConnection(),
b -> new ValidationTuple(b.getValue("a"), b.getValue("c"), scope, true,
validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);

top = UnionNode.getInstance(connectionsGroup, top, bulkedExternalInnerJoin);

Expand Down Expand Up @@ -218,7 +219,7 @@ private PlanNode getPlanNodeForOverrideTargetNode(ConnectionsGroup connectionsGr
Set.of()),
false, null,
BulkedExternalInnerJoin.getMapper("a", "c", scope, validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);
planNode = connectionsGroup.getCachedNodeFor(planNode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.rdf4j.sail.shacl.ast.ValidationApproach;
import org.eclipse.rdf4j.sail.shacl.ast.ValidationQuery;
import org.eclipse.rdf4j.sail.shacl.ast.paths.Path;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AbstractBulkJoinPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AllTargetsPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BufferedSplitter;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalInnerJoin;
Expand Down Expand Up @@ -171,7 +172,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
false,
null,
BulkedExternalInnerJoin.getMapper("a", "c", scope, validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);

if (connectionsGroup.getAddedStatements() != null) {
// filter by type against the added statements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.eclipse.rdf4j.sail.shacl.ast.ValidationQuery;
import org.eclipse.rdf4j.sail.shacl.ast.paths.Path;
import org.eclipse.rdf4j.sail.shacl.ast.paths.SimplePath;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AbstractBulkJoinPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BufferedSplitter;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalInnerJoin;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.ExternalFilterByQuery;
Expand Down Expand Up @@ -192,7 +193,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
false,
null,
BulkedExternalInnerJoin.getMapper("a", "c", scope, validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);

StatementMatcher.Variable<Value> subjectVariable = stableRandomVariableProvider.next();
StatementMatcher.Variable<Value> predicateVariable = stableRandomVariableProvider.next();
Expand Down Expand Up @@ -317,7 +318,10 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
}
return validationTuple;
},
connectionsGroup);
connectionsGroup,
List.of(AbstractBulkJoinPlanNode.DEFAULT_VARS.get(0), AbstractBulkJoinPlanNode.DEFAULT_VARS.get(1),
predicateVariable)
);

return bulkedExternalInnerJoin;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.rdf4j.sail.shacl.ast.StatementMatcher;
import org.eclipse.rdf4j.sail.shacl.ast.StatementMatcher.Variable;
import org.eclipse.rdf4j.sail.shacl.ast.paths.Path;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AbstractBulkJoinPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalLeftOuterJoin;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.EmptyNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.GroupByFilter;
Expand Down Expand Up @@ -113,7 +114,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
connectionsGroup.getRdfsSubClassOfReasoner(), stableRandomVariableProvider, Set.of()),
(b) -> new ValidationTuple(b.getValue("a"), b.getValue("c"), scope, true,
validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);

PlanNode invalidTargets = new GroupByFilter(joined, group -> {
return group.stream().map(ValidationTuple::getValue).noneMatch(hasValueIn::contains);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.rdf4j.sail.shacl.ast.ValidationApproach;
import org.eclipse.rdf4j.sail.shacl.ast.ValidationQuery;
import org.eclipse.rdf4j.sail.shacl.ast.paths.Path;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AbstractBulkJoinPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalLeftOuterJoin;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.EmptyNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.GroupByFilter;
Expand Down Expand Up @@ -98,16 +99,18 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
EffectiveTarget.Extend.left, false, null);

addedTargets = UnionNode.getInstance(connectionsGroup, addedByPath, addedTargets);
addedTargets = Unique.getInstance(addedTargets, false, connectionsGroup);
}

addedTargets = Unique.getInstance(new TrimToTarget(addedTargets, connectionsGroup), false,
connectionsGroup);

PlanNode joined = new BulkedExternalLeftOuterJoin(addedTargets, connectionsGroup.getBaseConnection(),
validationSettings.getDataGraph(),
path.getTargetQueryFragment(new Variable<>("a"), new Variable<>("c"),
connectionsGroup.getRdfsSubClassOfReasoner(), stableRandomVariableProvider, Set.of()),
(b) -> new ValidationTuple(b.getValue("a"), b.getValue("c"), scope, true,
validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);

PlanNode invalidTargets = new GroupByFilter(joined, group -> {
return group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.rdf4j.sail.shacl.ast.ValidationApproach;
import org.eclipse.rdf4j.sail.shacl.ast.ValidationQuery;
import org.eclipse.rdf4j.sail.shacl.ast.paths.Path;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AbstractBulkJoinPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalInnerJoin;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalLeftOuterJoin;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.EmptyNode;
Expand Down Expand Up @@ -113,7 +114,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
false,
null,
BulkedExternalInnerJoin.getMapper("a", "c", scope, validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);
} else {
relevantTargetsWithPath = new BulkedExternalLeftOuterJoin(
mergeNode,
Expand All @@ -126,7 +127,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
Set.of()),
(b) -> new ValidationTuple(b.getValue("a"), b.getValue("c"), scope, true,
validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);
}

relevantTargetsWithPath = connectionsGroup.getCachedNodeFor(relevantTargetsWithPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.rdf4j.sail.shacl.ast.StatementMatcher;
import org.eclipse.rdf4j.sail.shacl.ast.ValidationApproach;
import org.eclipse.rdf4j.sail.shacl.ast.ValidationQuery;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AbstractBulkJoinPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalLeftOuterJoin;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.EmptyNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.GroupByCountFilter;
Expand Down Expand Up @@ -118,7 +119,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
connectionsGroup.getRdfsSubClassOfReasoner(), stableRandomVariableProvider, Set.of()),
(b) -> new ValidationTuple(b.getValue("a"), b.getValue("c"), scope, true,
validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);

relevantTargetsWithPath = connectionsGroup.getCachedNodeFor(relevantTargetsWithPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.rdf4j.sail.shacl.ast.Shape;
import org.eclipse.rdf4j.sail.shacl.ast.StatementMatcher;
import org.eclipse.rdf4j.sail.shacl.ast.ValidationQuery;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AbstractBulkJoinPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalLeftOuterJoin;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.GroupByCountFilter;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.LeftOuterJoin;
Expand Down Expand Up @@ -182,7 +183,7 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va
Set.of()),
(b) -> new ValidationTuple(b.getValue("a"), b.getValue("c"), scope, true,
validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);

return new TupleMapper(relevantTargetsWithPath, t -> {
List<Value> targetChain = t.getTargetChain(true);
Expand Down Expand Up @@ -226,7 +227,7 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va
connectionsGroup.getRdfsSubClassOfReasoner(), stableRandomVariableProvider, Set.of()),
(b) -> new ValidationTuple(b.getValue("a"), b.getValue("c"), scope, true,
validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);

invalid = new NotValuesIn(allTargetsPlan, invalid, connectionsGroup);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.rdf4j.sail.shacl.ast.Shape;
import org.eclipse.rdf4j.sail.shacl.ast.StatementMatcher;
import org.eclipse.rdf4j.sail.shacl.ast.ValidationQuery;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AbstractBulkJoinPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AllTargetsPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalLeftOuterJoin;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.GroupByCountFilter;
Expand Down Expand Up @@ -189,7 +190,7 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va
Set.of()),
(b) -> new ValidationTuple(b.getValue("a"), b.getValue("c"), scope, true,
validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);

return new TupleMapper(relevantTargetsWithPath, t -> {
List<Value> targetChain = t.getTargetChain(true);
Expand Down Expand Up @@ -240,7 +241,7 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va
Set.of()),
(b) -> new ValidationTuple(b.getValue("a"), b.getValue("c"), scope, true,
validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);
}

invalid = new NotValuesIn(allTargetsPlan, invalid, connectionsGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.rdf4j.sail.shacl.ast.ValidationApproach;
import org.eclipse.rdf4j.sail.shacl.ast.ValidationQuery;
import org.eclipse.rdf4j.sail.shacl.ast.paths.Path;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AbstractBulkJoinPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalInnerJoin;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.EmptyNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.InnerJoin;
Expand Down Expand Up @@ -142,7 +143,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
null,
BulkedExternalInnerJoin.getMapper("a", "c", scope, validationSettings.getDataGraph()),

connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);

PlanNode nonUniqueTargetLang = new NonUniqueTargetLang(relevantTargetsWithPath, connectionsGroup);
return Unique.getInstance(new TrimToTarget(nonUniqueTargetLang, connectionsGroup), false, connectionsGroup);
Expand Down Expand Up @@ -189,8 +190,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
false,
null,
BulkedExternalInnerJoin.getMapper("a", "c", scope, validationSettings.getDataGraph()),

connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);

PlanNode nonUniqueTargetLang = new NonUniqueTargetLang(relevantTargetsWithPath, connectionsGroup);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public OneOrMorePath(Resource id, Path path) {

@Override
public String toString() {
return "OneOrOnePath{ " + path + " }";
return "OneOrMorePath{ " + path + " }";
}

@Override
Expand Down Expand Up @@ -132,14 +132,6 @@ public SparqlFragment getTargetQueryFragment(StatementMatcher.Variable subject,
rdfsSubClassOfReasoner, stableRandomVariableProvider,
inheritedVarNames);

// SparqlFragment targetQueryFragmentStart = path.getTargetQueryFragment(subject, pathStart,
// rdfsSubClassOfReasoner, stableRandomVariableProvider,
// inheritedVarNames);
//
// SparqlFragment targetQueryFragmentEnd = path.getTargetQueryFragment(pathEnd, object, rdfsSubClassOfReasoner,
// stableRandomVariableProvider,
// inheritedVarNames);

SparqlFragment targetQueryFragmentExactlyOne = path.getTargetQueryFragment(subject, object,
rdfsSubClassOfReasoner, stableRandomVariableProvider,
inheritedVarNames);
Expand Down Expand Up @@ -171,7 +163,7 @@ public SparqlFragment getTargetQueryFragment(StatementMatcher.Variable subject,
assert subjectName.equals(pathStart.getName());

String query = "select distinct " + subject.asSparqlVariable() + " where {\n"
+ subject.asSparqlVariable() + " (" + sparqlPathString + ")* "
+ subject.asSparqlVariable() + " (" + sparqlPathString + ")+ "
+ pathStart.asSparqlVariable() + "\n}";

TupleExpr tupleExpr = SparqlQueryParserCache.get(query);
Expand All @@ -185,7 +177,6 @@ public SparqlFragment getTargetQueryFragment(StatementMatcher.Variable subject,
new SingletonBindingSet(subjectName, statement.getSubject()), true)) {
while (evaluate.hasNext()) {
BindingSet next = evaluate.next();
System.out.println(next);
statements.add(new EffectiveTarget.SubjectObjectAndMatcher.SubjectObject(
((Resource) next.getValue(subject.getName())), null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.sail.shacl.ShaclSailConnection;
import org.eclipse.rdf4j.sail.shacl.ast.Exportable;
import org.eclipse.rdf4j.sail.shacl.ast.Identifiable;
import org.eclipse.rdf4j.sail.shacl.ast.ShaclUnsupportedException;
Expand All @@ -30,9 +31,13 @@
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.PlanNodeWrapper;
import org.eclipse.rdf4j.sail.shacl.wrapper.data.ConnectionsGroup;
import org.eclipse.rdf4j.sail.shacl.wrapper.shape.ShapeSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class Path implements Identifiable, Exportable, Targetable {

private static final Logger logger = LoggerFactory.getLogger(ShaclSailConnection.class);

Resource id;

public Path(Resource id) {
Expand Down Expand Up @@ -62,43 +67,37 @@ static public Path buildPath(ShapeSource shapeSource, Resource id) {
switch (pathType.toString()) {
case "http://www.w3.org/ns/shacl#inversePath":
if (ret != null) {
throw new ShaclUnsupportedException(
"Multiple path types not supported! " + Arrays.toString(collect.toArray()));
logger.error("Multiple path types not supported! {}", Arrays.toString(collect.toArray()));
}
ret = new InversePath(id, (Resource) statement.getObject(), shapeSource);
break;
case "http://www.w3.org/ns/shacl#alternativePath":
if (ret != null) {
throw new ShaclUnsupportedException(
"Multiple path types not supported! " + Arrays.toString(collect.toArray()));
logger.error("Multiple path types not supported! {}", Arrays.toString(collect.toArray()));
}
ret = new AlternativePath(id, (Resource) statement.getObject(), shapeSource);
break;
case "http://www.w3.org/ns/shacl#zeroOrMorePath":
if (ret != null) {
throw new ShaclUnsupportedException(
"Multiple path types not supported! " + Arrays.toString(collect.toArray()));
logger.error("Multiple path types not supported! {}", Arrays.toString(collect.toArray()));
}
ret = new ZeroOrMorePath(id, (Resource) statement.getObject(), shapeSource);
break;
case "http://www.w3.org/ns/shacl#oneOrMorePath":
if (ret != null) {
throw new ShaclUnsupportedException(
"Multiple path types not supported! " + Arrays.toString(collect.toArray()));
logger.error("Multiple path types not supported! {}", Arrays.toString(collect.toArray()));
}
ret = new OneOrMorePath(id, (Resource) statement.getObject(), shapeSource);
break;
case "http://www.w3.org/ns/shacl#zeroOrOnePath":
if (ret != null) {
throw new ShaclUnsupportedException(
"Multiple path types not supported! " + Arrays.toString(collect.toArray()));
logger.error("Multiple path types not supported! {}", Arrays.toString(collect.toArray()));
}
ret = new ZeroOrOnePath(id, (Resource) statement.getObject(), shapeSource);
break;
case "http://www.w3.org/1999/02/22-rdf-syntax-ns#first":
if (ret != null) {
throw new ShaclUnsupportedException(
"Multiple path types not supported! " + Arrays.toString(collect.toArray()));
logger.error("Multiple path types not supported! {}", Arrays.toString(collect.toArray()));
}
ret = new SequencePath(id, shapeSource);
break;
Expand Down
Loading

0 comments on commit e08f9aa

Please sign in to comment.