Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad committed Nov 6, 2024
1 parent 3193a24 commit ecf4d06
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public PlanNode getAllAdded(ConnectionsGroup connectionsGroup, Resource[] dataGr
PlanNode targetChainRetriever = new TargetChainRetriever(connectionsGroup, dataGraph,
targetQueryFragment.getStatementMatchers(), List.of(), null, targetQueryFragment,
variables,
ConstraintComponent.Scope.propertyShape, true, null);
ConstraintComponent.Scope.propertyShape, true);

targetChainRetriever = connectionsGroup.getCachedNodeFor(targetChainRetriever);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,8 @@ public PlanNode getPlanNode(ConnectionsGroup connectionsGroup, Resource[] dataGr
? optional.getQueryFragment().getStatementMatchers()
: new ArrayList<>();

EffectiveTargetFragment rsxTarget = null;

if (chain.getFirst().target instanceof RSXTargetShape) {
rsxTarget = chain.getFirst();
System.out.println();
List<StatementMatcher> statementMatchers1 = sparqlFragments.get(0).getStatementMatchers();
statementMatchersRemoval.addAll(statementMatchers1);
statementMatchersRemoval.addAll(sparqlFragments.get(0).getStatementMatchers());
includeTargetsAffectedByRemoval = true;
}

Expand All @@ -295,7 +290,7 @@ public PlanNode getPlanNode(ConnectionsGroup connectionsGroup, Resource[] dataGr
fragment,
getVars(false),
scope,
false, rsxTarget);
false);
} else {
targetsPlanNode = new TargetChainRetriever(
connectionsGroup,
Expand All @@ -306,7 +301,7 @@ public PlanNode getPlanNode(ConnectionsGroup connectionsGroup, Resource[] dataGr
fragment,
getVars(false),
scope,
false, rsxTarget);
false);
}
} else {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private PlanNode getAddedRemovedInner(ConnectionsGroup connectionsGroup, Resourc
sparqlFragment,
vars,
scope,
false, null), false);
false), false);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -83,8 +84,7 @@ public class TargetChainRetriever implements PlanNode {
private final EffectiveTarget.EffectiveTargetFragment removedStatementTarget;
private final boolean hasValue;
private final Set<String> varNamesInQueryFragment;
private final EffectiveTarget.EffectiveTargetFragment rsxTarget;
private final List<StatementMatcher> originalStatementMatchers;
private final Set<StatementMatcher> originalStatementMatchers;

private final StackTraceElement[] stackTrace;
private ValidationExecutionLogger validationExecutionLogger;
Expand All @@ -93,15 +93,15 @@ public TargetChainRetriever(ConnectionsGroup connectionsGroup,
Resource[] dataGraph, List<StatementMatcher> statementMatchers,
List<StatementMatcher> removedStatementMatchers,
EffectiveTarget.EffectiveTargetFragment removedStatementTarget, SparqlFragment queryFragment,
List<Variable<Value>> vars, ConstraintComponent.Scope scope, boolean hasValue,
EffectiveTarget.EffectiveTargetFragment rsxTarget) {
List<Variable<Value>> vars, ConstraintComponent.Scope scope, boolean hasValue) {
this.connectionsGroup = connectionsGroup;
this.dataGraph = dataGraph;
this.varNames = vars.stream().map(StatementMatcher.Variable::getName).collect(Collectors.toSet());
assert !this.varNames.isEmpty();
this.dataset = PlanNodeHelper.asDefaultGraphDataset(this.dataGraph);
this.originalStatementMatchers = statementMatchers;
this.originalStatementMatchers = new HashSet<>(statementMatchers);
this.statementMatchers = StatementMatcher.reduce(statementMatchers);
assert originalStatementMatchers.containsAll(this.statementMatchers);

this.scope = scope;

Expand Down Expand Up @@ -130,12 +130,13 @@ public TargetChainRetriever(ConnectionsGroup connectionsGroup,
? StatementMatcher.reduce(removedStatementMatchers)
: Collections.emptyList();

assert removedStatementMatchers == null || removedStatementMatchers.containsAll(this.removedStatementMatchers);

this.removedStatementTarget = removedStatementTarget;

this.hasValue = hasValue;

assert scope == ConstraintComponent.Scope.propertyShape || !this.hasValue;
this.rsxTarget = rsxTarget;

}

Expand Down Expand Up @@ -330,8 +331,7 @@ private List<BindingSet> readStatementsInBulk(Set<String> variableNames) {
Stream<EffectiveTarget.StatementsAndMatcher> rootStatements = Stream
.of(new EffectiveTarget.StatementsAndMatcher(List.of(next), currentStatementMatcher));
if (removedStatement && removedStatementTarget != null) {

if (!statementMatchers.contains(currentStatementMatcher)) {
if (!originalStatementMatchers.contains(currentStatementMatcher)) {
// we only need to find the root if the currentStatementMatcher doesn't match anything in
// the query
Stream<EffectiveTarget.StatementsAndMatcher> root = removedStatementTarget.getRoot(
Expand All @@ -346,10 +346,6 @@ private List<BindingSet> readStatementsInBulk(Set<String> variableNames) {

}

List<EffectiveTarget.StatementsAndMatcher> collect = rootStatements.collect(Collectors.toList());

rootStatements = collect.stream();

rootStatements
.filter(EffectiveTarget.StatementsAndMatcher::hasStatements)
.flatMap(statementsAndMatcher -> {
Expand Down Expand Up @@ -390,16 +386,6 @@ private List<BindingSet> readStatementsInBulk(Set<String> variableNames) {
bindings[0].getValue());

} else {
Set<String> inheritedVarNames = newCurrentStatementMatcher
.getInheritedVarNames();
if (!inheritedVarNames.isEmpty() && variableNames.size() > 1) {
Set<String> varNames1 = newCurrentStatementMatcher.getVarNames();
if (variableNames.size() > varNames1.size()) {
System.out.println();
}

}

return new SimpleBindingSet(variableNames, bindings);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

package org.eclipse.rdf4j.sail.shacl;

import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT;
import static org.junit.jupiter.params.provider.Arguments.arguments;

import java.io.File;
Expand Down Expand Up @@ -83,6 +84,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.Isolated;
import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ 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#>

DELETE DATA {
ex:validPerson1 ex:info "red" .
INSERT DATA {
ex:validPerson1 ex:info "blue", "red" .
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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#>

DELETE DATA {
ex:validPerson1 ex:info "red" .
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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#>

DELETE DATA {
ex:validPerson1 ex:info "red" .
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@prefix ex: <http://example.com/ns#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rsx: <http://rdf4j.org/shacl-extensions#> .
@prefix rdf4j: <http://rdf4j.org/schema/rdf4j#> .

[] a sh:ValidationReport;
rdf4j:truncated false;
sh:conforms false;
sh:result [ a sh:ValidationResult;
rsx:shapesGraph rdf4j:SHACLShapeGraph;
sh:focusNode ex:validPerson1;
sh:resultPath ex:info2;
sh:resultSeverity sh:Violation;
sh:sourceConstraintComponent sh:MinCountConstraintComponent;
sh:sourceShape [ a sh:PropertyShape;
sh:minCount 1;
sh:path ex:info2
]
] .
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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:person1 ex:knows1 ex:person2.
ex:person2 ex:knows2 ex:person3.
ex:person3 ex:knows3 ex:person4.
ex:person4 ex:knows4 ex:person5.
ex:person5 ex:knows5 ex:person6.
ex:person6 rdf:type ex:Person, ex:NotPerson.


ex:person1 ex:knowsA ex:peter.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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#>

DELETE DATA {

ex:person5 ex:knows5 ex:person6.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@prefix ex: <http://example.com/ns#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rsx: <http://rdf4j.org/shacl-extensions#> .
@prefix rdf4j: <http://rdf4j.org/schema/rdf4j#> .

[] a sh:ValidationReport;
rdf4j:truncated false;
sh:conforms true .

0 comments on commit ecf4d06

Please sign in to comment.