From a85681f1bbbf45eb30cc6ae81d881f45492f2b3f Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sun, 18 Jun 2023 18:49:32 +0200 Subject: refactor: remove Rule We will need to rework rule execution according to recent Dnf changes. --- .../reasoning/rule/RelationRefinementAction.java | 41 --------------------- .../tools/refinery/store/reasoning/rule/Rule.java | 43 ---------------------- .../refinery/store/reasoning/rule/RuleAction.java | 17 --------- .../store/reasoning/rule/RuleActionExecutor.java | 14 ------- .../store/reasoning/rule/RuleExecutor.java | 40 -------------------- 5 files changed, 155 deletions(-) delete mode 100644 subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RelationRefinementAction.java delete mode 100644 subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/Rule.java delete mode 100644 subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RuleAction.java delete mode 100644 subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RuleActionExecutor.java delete mode 100644 subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RuleExecutor.java (limited to 'subprojects') diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RelationRefinementAction.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RelationRefinementAction.java deleted file mode 100644 index 0beee248..00000000 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RelationRefinementAction.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors - * - * SPDX-License-Identifier: EPL-2.0 - */ -package tools.refinery.store.reasoning.rule; - -import tools.refinery.store.reasoning.ReasoningAdapter; -import tools.refinery.store.reasoning.representation.PartialRelation; -import tools.refinery.store.model.Model; -import tools.refinery.store.query.term.Variable; -import tools.refinery.store.representation.TruthValue; -import tools.refinery.store.tuple.Tuple; - -import java.util.List; - -public record RelationRefinementAction(PartialRelation target, List arguments, TruthValue value) - implements RuleAction { - public RelationRefinementAction { - if (arguments.size() != target.arity()) { - throw new IllegalArgumentException("%s needs %d parameters, but got %s".formatted(target.name(), - target.arity(), arguments.size())); - } - if (value == TruthValue.UNKNOWN) { - throw new IllegalArgumentException("Refining with UNKNOWN has no effect"); - } - } - - @Override - public RuleActionExecutor createExecutor(int[] argumentIndices, Model model) { - var targetInterpretation = model.getAdapter(ReasoningAdapter.class).getPartialInterpretation(target); - return activationTuple -> { - int arity = argumentIndices.length; - var arguments = new int[arity]; - for (int i = 0; i < arity; i++) { - arguments[i] = activationTuple.get(argumentIndices[i]); - } - return targetInterpretation.merge(Tuple.of(arguments), value); - }; - } -} diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/Rule.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/Rule.java deleted file mode 100644 index 45b0f02e..00000000 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/Rule.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors - * - * SPDX-License-Identifier: EPL-2.0 - */ -package tools.refinery.store.reasoning.rule; - -import tools.refinery.store.model.Model; -import tools.refinery.store.query.dnf.Dnf; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; - -public record Rule(Dnf precondition, List actions) { - public Rule { - var parameterSet = new HashSet<>(precondition.getParameters()); - for (var action : actions) { - for (var argument : action.arguments()) { - if (!parameterSet.contains(argument)) { - throw new IllegalArgumentException( - "Argument %s of action %s does not appear in the parameter list %s of %s" - .formatted(argument, action, precondition.getParameters(), precondition.name())); - } - } - } - } - - public RuleExecutor createExecutor(Model model) { - var parameters = precondition.getParameters(); - var actionExecutors = new ArrayList(actions.size()); - for (var action : actions) { - var arguments = action.arguments(); - int arity = arguments.size(); - var argumentIndices = new int[arity]; - for (int i = 0; i < arity; i++) { - argumentIndices[i] = parameters.indexOf(arguments.get(i)); - } - actionExecutors.add(action.createExecutor(argumentIndices, model)); - } - return new RuleExecutor(this, model, actionExecutors); - } -} diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RuleAction.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RuleAction.java deleted file mode 100644 index 97ea7313..00000000 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RuleAction.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors - * - * SPDX-License-Identifier: EPL-2.0 - */ -package tools.refinery.store.reasoning.rule; - -import tools.refinery.store.model.Model; -import tools.refinery.store.query.term.Variable; - -import java.util.List; - -public interface RuleAction { - List arguments(); - - RuleActionExecutor createExecutor(int[] argumentIndices, Model model); -} diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RuleActionExecutor.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RuleActionExecutor.java deleted file mode 100644 index 5d743869..00000000 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RuleActionExecutor.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors - * - * SPDX-License-Identifier: EPL-2.0 - */ -package tools.refinery.store.reasoning.rule; - -import tools.refinery.store.reasoning.MergeResult; -import tools.refinery.store.tuple.Tuple; - -@FunctionalInterface -public interface RuleActionExecutor { - MergeResult execute(Tuple activationTuple); -} diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RuleExecutor.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RuleExecutor.java deleted file mode 100644 index 32cf13ea..00000000 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RuleExecutor.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors - * - * SPDX-License-Identifier: EPL-2.0 - */ -package tools.refinery.store.reasoning.rule; - -import tools.refinery.store.model.Model; -import tools.refinery.store.reasoning.MergeResult; -import tools.refinery.store.tuple.Tuple; - -import java.util.List; - -public final class RuleExecutor { - private final Rule rule; - private final Model model; - private final List actionExecutors; - - RuleExecutor(Rule rule, Model model, List actionExecutors) { - this.rule = rule; - this.model = model; - this.actionExecutors = actionExecutors; - } - - public Rule getRule() { - return rule; - } - - public Model getModel() { - return model; - } - - public MergeResult execute(Tuple activationTuple) { - MergeResult mergeResult = MergeResult.UNCHANGED; - for (var actionExecutor : actionExecutors) { - mergeResult = mergeResult.andAlso(actionExecutor.execute(activationTuple)); - } - return mergeResult; - } -} -- cgit v1.2.3-54-g00ecf