aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/containment/ContainmentHierarchyTranslator.java4
-rw-r--r--subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/containment/ContainsRefiner.java70
2 files changed, 1 insertions, 73 deletions
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/containment/ContainmentHierarchyTranslator.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/containment/ContainmentHierarchyTranslator.java
index eb112d0e..37eac022 100644
--- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/containment/ContainmentHierarchyTranslator.java
+++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/containment/ContainmentHierarchyTranslator.java
@@ -209,9 +209,7 @@ public class ContainmentHierarchyTranslator implements ModelStoreConfiguration {
209 })) 209 }))
210 .must(Query.of(mustName, (builder, parent, child) -> builder.clause( 210 .must(Query.of(mustName, (builder, parent, child) -> builder.clause(
211 new MustContainsView(containsStorage).call(parent, child) 211 new MustContainsView(containsStorage).call(parent, child)
212 ))) 212 ))));
213 .refiner(ContainsRefiner.of(containsStorage))
214 .initializer(new RefinementBasedInitializer<>(CONTAINS_SYMBOL)));
215 } 213 }
216 214
217 private void translateInvalidNumberOfContainers(ModelStoreBuilder storeBuilder) { 215 private void translateInvalidNumberOfContainers(ModelStoreBuilder storeBuilder) {
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/containment/ContainsRefiner.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/containment/ContainsRefiner.java
deleted file mode 100644
index b57ca095..00000000
--- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/containment/ContainsRefiner.java
+++ /dev/null
@@ -1,70 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.reasoning.translator.containment;
7
8import tools.refinery.store.model.Interpretation;
9import tools.refinery.store.reasoning.ReasoningAdapter;
10import tools.refinery.store.reasoning.refinement.AbstractPartialInterpretationRefiner;
11import tools.refinery.store.reasoning.refinement.PartialInterpretationRefiner;
12import tools.refinery.store.reasoning.representation.PartialSymbol;
13import tools.refinery.store.representation.Symbol;
14import tools.refinery.store.representation.TruthValue;
15import tools.refinery.store.tuple.Tuple;
16
17import java.util.Set;
18
19class ContainsRefiner extends AbstractPartialInterpretationRefiner<TruthValue, Boolean> {
20 private static final InferredContainment CONTAINS_TRUE = new InferredContainment(TruthValue.TRUE, Set.of(),
21 Set.of());
22 private static final InferredContainment CONTAINS_FALSE = new InferredContainment(TruthValue.FALSE, Set.of(),
23 Set.of());
24 private static final InferredContainment CONTAINS_ERROR = new InferredContainment(TruthValue.ERROR, Set.of(),
25 Set.of());
26
27 private final PartialInterpretationRefiner<TruthValue, Boolean> containedRefiner;
28 private final Interpretation<InferredContainment> interpretation;
29
30 public ContainsRefiner(ReasoningAdapter adapter, PartialSymbol<TruthValue, Boolean> partialSymbol,
31 Symbol<InferredContainment> symbol) {
32 super(adapter, partialSymbol);
33 containedRefiner = adapter.getRefiner(ContainmentHierarchyTranslator.CONTAINED_SYMBOL);
34 interpretation = adapter.getModel().getInterpretation(symbol);
35 }
36
37 @Override
38 public boolean merge(Tuple key, TruthValue value) {
39 var oldValue = interpretation.get(key);
40 var newValue = mergeContains(oldValue, value);
41 if (oldValue != newValue) {
42 interpretation.put(key, newValue);
43 }
44 if (value.must()) {
45 return containedRefiner.merge(Tuple.of(key.get(1)), TruthValue.TRUE);
46 }
47 return true;
48 }
49
50 public InferredContainment mergeContains(InferredContainment oldValue, TruthValue toMerge) {
51 var oldContains = oldValue.contains();
52 var newContains = oldContains.merge(toMerge);
53 if (newContains == oldContains) {
54 return oldValue;
55 }
56 if (oldValue.mustLinks().isEmpty() && oldValue.forbiddenLinks().isEmpty()) {
57 return switch (toMerge) {
58 case UNKNOWN -> oldValue;
59 case TRUE -> oldContains.may() ? CONTAINS_TRUE : CONTAINS_ERROR;
60 case FALSE -> oldContains.must() ? CONTAINS_ERROR : CONTAINS_FALSE;
61 case ERROR -> CONTAINS_ERROR;
62 };
63 }
64 return new InferredContainment(newContains, oldValue.mustLinks(), oldValue.forbiddenLinks());
65 }
66
67 public static Factory<TruthValue, Boolean> of(Symbol<InferredContainment> symbol) {
68 return (adapter, partialSymbol) -> new ContainsRefiner(adapter, partialSymbol, symbol);
69 }
70}