diff options
author | Kristóf Marussy <kristof@marussy.com> | 2023-06-18 18:49:32 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2023-06-18 18:49:32 +0200 |
commit | a85681f1bbbf45eb30cc6ae81d881f45492f2b3f (patch) | |
tree | 94347b92b67f577ebda56e87ed14d2c626c2fbe7 /subprojects/store-reasoning | |
parent | chore: .yarnrc.yml license (diff) | |
download | refinery-a85681f1bbbf45eb30cc6ae81d881f45492f2b3f.tar.gz refinery-a85681f1bbbf45eb30cc6ae81d881f45492f2b3f.tar.zst refinery-a85681f1bbbf45eb30cc6ae81d881f45492f2b3f.zip |
refactor: remove Rule
We will need to rework rule execution according to recent Dnf changes.
Diffstat (limited to 'subprojects/store-reasoning')
5 files changed, 0 insertions, 155 deletions
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 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.reasoning.rule; | ||
7 | |||
8 | import tools.refinery.store.reasoning.ReasoningAdapter; | ||
9 | import tools.refinery.store.reasoning.representation.PartialRelation; | ||
10 | import tools.refinery.store.model.Model; | ||
11 | import tools.refinery.store.query.term.Variable; | ||
12 | import tools.refinery.store.representation.TruthValue; | ||
13 | import tools.refinery.store.tuple.Tuple; | ||
14 | |||
15 | import java.util.List; | ||
16 | |||
17 | public record RelationRefinementAction(PartialRelation target, List<Variable> arguments, TruthValue value) | ||
18 | implements RuleAction { | ||
19 | public RelationRefinementAction { | ||
20 | if (arguments.size() != target.arity()) { | ||
21 | throw new IllegalArgumentException("%s needs %d parameters, but got %s".formatted(target.name(), | ||
22 | target.arity(), arguments.size())); | ||
23 | } | ||
24 | if (value == TruthValue.UNKNOWN) { | ||
25 | throw new IllegalArgumentException("Refining with UNKNOWN has no effect"); | ||
26 | } | ||
27 | } | ||
28 | |||
29 | @Override | ||
30 | public RuleActionExecutor createExecutor(int[] argumentIndices, Model model) { | ||
31 | var targetInterpretation = model.getAdapter(ReasoningAdapter.class).getPartialInterpretation(target); | ||
32 | return activationTuple -> { | ||
33 | int arity = argumentIndices.length; | ||
34 | var arguments = new int[arity]; | ||
35 | for (int i = 0; i < arity; i++) { | ||
36 | arguments[i] = activationTuple.get(argumentIndices[i]); | ||
37 | } | ||
38 | return targetInterpretation.merge(Tuple.of(arguments), value); | ||
39 | }; | ||
40 | } | ||
41 | } | ||
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 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.reasoning.rule; | ||
7 | |||
8 | import tools.refinery.store.model.Model; | ||
9 | import tools.refinery.store.query.dnf.Dnf; | ||
10 | |||
11 | import java.util.ArrayList; | ||
12 | import java.util.HashSet; | ||
13 | import java.util.List; | ||
14 | |||
15 | public record Rule(Dnf precondition, List<RuleAction> actions) { | ||
16 | public Rule { | ||
17 | var parameterSet = new HashSet<>(precondition.getParameters()); | ||
18 | for (var action : actions) { | ||
19 | for (var argument : action.arguments()) { | ||
20 | if (!parameterSet.contains(argument)) { | ||
21 | throw new IllegalArgumentException( | ||
22 | "Argument %s of action %s does not appear in the parameter list %s of %s" | ||
23 | .formatted(argument, action, precondition.getParameters(), precondition.name())); | ||
24 | } | ||
25 | } | ||
26 | } | ||
27 | } | ||
28 | |||
29 | public RuleExecutor createExecutor(Model model) { | ||
30 | var parameters = precondition.getParameters(); | ||
31 | var actionExecutors = new ArrayList<RuleActionExecutor>(actions.size()); | ||
32 | for (var action : actions) { | ||
33 | var arguments = action.arguments(); | ||
34 | int arity = arguments.size(); | ||
35 | var argumentIndices = new int[arity]; | ||
36 | for (int i = 0; i < arity; i++) { | ||
37 | argumentIndices[i] = parameters.indexOf(arguments.get(i)); | ||
38 | } | ||
39 | actionExecutors.add(action.createExecutor(argumentIndices, model)); | ||
40 | } | ||
41 | return new RuleExecutor(this, model, actionExecutors); | ||
42 | } | ||
43 | } | ||
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 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.reasoning.rule; | ||
7 | |||
8 | import tools.refinery.store.model.Model; | ||
9 | import tools.refinery.store.query.term.Variable; | ||
10 | |||
11 | import java.util.List; | ||
12 | |||
13 | public interface RuleAction { | ||
14 | List<Variable> arguments(); | ||
15 | |||
16 | RuleActionExecutor createExecutor(int[] argumentIndices, Model model); | ||
17 | } | ||
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 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.reasoning.rule; | ||
7 | |||
8 | import tools.refinery.store.reasoning.MergeResult; | ||
9 | import tools.refinery.store.tuple.Tuple; | ||
10 | |||
11 | @FunctionalInterface | ||
12 | public interface RuleActionExecutor { | ||
13 | MergeResult execute(Tuple activationTuple); | ||
14 | } | ||
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 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.reasoning.rule; | ||
7 | |||
8 | import tools.refinery.store.model.Model; | ||
9 | import tools.refinery.store.reasoning.MergeResult; | ||
10 | import tools.refinery.store.tuple.Tuple; | ||
11 | |||
12 | import java.util.List; | ||
13 | |||
14 | public final class RuleExecutor { | ||
15 | private final Rule rule; | ||
16 | private final Model model; | ||
17 | private final List<RuleActionExecutor> actionExecutors; | ||
18 | |||
19 | RuleExecutor(Rule rule, Model model, List<RuleActionExecutor> actionExecutors) { | ||
20 | this.rule = rule; | ||
21 | this.model = model; | ||
22 | this.actionExecutors = actionExecutors; | ||
23 | } | ||
24 | |||
25 | public Rule getRule() { | ||
26 | return rule; | ||
27 | } | ||
28 | |||
29 | public Model getModel() { | ||
30 | return model; | ||
31 | } | ||
32 | |||
33 | public MergeResult execute(Tuple activationTuple) { | ||
34 | MergeResult mergeResult = MergeResult.UNCHANGED; | ||
35 | for (var actionExecutor : actionExecutors) { | ||
36 | mergeResult = mergeResult.andAlso(actionExecutor.execute(activationTuple)); | ||
37 | } | ||
38 | return mergeResult; | ||
39 | } | ||
40 | } | ||