Skip to content

Commit

Permalink
code cleanup (+1 squashed commit)
Browse files Browse the repository at this point in the history
Squashed commits:
[fff7976510] code cleanup
  • Loading branch information
hmottestad committed Dec 25, 2023
1 parent a05a684 commit 72813eb
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*******************************************************************************
* Copyright (c) 2020 Eclipse RDF4J contributors.
* Copyright (c) 2023 Eclipse RDF4J contributors.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
******************************************************************************/

package org.eclipse.rdf4j.sail.shacl.ast.constraintcomponents;

Expand Down Expand Up @@ -49,11 +49,17 @@ public AbstractPairwiseConstraintComponent(IRI predicate, Shape shape) {
this.shape = shape;
}

abstract IRI getIRI();
/**
* The abstract method that is implemented by the subclasses to return the IRI of the constraint component, e.g.
* sh:equals, sh:disjoint etc.
*
* @return The IRI of the constraint component
*/
abstract IRI getConstraintIri();

@Override
public void toModel(Resource subject, IRI predicate, Model model, Set<Resource> cycleDetection) {
model.add(subject, getIRI(), this.predicate);
model.add(subject, getConstraintIri(), this.predicate);
}

@Override
Expand Down Expand Up @@ -112,6 +118,18 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
return getPairwiseCheck(connectionsGroup, validationSettings, allTargets, subject, object, targetQueryFragment);
}

/**
* The abstract method that is implemented by the subclasses to add the pairwise check as a PlanNode to the
* validation plan.
*
* @param connectionsGroup
* @param validationSettings
* @param allTargets
* @param subject
* @param object
* @param targetQueryFragment
* @return The PlanNode that performs the pairwise check
*/
abstract PlanNode getPairwiseCheck(ConnectionsGroup connectionsGroup, ValidationSettings validationSettings,
PlanNode allTargets, StatementMatcher.Variable<Resource> subject, StatementMatcher.Variable<Value> object,
SparqlFragment targetQueryFragment);
Expand All @@ -136,55 +154,6 @@ private PlanNode getAllTargetsBasedOnPredicate(ConnectionsGroup connectionsGroup
return Unique.getInstance(UnionNode.getInstance(targetFilter1, targetFilter2), false);
}

// @Override
// public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
// StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
// assert scope == Scope.propertyShape;
//
// PlanNode allTargetsPlan = getTargetChain()
// .getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(),
// stableRandomVariableProvider)
// .getPlanNode(connectionsGroup, dataGraph, Scope.nodeShape, true, null);
//
// allTargetsPlan = new ShiftToPropertyShape(allTargetsPlan);
//
// // removed statements that match predicate could affect sh:or
// if (connectionsGroup.getStats().hasRemoved()) {
// PlanNode deletedPredicates = new UnorderedSelect(connectionsGroup.getRemovedStatements(), null, predicate,
// null, dataGraph, UnorderedSelect.Mapper.SubjectScopedMapper.getFunction(Scope.propertyShape));
// deletedPredicates = getTargetChain()
// .getEffectiveTarget(Scope.propertyShape, connectionsGroup.getRdfsSubClassOfReasoner(),
// stableRandomVariableProvider)
// .getTargetFilter(connectionsGroup, dataGraph, deletedPredicates);
// deletedPredicates = getTargetChain()
// .getEffectiveTarget(Scope.propertyShape, connectionsGroup.getRdfsSubClassOfReasoner(),
// stableRandomVariableProvider)
// .extend(deletedPredicates, connectionsGroup, dataGraph, Scope.propertyShape, EffectiveTarget.Extend.left,
// false,
// null);
// allTargetsPlan = UnionNode.getInstanceDedupe(allTargetsPlan, deletedPredicates);
// }
//
// // added statements that match predicate could affect sh:not
// if (connectionsGroup.getStats().hasAdded()) {
// PlanNode addedPredicates = new UnorderedSelect(connectionsGroup.getAddedStatements(), null, predicate,
// null, dataGraph, UnorderedSelect.Mapper.SubjectScopedMapper.getFunction(Scope.propertyShape));
// addedPredicates = getTargetChain()
// .getEffectiveTarget(Scope.propertyShape, connectionsGroup.getRdfsSubClassOfReasoner(),
// stableRandomVariableProvider)
// .getTargetFilter(connectionsGroup, dataGraph, addedPredicates);
// addedPredicates = getTargetChain()
// .getEffectiveTarget(Scope.propertyShape, connectionsGroup.getRdfsSubClassOfReasoner(),
// stableRandomVariableProvider)
// .extend(addedPredicates, connectionsGroup, dataGraph, Scope.propertyShape, EffectiveTarget.Extend.left,
// false,
// null);
// allTargetsPlan = UnionNode.getInstanceDedupe(allTargetsPlan, addedPredicates);
// }
//
// return Unique.getInstance(new TrimToTarget(allTargetsPlan), false);
// }

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
Expand Down Expand Up @@ -291,26 +260,6 @@ public boolean requiresEvaluation(ConnectionsGroup connectionsGroup, Scope scope
|| connectionsGroup.getAddedStatements().hasStatement(null, predicate, null, true, dataGraph);
}

@Override
public ValidationApproach getPreferredValidationApproach(ConnectionsGroup connectionsGroup) {
return ValidationApproach.Transactional;
}

@Override
public ValidationApproach getOptimalBulkValidationApproach() {
return ValidationApproach.Transactional;
}

@Override
public ConstraintComponent deepClone() {
throw new UnsupportedOperationException();
}

@Override
public List<Literal> getDefaultMessage() {
return List.of();
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -327,7 +276,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return predicate.hashCode() + "LessThanConstraintComponent".hashCode();
return predicate.hashCode() + "AbstractPairwiseConstraintComponent".hashCode();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public DisjointConstraintComponent(IRI predicate, Shape shape) {
}

@Override
IRI getIRI() {
IRI getConstraintIri() {
return SHACL.DISJOINT;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public EqualsConstraintComponent(IRI predicate, Shape shape) {
}

@Override
IRI getIRI() {
IRI getConstraintIri() {
return SHACL.EQUALS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public LessThanConstraintComponent(IRI predicate, Shape shape) {
}

@Override
IRI getIRI() {
IRI getConstraintIri() {
return SHACL.LESS_THAN;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public LessThanOrEqualsConstraintComponent(IRI predicate, Shape shape) {
}

@Override
IRI getIRI() {
IRI getConstraintIri() {
return SHACL.LESS_THAN_OR_EQUALS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@

import com.google.common.collect.Sets;

/**
* Used by sh:equals to return any targets and values where the target has values by path that are not values by the
* predicate, or vice versa. It returns the targets and any symmetricDifference values when comparing the set of values
* by path and by predicate.
*
* @author Håvard Ottestad
*/
public class CheckDisjointValuesBasedOnPathAndPredicate extends AbstractPairwisePlanNode {

public CheckDisjointValuesBasedOnPathAndPredicate(SailConnection connection, Resource[] dataGraph, PlanNode parent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,14 @@
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.query.algebra.Compare;
import org.eclipse.rdf4j.query.algebra.evaluation.util.QueryEvaluationUtility;
import org.eclipse.rdf4j.query.algebra.evaluation.util.ValueComparator;
import org.eclipse.rdf4j.sail.SailConnection;
import org.eclipse.rdf4j.sail.shacl.ast.Shape;
import org.eclipse.rdf4j.sail.shacl.ast.SparqlFragment;
import org.eclipse.rdf4j.sail.shacl.ast.StatementMatcher;
import org.eclipse.rdf4j.sail.shacl.ast.constraintcomponents.ConstraintComponent;

/**
* Used by sh:equals to return any targets and values where the target has values by path that are not values by the
* predicate, or vice versa. It returns the targets and any symmetricDifference values when comparing the set of values
* by path and by predicate.
*
* @author Håvard Ottestad
*/
public class CheckLessThanOrEqualValuesBasedOnPathAndPredicate extends AbstractPairwisePlanNode {

private final ValueComparator valueComparator = new ValueComparator();

public CheckLessThanOrEqualValuesBasedOnPathAndPredicate(SailConnection connection, Resource[] dataGraph,
PlanNode parent, IRI predicate, StatementMatcher.Variable<Resource> subject,
StatementMatcher.Variable<Value> object, SparqlFragment targetQueryFragment, Shape shape,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@
import org.eclipse.rdf4j.sail.shacl.ast.StatementMatcher;
import org.eclipse.rdf4j.sail.shacl.ast.constraintcomponents.ConstraintComponent;

/**
* Used by sh:equals to return any targets and values where the target has values by path that are not values by the
* predicate, or vice versa. It returns the targets and any symmetricDifference values when comparing the set of values
* by path and by predicate.
*
* @author Håvard Ottestad
*/
public class CheckLessThanValuesBasedOnPathAndPredicate extends AbstractPairwisePlanNode {

private final ValueComparator valueComparator = new ValueComparator();
Expand Down

0 comments on commit 72813eb

Please sign in to comment.