aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeHierarchyPartialModelTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeHierarchyPartialModelTest.java')
-rw-r--r--subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeHierarchyPartialModelTest.java186
1 files changed, 186 insertions, 0 deletions
diff --git a/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeHierarchyPartialModelTest.java b/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeHierarchyPartialModelTest.java
new file mode 100644
index 00000000..cd9df19a
--- /dev/null
+++ b/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeHierarchyPartialModelTest.java
@@ -0,0 +1,186 @@
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.typehierarchy;
7
8import org.junit.jupiter.api.BeforeEach;
9import org.junit.jupiter.api.Test;
10import tools.refinery.store.model.Model;
11import tools.refinery.store.model.ModelStore;
12import tools.refinery.store.query.ModelQueryAdapter;
13import tools.refinery.store.query.viatra.ViatraModelQueryAdapter;
14import tools.refinery.store.reasoning.ReasoningAdapter;
15import tools.refinery.store.reasoning.ReasoningStoreAdapter;
16import tools.refinery.store.reasoning.literal.Concreteness;
17import tools.refinery.store.reasoning.representation.PartialRelation;
18import tools.refinery.store.reasoning.seed.ModelSeed;
19import tools.refinery.store.representation.TruthValue;
20import tools.refinery.store.tuple.Tuple;
21
22import static org.hamcrest.MatcherAssert.assertThat;
23import static org.hamcrest.Matchers.is;
24
25class TypeHierarchyPartialModelTest {
26 private final PartialRelation person = new PartialRelation("Person", 1);
27 private final PartialRelation member = new PartialRelation("Member", 1);
28 private final PartialRelation student = new PartialRelation("Student", 1);
29 private final PartialRelation teacher = new PartialRelation("Teacher", 1);
30 private final PartialRelation pet = new PartialRelation("Pet", 1);
31
32 private Model model;
33
34 @BeforeEach
35 void beforeEach() {
36 var typeHierarchy = TypeHierarchy.builder()
37 .type(person, true)
38 .type(member, true, person)
39 .type(student, member)
40 .type(teacher, member)
41 .type(pet)
42 .build();
43
44 var store = ModelStore.builder()
45 .with(ViatraModelQueryAdapter.builder())
46 .with(ReasoningAdapter.builder())
47 .with(new TypeHierarchyTranslator(typeHierarchy))
48 .build();
49
50 var seed = ModelSeed.builder(4)
51 .seed(person, builder -> builder
52 .reducedValue(TruthValue.UNKNOWN)
53 .put(Tuple.of(3), TruthValue.FALSE))
54 .seed(member, builder -> builder
55 .reducedValue(TruthValue.UNKNOWN)
56 .put(Tuple.of(1), TruthValue.TRUE)
57 .put(Tuple.of(2), TruthValue.TRUE))
58 .seed(student, builder -> builder
59 .reducedValue(TruthValue.UNKNOWN)
60 .put(Tuple.of(0), TruthValue.TRUE)
61 .put(Tuple.of(2), TruthValue.FALSE))
62 .seed(teacher, builder -> builder.reducedValue(TruthValue.UNKNOWN))
63 .seed(pet, builder -> builder.reducedValue(TruthValue.UNKNOWN))
64 .build();
65 model = store.getAdapter(ReasoningStoreAdapter.class).createInitialModel(seed);
66 }
67
68 @Test
69 void initialModelTest() {
70 var reasoningAdapter = model.getAdapter(ReasoningAdapter.class);
71
72 var personInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, person);
73 assertThat(personInterpretation.get(Tuple.of(0)), is(TruthValue.TRUE));
74 assertThat(personInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE));
75 assertThat(personInterpretation.get(Tuple.of(2)), is(TruthValue.TRUE));
76 assertThat(personInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
77
78 var memberInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, member);
79 assertThat(memberInterpretation.get(Tuple.of(0)), is(TruthValue.TRUE));
80 assertThat(memberInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE));
81 assertThat(memberInterpretation.get(Tuple.of(2)), is(TruthValue.TRUE));
82 assertThat(memberInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
83
84 var studentInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, student);
85 assertThat(studentInterpretation.get(Tuple.of(0)), is(TruthValue.TRUE));
86 assertThat(studentInterpretation.get(Tuple.of(1)), is(TruthValue.UNKNOWN));
87 assertThat(studentInterpretation.get(Tuple.of(2)), is(TruthValue.FALSE));
88 assertThat(studentInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
89
90 var teacherInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, teacher);
91 assertThat(teacherInterpretation.get(Tuple.of(0)), is(TruthValue.FALSE));
92 assertThat(teacherInterpretation.get(Tuple.of(1)), is(TruthValue.UNKNOWN));
93 assertThat(teacherInterpretation.get(Tuple.of(2)), is(TruthValue.TRUE));
94 assertThat(teacherInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
95
96 var petInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, pet);
97 assertThat(petInterpretation.get(Tuple.of(0)), is(TruthValue.FALSE));
98 assertThat(petInterpretation.get(Tuple.of(1)), is(TruthValue.FALSE));
99 assertThat(petInterpretation.get(Tuple.of(2)), is(TruthValue.FALSE));
100 assertThat(petInterpretation.get(Tuple.of(3)), is(TruthValue.UNKNOWN));
101 }
102
103 @Test
104 void initialModelCandidateTest() {
105 var reasoningAdapter = model.getAdapter(ReasoningAdapter.class);
106
107 var personCandidateInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.CANDIDATE, person);
108 assertThat(personCandidateInterpretation.get(Tuple.of(0)), is(TruthValue.TRUE));
109 assertThat(personCandidateInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE));
110 assertThat(personCandidateInterpretation.get(Tuple.of(2)), is(TruthValue.TRUE));
111 assertThat(personCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
112
113 var memberCandidateInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.CANDIDATE, member);
114 assertThat(memberCandidateInterpretation.get(Tuple.of(0)), is(TruthValue.TRUE));
115 assertThat(memberCandidateInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE));
116 assertThat(memberCandidateInterpretation.get(Tuple.of(2)), is(TruthValue.TRUE));
117 assertThat(memberCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
118
119 var studentCandidateInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.CANDIDATE, student);
120 assertThat(studentCandidateInterpretation.get(Tuple.of(0)), is(TruthValue.TRUE));
121 assertThat(studentCandidateInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE));
122 assertThat(studentCandidateInterpretation.get(Tuple.of(2)), is(TruthValue.FALSE));
123 assertThat(studentCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
124
125 var teacherCandidateInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.CANDIDATE, teacher);
126 assertThat(teacherCandidateInterpretation.get(Tuple.of(0)), is(TruthValue.FALSE));
127 assertThat(teacherCandidateInterpretation.get(Tuple.of(1)), is(TruthValue.FALSE));
128 assertThat(teacherCandidateInterpretation.get(Tuple.of(2)), is(TruthValue.TRUE));
129 assertThat(teacherCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
130
131 var petCandidateInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.CANDIDATE, pet);
132 assertThat(petCandidateInterpretation.get(Tuple.of(0)), is(TruthValue.FALSE));
133 assertThat(petCandidateInterpretation.get(Tuple.of(1)), is(TruthValue.FALSE));
134 assertThat(petCandidateInterpretation.get(Tuple.of(2)), is(TruthValue.FALSE));
135 assertThat(petCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
136 }
137
138 @Test
139 void refinedModelTest() {
140 var reasoningAdapter = model.getAdapter(ReasoningAdapter.class);
141 var studentRefiner = reasoningAdapter.getRefiner(student);
142 studentRefiner.merge(Tuple.of(1), TruthValue.FALSE);
143 studentRefiner.merge(Tuple.of(3), TruthValue.TRUE);
144 model.getAdapter(ModelQueryAdapter.class).flushChanges();
145
146 var personInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, person);
147 assertThat(personInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE));
148 assertThat(personInterpretation.get(Tuple.of(3)), is(TruthValue.ERROR));
149
150 var personCandidateInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.CANDIDATE, person);
151 assertThat(personCandidateInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE));
152 assertThat(personCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
153
154 var memberInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, member);
155 assertThat(memberInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE));
156 assertThat(memberInterpretation.get(Tuple.of(3)), is(TruthValue.ERROR));
157
158 var memberCandidateInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.CANDIDATE, member);
159 assertThat(memberCandidateInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE));
160 assertThat(memberCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
161
162 var studentInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, student);
163 assertThat(studentInterpretation.get(Tuple.of(1)), is(TruthValue.FALSE));
164 assertThat(studentInterpretation.get(Tuple.of(3)), is(TruthValue.ERROR));
165
166 var studentCandidateInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.CANDIDATE, student);
167 assertThat(studentCandidateInterpretation.get(Tuple.of(1)), is(TruthValue.FALSE));
168 assertThat(studentCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
169
170 var teacherInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, teacher);
171 assertThat(teacherInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE));
172 assertThat(teacherInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
173
174 var teacherCandidateInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.CANDIDATE, teacher);
175 assertThat(teacherCandidateInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE));
176 assertThat(teacherCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
177
178 var petInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, pet);
179 assertThat(petInterpretation.get(Tuple.of(1)), is(TruthValue.FALSE));
180 assertThat(petInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
181
182 var petCandidateInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.CANDIDATE, pet);
183 assertThat(petCandidateInterpretation.get(Tuple.of(1)), is(TruthValue.FALSE));
184 assertThat(petCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE));
185 }
186}