diff options
author | Kristóf Marussy <kristof@marussy.com> | 2023-08-27 02:13:15 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2023-08-27 02:13:15 +0200 |
commit | cca3b176cea8df8823094c105f612844b649647e (patch) | |
tree | 02e24ecd37228fe170a3b07e4e29570bf97732bf /subprojects/store-reasoning/src/test/java/tools | |
parent | chore(deps): bump frontend dependencies (diff) | |
download | refinery-cca3b176cea8df8823094c105f612844b649647e.tar.gz refinery-cca3b176cea8df8823094c105f612844b649647e.tar.zst refinery-cca3b176cea8df8823094c105f612844b649647e.zip |
fix: strong represenative election algorithm
Make sure to merge all clusters reachable from source and target.
Diffstat (limited to 'subprojects/store-reasoning/src/test/java/tools')
-rw-r--r-- | subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/containment/ContainmentHierarchyTranslatorTest.java | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/containment/ContainmentHierarchyTranslatorTest.java b/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/containment/ContainmentHierarchyTranslatorTest.java new file mode 100644 index 00000000..bbfaff84 --- /dev/null +++ b/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/containment/ContainmentHierarchyTranslatorTest.java | |||
@@ -0,0 +1,128 @@ | |||
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.translator.containment; | ||
7 | |||
8 | import org.junit.jupiter.api.BeforeEach; | ||
9 | import org.junit.jupiter.api.Test; | ||
10 | import tools.refinery.store.model.ModelStore; | ||
11 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; | ||
12 | import tools.refinery.store.reasoning.ReasoningAdapter; | ||
13 | import tools.refinery.store.reasoning.ReasoningStoreAdapter; | ||
14 | import tools.refinery.store.reasoning.literal.Concreteness; | ||
15 | import tools.refinery.store.reasoning.representation.PartialRelation; | ||
16 | import tools.refinery.store.reasoning.seed.ModelSeed; | ||
17 | import tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator; | ||
18 | import tools.refinery.store.reasoning.translator.multiplicity.UnconstrainedMultiplicity; | ||
19 | import tools.refinery.store.reasoning.translator.typehierarchy.TypeHierarchy; | ||
20 | import tools.refinery.store.reasoning.translator.typehierarchy.TypeHierarchyTranslator; | ||
21 | import tools.refinery.store.representation.TruthValue; | ||
22 | import tools.refinery.store.representation.cardinality.CardinalityIntervals; | ||
23 | import tools.refinery.store.tuple.Tuple; | ||
24 | |||
25 | import java.util.Map; | ||
26 | |||
27 | import static org.hamcrest.MatcherAssert.assertThat; | ||
28 | import static org.hamcrest.Matchers.is; | ||
29 | import static tools.refinery.store.reasoning.translator.containment.ContainmentHierarchyTranslator.CONTAINED_SYMBOL; | ||
30 | import static tools.refinery.store.reasoning.translator.containment.ContainmentHierarchyTranslator.CONTAINS_SYMBOL; | ||
31 | import static tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator.COUNT_SYMBOL; | ||
32 | |||
33 | class ContainmentHierarchyTranslatorTest { | ||
34 | private final PartialRelation c1 = new PartialRelation("C1", 1); | ||
35 | private final PartialRelation c2 = new PartialRelation("C2", 1); | ||
36 | private final PartialRelation entry = new PartialRelation("entry", 2); | ||
37 | |||
38 | private ModelStore store; | ||
39 | |||
40 | @BeforeEach | ||
41 | void beforeEach() { | ||
42 | |||
43 | var typeHierarchy = TypeHierarchy.builder() | ||
44 | .type(CONTAINED_SYMBOL, true) | ||
45 | .type(c1) | ||
46 | .type(c2, c1, CONTAINED_SYMBOL) | ||
47 | .build(); | ||
48 | |||
49 | var containmentHierarchy = Map.of( | ||
50 | entry, | ||
51 | new ContainmentInfo(c1, UnconstrainedMultiplicity.INSTANCE, c2) | ||
52 | ); | ||
53 | |||
54 | store = ModelStore.builder() | ||
55 | .with(ViatraModelQueryAdapter.builder()) | ||
56 | .with(ReasoningAdapter.builder()) | ||
57 | .with(new MultiObjectTranslator()) | ||
58 | .with(new TypeHierarchyTranslator(typeHierarchy)) | ||
59 | .with(new ContainmentHierarchyTranslator(containmentHierarchy)) | ||
60 | .build(); | ||
61 | } | ||
62 | |||
63 | @Test | ||
64 | void treeTest() { | ||
65 | var modelSeed = ModelSeed.builder(3) | ||
66 | .seed(COUNT_SYMBOL, builder -> builder.reducedValue(CardinalityIntervals.ONE)) | ||
67 | .seed(CONTAINED_SYMBOL, builder -> builder.reducedValue(TruthValue.UNKNOWN)) | ||
68 | .seed(CONTAINS_SYMBOL, builder -> builder.reducedValue(TruthValue.UNKNOWN)) | ||
69 | .seed(c1, builder -> builder | ||
70 | .reducedValue(TruthValue.UNKNOWN) | ||
71 | .put(Tuple.of(0), TruthValue.TRUE)) | ||
72 | .seed(c2, builder -> builder | ||
73 | .put(Tuple.of(1), TruthValue.TRUE) | ||
74 | .put(Tuple.of(2), TruthValue.TRUE)) | ||
75 | .seed(entry, builder -> builder | ||
76 | .reducedValue(TruthValue.UNKNOWN) | ||
77 | .put(Tuple.of(0, 1), TruthValue.TRUE) | ||
78 | .put(Tuple.of(0, 2), TruthValue.TRUE)) | ||
79 | .build(); | ||
80 | |||
81 | var model = store.getAdapter(ReasoningStoreAdapter.class).createInitialModel(modelSeed); | ||
82 | var interpretation = model.getAdapter(ReasoningAdapter.class).getPartialInterpretation(Concreteness.PARTIAL, | ||
83 | entry); | ||
84 | |||
85 | assertThat(interpretation.get(Tuple.of(0, 0)), is(TruthValue.FALSE)); | ||
86 | assertThat(interpretation.get(Tuple.of(0, 1)), is(TruthValue.TRUE)); | ||
87 | assertThat(interpretation.get(Tuple.of(0, 2)), is(TruthValue.TRUE)); | ||
88 | assertThat(interpretation.get(Tuple.of(1, 0)), is(TruthValue.FALSE)); | ||
89 | assertThat(interpretation.get(Tuple.of(1, 1)), is(TruthValue.FALSE)); | ||
90 | assertThat(interpretation.get(Tuple.of(1, 2)), is(TruthValue.FALSE)); | ||
91 | assertThat(interpretation.get(Tuple.of(2, 0)), is(TruthValue.FALSE)); | ||
92 | assertThat(interpretation.get(Tuple.of(2, 1)), is(TruthValue.FALSE)); | ||
93 | assertThat(interpretation.get(Tuple.of(2, 2)), is(TruthValue.FALSE)); | ||
94 | } | ||
95 | |||
96 | @Test | ||
97 | void loopTest() { | ||
98 | var modelSeed = ModelSeed.builder(3) | ||
99 | .seed(COUNT_SYMBOL, builder -> builder.reducedValue(CardinalityIntervals.ONE)) | ||
100 | .seed(CONTAINED_SYMBOL, builder -> builder.reducedValue(TruthValue.UNKNOWN)) | ||
101 | .seed(CONTAINS_SYMBOL, builder -> builder.reducedValue(TruthValue.UNKNOWN)) | ||
102 | .seed(c1, builder -> builder.reducedValue(TruthValue.UNKNOWN)) | ||
103 | .seed(c2, builder -> builder | ||
104 | .put(Tuple.of(0), TruthValue.TRUE) | ||
105 | .put(Tuple.of(1), TruthValue.TRUE) | ||
106 | .put(Tuple.of(2), TruthValue.TRUE)) | ||
107 | .seed(entry, builder -> builder | ||
108 | .reducedValue(TruthValue.UNKNOWN) | ||
109 | .put(Tuple.of(0, 1), TruthValue.TRUE) | ||
110 | .put(Tuple.of(1, 2), TruthValue.TRUE) | ||
111 | .put(Tuple.of(2, 0), TruthValue.TRUE)) | ||
112 | .build(); | ||
113 | |||
114 | var model = store.getAdapter(ReasoningStoreAdapter.class).createInitialModel(modelSeed); | ||
115 | var interpretation = model.getAdapter(ReasoningAdapter.class).getPartialInterpretation(Concreteness.PARTIAL, | ||
116 | entry); | ||
117 | |||
118 | assertThat(interpretation.get(Tuple.of(0, 0)), is(TruthValue.FALSE)); | ||
119 | assertThat(interpretation.get(Tuple.of(0, 1)), is(TruthValue.ERROR)); | ||
120 | assertThat(interpretation.get(Tuple.of(0, 2)), is(TruthValue.FALSE)); | ||
121 | assertThat(interpretation.get(Tuple.of(1, 0)), is(TruthValue.FALSE)); | ||
122 | assertThat(interpretation.get(Tuple.of(1, 1)), is(TruthValue.FALSE)); | ||
123 | assertThat(interpretation.get(Tuple.of(1, 2)), is(TruthValue.ERROR)); | ||
124 | assertThat(interpretation.get(Tuple.of(2, 0)), is(TruthValue.ERROR)); | ||
125 | assertThat(interpretation.get(Tuple.of(2, 1)), is(TruthValue.FALSE)); | ||
126 | assertThat(interpretation.get(Tuple.of(2, 2)), is(TruthValue.FALSE)); | ||
127 | } | ||
128 | } | ||