diff options
Diffstat (limited to 'subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/actions/MergeActionLiteral.java')
-rw-r--r-- | subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/actions/MergeActionLiteral.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/actions/MergeActionLiteral.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/actions/MergeActionLiteral.java new file mode 100644 index 00000000..8d0d7961 --- /dev/null +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/actions/MergeActionLiteral.java | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.reasoning.actions; | ||
7 | |||
8 | import tools.refinery.store.dse.transition.actions.AbstractActionLiteral; | ||
9 | import tools.refinery.store.dse.transition.actions.BoundActionLiteral; | ||
10 | import tools.refinery.store.model.Model; | ||
11 | import tools.refinery.store.query.term.NodeVariable; | ||
12 | import tools.refinery.store.reasoning.ReasoningAdapter; | ||
13 | import tools.refinery.store.reasoning.representation.PartialSymbol; | ||
14 | import tools.refinery.store.tuple.Tuple; | ||
15 | |||
16 | import java.util.List; | ||
17 | |||
18 | public class MergeActionLiteral<A, C> extends AbstractActionLiteral { | ||
19 | private final PartialSymbol<A, C> partialSymbol; | ||
20 | private final List<NodeVariable> parameters; | ||
21 | private final A value; | ||
22 | |||
23 | public MergeActionLiteral(PartialSymbol<A, C> partialSymbol, A value, List<NodeVariable> parameters) { | ||
24 | if (partialSymbol.arity() != parameters.size()) { | ||
25 | throw new IllegalArgumentException("Expected %d parameters for partial symbol %s, got %d instead" | ||
26 | .formatted(partialSymbol.arity(), partialSymbol, parameters.size())); | ||
27 | } | ||
28 | this.partialSymbol = partialSymbol; | ||
29 | this.parameters = parameters; | ||
30 | this.value = value; | ||
31 | } | ||
32 | |||
33 | public PartialSymbol<A, C> getPartialSymbol() { | ||
34 | return partialSymbol; | ||
35 | } | ||
36 | |||
37 | public List<NodeVariable> getParameters() { | ||
38 | return parameters; | ||
39 | } | ||
40 | |||
41 | public A getValue() { | ||
42 | return value; | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public List<NodeVariable> getInputVariables() { | ||
47 | return getParameters(); | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public List<NodeVariable> getOutputVariables() { | ||
52 | return List.of(); | ||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public BoundActionLiteral bindToModel(Model model) { | ||
57 | var refiner = model.getAdapter(ReasoningAdapter.class).getRefiner(partialSymbol); | ||
58 | return tuple -> refiner.merge(tuple, value) ? Tuple.of() : null; | ||
59 | } | ||
60 | } | ||