From 2b1c34811e9f09e0fcd4f624e9700305044b2d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Avard=20Ottestad?= Date: Mon, 30 Sep 2024 09:39:44 +0200 Subject: [PATCH] GH-5139 fix bug in sh:qualifiedMaxCount --- .../rdf4j/sail/shacl/ast/NodeShape.java | 5 +- .../rdf4j/sail/shacl/ast/PropertyShape.java | 5 +- .../AbstractConstraintComponent.java | 3 +- .../AbstractPairwiseConstraintComponent.java | 3 +- .../AbstractSimpleConstraintComponent.java | 3 +- .../AndConstraintComponent.java | 5 +- .../ClassConstraintComponent.java | 3 +- .../ClosedConstraintComponent.java | 3 +- .../ConstraintComponent.java | 3 +- .../DashHasValueInConstraintComponent.java | 3 +- .../HasValueConstraintComponent.java | 3 +- .../MaxCountConstraintComponent.java | 3 +- .../MinCountConstraintComponent.java | 3 +- .../NotConstraintComponent.java | 7 +-- .../OrConstraintComponent.java | 7 +-- .../QualifiedMaxCountConstraintComponent.java | 48 ++++++++++++------- .../QualifiedMinCountConstraintComponent.java | 11 +++-- .../SparqlConstraintComponent.java | 3 +- .../UniqueLangConstraintComponent.java | 3 +- .../VoidConstraintComponent.java | 3 +- .../sail/shacl/ast/paths/ZeroOrMorePath.java | 1 - 21 files changed, 81 insertions(+), 47 deletions(-) diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/NodeShape.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/NodeShape.java index 0688db2316e..dcd9291cba6 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/NodeShape.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/NodeShape.java @@ -202,11 +202,12 @@ public SourceConstraintComponent getConstraintComponent() { @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { PlanNode planNode = constraintComponents.stream() .map(c -> c.getAllTargetsPlan(connectionsGroup, dataGraph, Scope.nodeShape, - new StatementMatcher.StableRandomVariableProvider())) + new StatementMatcher.StableRandomVariableProvider(), validationSettings)) .distinct() .reduce((nodes, nodes2) -> UnionNode.getInstanceDedupe(connectionsGroup, nodes, nodes2)) .orElse(EmptyNode.getInstance()); diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/PropertyShape.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/PropertyShape.java index 5735bf9276d..db324f3c020 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/PropertyShape.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/PropertyShape.java @@ -255,10 +255,11 @@ constraintComponent, getSeverity(), t.getScope(), t.getContexts(), @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { PlanNode planNode = constraintComponents.stream() .map(c -> c.getAllTargetsPlan(connectionsGroup, dataGraph, Scope.propertyShape, - new StatementMatcher.StableRandomVariableProvider())) + new StatementMatcher.StableRandomVariableProvider(), validationSettings)) .distinct() .reduce((nodes, nodes2) -> UnionNode.getInstanceDedupe(connectionsGroup, nodes, nodes2)) .orElse(EmptyNode.getInstance()); diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AbstractConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AbstractConstraintComponent.java index 0b0f0266f67..fedfe846162 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AbstractConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AbstractConstraintComponent.java @@ -103,7 +103,8 @@ public boolean requiresEvaluation(ConnectionsGroup connectionsGroup, Scope scope @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { throw new UnsupportedOperationException(); } diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AbstractPairwiseConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AbstractPairwiseConstraintComponent.java index 0e98dafb020..daba61bd6c0 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AbstractPairwiseConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AbstractPairwiseConstraintComponent.java @@ -161,7 +161,8 @@ private PlanNode getAllTargetsBasedOnPredicate(ConnectionsGroup connectionsGroup @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { if (scope == Scope.propertyShape) { PlanNode allTargetsPlan = getTargetChain() .getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(), diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AbstractSimpleConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AbstractSimpleConstraintComponent.java index 27794706e63..9682bc42ee2 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AbstractSimpleConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AbstractSimpleConstraintComponent.java @@ -332,7 +332,8 @@ String literalToString(Literal literal) { @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { if (scope == Scope.propertyShape) { diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AndConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AndConstraintComponent.java index aa6bb4f8860..bfc71a8e135 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AndConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/AndConstraintComponent.java @@ -121,10 +121,11 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { PlanNode planNode = and.stream() .map(c -> c.getAllTargetsPlan(connectionsGroup, dataGraph, scope, - new StatementMatcher.StableRandomVariableProvider())) + new StatementMatcher.StableRandomVariableProvider(), validationSettings)) .distinct() .reduce((nodes, nodes2) -> UnionNode.getInstanceDedupe(connectionsGroup, nodes, nodes2)) .orElse(EmptyNode.getInstance()); diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/ClassConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/ClassConstraintComponent.java index 4b1173d5251..935c1cf3727 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/ClassConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/ClassConstraintComponent.java @@ -237,7 +237,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { if (scope == Scope.propertyShape) { PlanNode allTargetsPlan = getTargetChain() .getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(), diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/ClosedConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/ClosedConstraintComponent.java index c5deca68eed..a12cc650c84 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/ClosedConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/ClosedConstraintComponent.java @@ -330,7 +330,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { EffectiveTarget effectiveTarget = getTargetChain().getEffectiveTarget(scope, connectionsGroup.getRdfsSubClassOfReasoner(), stableRandomVariableProvider); diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/ConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/ConstraintComponent.java index 15a153cfc6c..e051b20057c 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/ConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/ConstraintComponent.java @@ -63,7 +63,8 @@ boolean requiresEvaluation(ConnectionsGroup connectionsGroup, Scope scope, Resou SourceConstraintComponent getConstraintComponent(); PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider); + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings); SparqlFragment buildSparqlValidNodes_rsx_targetShape(Variable subject, Variable object, RdfsSubClassOfReasoner rdfsSubClassOfReasoner, Scope scope, diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/DashHasValueInConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/DashHasValueInConstraintComponent.java index c0d0f2840c0..2839d3bcd71 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/DashHasValueInConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/DashHasValueInConstraintComponent.java @@ -150,7 +150,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { if (scope == Scope.propertyShape) { PlanNode allTargetsPlan = getTargetChain() .getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(), diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/HasValueConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/HasValueConstraintComponent.java index 471cafc2bb3..a4f3d66b11c 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/HasValueConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/HasValueConstraintComponent.java @@ -147,7 +147,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { if (scope == Scope.propertyShape) { PlanNode allTargetsPlan = getTargetChain() .getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(), diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxCountConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxCountConstraintComponent.java index b4b3c74c907..f38c04ac44a 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxCountConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxCountConstraintComponent.java @@ -141,7 +141,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { if (scope == Scope.propertyShape) { PlanNode allTargetsPlan = getTargetChain() .getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(), diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinCountConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinCountConstraintComponent.java index 1f16d608d96..7f4f4af9ae6 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinCountConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinCountConstraintComponent.java @@ -132,7 +132,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { return EmptyNode.getInstance(); } diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/NotConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/NotConstraintComponent.java index a4d4a208b2d..40f793308ac 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/NotConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/NotConstraintComponent.java @@ -101,7 +101,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections planNodeProvider = overrideTargetNode; } else { planNodeProvider = () -> getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope, - stableRandomVariableProvider); + stableRandomVariableProvider, validationSettings); } PlanNode planNode = not.generateTransactionalValidationPlan( @@ -166,7 +166,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { PlanNode allTargets; if (scope == Scope.propertyShape) { @@ -186,7 +187,7 @@ public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] } PlanNode notTargets = not.getAllTargetsPlan(connectionsGroup, dataGraph, scope, - new StatementMatcher.StableRandomVariableProvider()); + new StatementMatcher.StableRandomVariableProvider(), validationSettings); return Unique.getInstance(UnionNode.getInstanceDedupe(connectionsGroup, allTargets, notTargets), false, connectionsGroup); diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/OrConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/OrConstraintComponent.java index db9c6744675..393e7cbd9a4 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/OrConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/OrConstraintComponent.java @@ -121,7 +121,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections } else { planNodeProvider = BufferedSplitter.getInstance( getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope, - stableRandomVariableProvider), + stableRandomVariableProvider, validationSettings), false); } @@ -141,7 +141,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { PlanNode allTargets; if (scope == Scope.propertyShape) { @@ -162,7 +163,7 @@ public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] PlanNode planNode = or.stream() .map(or -> or.getAllTargetsPlan(connectionsGroup, dataGraph, scope, - new StatementMatcher.StableRandomVariableProvider())) + new StatementMatcher.StableRandomVariableProvider(), validationSettings)) .distinct() .reduce((nodes, nodes2) -> UnionNode.getInstanceDedupe(connectionsGroup, nodes, nodes2)) .orElse(EmptyNode.getInstance()); diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/QualifiedMaxCountConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/QualifiedMaxCountConstraintComponent.java index 870fcedde84..63b660bf6f5 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/QualifiedMaxCountConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/QualifiedMaxCountConstraintComponent.java @@ -28,11 +28,13 @@ import org.eclipse.rdf4j.sail.shacl.ast.Cache; import org.eclipse.rdf4j.sail.shacl.ast.NodeShape; import org.eclipse.rdf4j.sail.shacl.ast.PropertyShape; +import org.eclipse.rdf4j.sail.shacl.ast.ShaclParsingException; import org.eclipse.rdf4j.sail.shacl.ast.ShaclProperties; import org.eclipse.rdf4j.sail.shacl.ast.ShaclUnsupportedException; 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.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.GroupByCountFilter; @@ -121,22 +123,27 @@ public ValidationQuery generateSparqlValidationQuery(ConnectionsGroup connection public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connectionsGroup, ValidationSettings validationSettings, PlanNodeProvider overrideTargetNode, Scope scope) { - assert scope == Scope.propertyShape; + + if (scope != Scope.propertyShape) { + throw new ShaclParsingException( + "QualifiedMaxCountConstraintComponent can only be used on property shapes!"); + } StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider = new StatementMatcher.StableRandomVariableProvider(); PlanNode target; + EffectiveTarget effectiveTarget = getTargetChain().getEffectiveTarget(scope, + connectionsGroup.getRdfsSubClassOfReasoner(), stableRandomVariableProvider); + if (overrideTargetNode != null) { - target = getTargetChain() - .getEffectiveTarget(scope, connectionsGroup.getRdfsSubClassOfReasoner(), - stableRandomVariableProvider) + target = effectiveTarget .extend(overrideTargetNode.getPlanNode(), connectionsGroup, validationSettings.getDataGraph(), scope, EffectiveTarget.Extend.right, false, null); } else { target = getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope, - stableRandomVariableProvider); + stableRandomVariableProvider, validationSettings); } PlanNode planNode = negated(connectionsGroup, validationSettings, overrideTargetNode, scope); @@ -160,7 +167,7 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va if (overrideTargetNode == null) { target = getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope, - stableRandomVariableProvider); + stableRandomVariableProvider, validationSettings); } else { target = getTargetChain() .getEffectiveTarget(scope, connectionsGroup.getRdfsSubClassOfReasoner(), @@ -205,7 +212,7 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va if (overrideTargetNode == null) { allTargetsPlan = getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope, - stableRandomVariableProvider); + stableRandomVariableProvider, validationSettings); } else { allTargetsPlan = getTargetChain() .getEffectiveTarget(scope, connectionsGroup.getRdfsSubClassOfReasoner(), @@ -237,20 +244,29 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { assert scope == Scope.propertyShape; - PlanNode allTargets = getTargetChain() + EffectiveTarget effectiveTarget = getTargetChain() .getEffectiveTarget(Scope.propertyShape, connectionsGroup.getRdfsSubClassOfReasoner(), - stableRandomVariableProvider) - .getPlanNode(connectionsGroup, dataGraph, Scope.propertyShape, true, null); + stableRandomVariableProvider); - PlanNode subTargets = qualifiedValueShape.getAllTargetsPlan(connectionsGroup, dataGraph, scope, - new StatementMatcher.StableRandomVariableProvider()); + Path path = getTargetChain().getPath().orElseThrow(); - return Unique - .getInstance(new TrimToTarget(UnionNode.getInstanceDedupe(connectionsGroup, allTargets, subTargets), - connectionsGroup), false, connectionsGroup); + PlanNode allTargets = getAllTargetsIncludingThoseAddedByPath(connectionsGroup, validationSettings, scope, + effectiveTarget, path, false); + + PlanNode subTargets = qualifiedValueShape.getAllTargetsPlan(connectionsGroup, dataGraph, scope, + new StatementMatcher.StableRandomVariableProvider(), validationSettings); + + return Unique.getInstance( + new TrimToTarget( + UnionNode.getInstanceDedupe(connectionsGroup, allTargets, subTargets), + connectionsGroup + ), + false, connectionsGroup + ); } diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/QualifiedMinCountConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/QualifiedMinCountConstraintComponent.java index 8f241009774..a3ad8f3a70e 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/QualifiedMinCountConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/QualifiedMinCountConstraintComponent.java @@ -139,7 +139,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections false, null); } else { target = getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope, - stableRandomVariableProvider); + stableRandomVariableProvider, validationSettings); } PlanNode planNode = negated(connectionsGroup, validationSettings, overrideTargetNode, scope); @@ -163,7 +163,7 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va if (overrideTargetNode == null) { target = getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope, - stableRandomVariableProvider); + stableRandomVariableProvider, validationSettings); } else { PlanNode planNode = overrideTargetNode.getPlanNode(); if (planNode instanceof AllTargetsPlanNode) { @@ -211,7 +211,7 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va PlanNode allTargetsPlan; if (overrideTargetNode == null) { allTargetsPlan = getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope, - stableRandomVariableProvider); + stableRandomVariableProvider, validationSettings); } else { allTargetsPlan = getTargetChain() .getEffectiveTarget(scope, connectionsGroup.getRdfsSubClassOfReasoner(), @@ -252,7 +252,8 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { assert scope == Scope.propertyShape; PlanNode allTargets = getTargetChain() @@ -261,7 +262,7 @@ public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] .getPlanNode(connectionsGroup, dataGraph, Scope.propertyShape, true, null); PlanNode subTargets = qualifiedValueShape.getAllTargetsPlan(connectionsGroup, dataGraph, scope, - new StatementMatcher.StableRandomVariableProvider()); + new StatementMatcher.StableRandomVariableProvider(), validationSettings); return Unique .getInstance(new TrimToTarget(UnionNode.getInstanceDedupe(connectionsGroup, allTargets, subTargets), diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/SparqlConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/SparqlConstraintComponent.java index 512ae5b338b..77af99c9376 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/SparqlConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/SparqlConstraintComponent.java @@ -224,7 +224,8 @@ private PlanNode getPlanNodeForOverrideTargetNode(ConnectionsGroup connectionsGr @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { return getTargetChain() .getEffectiveTarget(scope, connectionsGroup.getRdfsSubClassOfReasoner(), stableRandomVariableProvider) .getAllTargets(connectionsGroup, dataGraph, scope); diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/UniqueLangConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/UniqueLangConstraintComponent.java index 8b11807c8f2..b51e7a7a58a 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/UniqueLangConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/UniqueLangConstraintComponent.java @@ -200,7 +200,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { if (scope == Scope.propertyShape) { PlanNode allTargetsPlan = getTargetChain() .getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(), diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/VoidConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/VoidConstraintComponent.java index f2bdcc3d1e6..f658cf12b45 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/VoidConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/VoidConstraintComponent.java @@ -59,7 +59,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections @Override public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope, - StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) { + StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider, + ValidationSettings validationSettings) { return EmptyNode.getInstance(); } diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/paths/ZeroOrMorePath.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/paths/ZeroOrMorePath.java index ae662dce828..59af1e127eb 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/paths/ZeroOrMorePath.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/paths/ZeroOrMorePath.java @@ -187,7 +187,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)); }