diff options
author | 2023-01-23 20:27:55 +0100 | |
---|---|---|
committer | 2023-01-29 00:02:28 +0100 | |
commit | d91acf3690682d243dbc150df902525b6e545c2f (patch) | |
tree | f39695cc193828df0b78030b5a56bd968e277457 /subprojects/store-query-viatra/src/test | |
parent | chore(deps): bump dependencies (diff) | |
download | refinery-d91acf3690682d243dbc150df902525b6e545c2f.tar.gz refinery-d91acf3690682d243dbc150df902525b6e545c2f.tar.zst refinery-d91acf3690682d243dbc150df902525b6e545c2f.zip |
refactor: Model store and query API
Use Adapters to simplify API usage.
Diffstat (limited to 'subprojects/store-query-viatra/src/test')
4 files changed, 370 insertions, 275 deletions
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTest.java index e82e006c..72e8d7e5 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTest.java | |||
@@ -1,17 +1,20 @@ | |||
1 | package tools.refinery.store.query.viatra; | 1 | package tools.refinery.store.query.viatra; |
2 | 2 | ||
3 | import org.junit.jupiter.api.Test; | 3 | import org.junit.jupiter.api.Test; |
4 | import tools.refinery.store.model.representation.Relation; | 4 | import tools.refinery.store.model.ModelStore; |
5 | import tools.refinery.store.model.representation.TruthValue; | 5 | import tools.refinery.store.query.DNF; |
6 | import tools.refinery.store.query.*; | 6 | import tools.refinery.store.query.ModelQuery; |
7 | import tools.refinery.store.query.Variable; | ||
7 | import tools.refinery.store.query.atom.*; | 8 | import tools.refinery.store.query.atom.*; |
8 | import tools.refinery.store.query.view.FilteredRelationView; | 9 | import tools.refinery.store.query.view.FilteredRelationView; |
9 | import tools.refinery.store.query.view.KeyOnlyRelationView; | 10 | import tools.refinery.store.query.view.KeyOnlyRelationView; |
10 | import tools.refinery.store.query.view.RelationView; | 11 | import tools.refinery.store.representation.Symbol; |
12 | import tools.refinery.store.representation.TruthValue; | ||
11 | import tools.refinery.store.tuple.Tuple; | 13 | import tools.refinery.store.tuple.Tuple; |
12 | import tools.refinery.store.tuple.TupleLike; | 14 | import tools.refinery.store.tuple.TupleLike; |
13 | 15 | ||
14 | import java.util.*; | 16 | import java.util.HashSet; |
17 | import java.util.Set; | ||
15 | import java.util.stream.Stream; | 18 | import java.util.stream.Stream; |
16 | 19 | ||
17 | import static org.junit.jupiter.api.Assertions.assertEquals; | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; |
@@ -19,41 +22,49 @@ import static org.junit.jupiter.api.Assertions.assertEquals; | |||
19 | class QueryTest { | 22 | class QueryTest { |
20 | @Test | 23 | @Test |
21 | void typeConstraintTest() { | 24 | void typeConstraintTest() { |
22 | Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false); | 25 | var person = new Symbol<>("Person", 1, Boolean.class, false); |
23 | Relation<Boolean> asset = new Relation<>("Asset", 1, Boolean.class, false); | 26 | var asset = new Symbol<>("Asset", 1, Boolean.class, false); |
24 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 27 | var personView = new KeyOnlyRelationView<>(person); |
25 | 28 | ||
26 | var p1 = new Variable("p1"); | 29 | var p1 = new Variable("p1"); |
27 | DNF predicate = DNF.builder("TypeConstraint") | 30 | var predicate = DNF.builder("TypeConstraint") |
28 | .parameters(p1) | 31 | .parameters(p1) |
29 | .clause(new RelationViewAtom(personView, p1)) | 32 | .clause(new RelationViewAtom(personView, p1)) |
30 | .build(); | 33 | .build(); |
31 | 34 | ||
32 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, asset), Set.of(personView), | 35 | var store = ModelStore.builder() |
33 | Set.of(predicate)); | 36 | .symbols(person, asset) |
34 | QueryableModel model = store.createModel(); | 37 | .with(ViatraModelQuery.ADAPTER) |
38 | .queries(predicate) | ||
39 | .build(); | ||
40 | |||
41 | var model = store.createModel(); | ||
42 | var personInterpretation = model.getInterpretation(person); | ||
43 | var assetInterpretation = model.getInterpretation(asset); | ||
44 | var queryEngine = model.getAdapter(ModelQuery.ADAPTER); | ||
45 | var predicateResultSet = queryEngine.getResultSet(predicate); | ||
35 | 46 | ||
36 | model.put(person, Tuple.of(0), true); | 47 | personInterpretation.put(Tuple.of(0), true); |
37 | model.put(person, Tuple.of(1), true); | 48 | personInterpretation.put(Tuple.of(1), true); |
38 | model.put(asset, Tuple.of(1), true); | ||
39 | model.put(asset, Tuple.of(2), true); | ||
40 | 49 | ||
41 | model.flushChanges(); | 50 | assetInterpretation.put(Tuple.of(1), true); |
42 | assertEquals(2, model.countResults(predicate)); | 51 | assetInterpretation.put(Tuple.of(2), true); |
43 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0), Tuple.of(1))); | 52 | |
53 | queryEngine.flushChanges(); | ||
54 | assertEquals(2, predicateResultSet.countResults()); | ||
55 | compareMatchSets(predicateResultSet.allResults(), Set.of(Tuple.of(0), Tuple.of(1))); | ||
44 | } | 56 | } |
45 | 57 | ||
46 | @Test | 58 | @Test |
47 | void relationConstraintTest() { | 59 | void relationConstraintTest() { |
48 | Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false); | 60 | var person = new Symbol<>("Person", 1, Boolean.class, false); |
49 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.class, TruthValue.FALSE); | 61 | var friend = new Symbol<>("friend", 2, TruthValue.class, TruthValue.FALSE); |
50 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 62 | var personView = new KeyOnlyRelationView<>(person); |
51 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", | 63 | var friendMustView = new FilteredRelationView<>(friend, "must", TruthValue::must); |
52 | TruthValue::must); | 64 | |
53 | 65 | var p1 = new Variable("p1"); | |
54 | Variable p1 = new Variable("p1"); | 66 | var p2 = new Variable("p2"); |
55 | Variable p2 = new Variable("p2"); | 67 | var predicate = DNF.builder("RelationConstraint") |
56 | DNF predicate = DNF.builder("RelationConstraint") | ||
57 | .parameters(p1, p2) | 68 | .parameters(p1, p2) |
58 | .clause( | 69 | .clause( |
59 | new RelationViewAtom(personView, p1), | 70 | new RelationViewAtom(personView, p1), |
@@ -62,37 +73,45 @@ class QueryTest { | |||
62 | ) | 73 | ) |
63 | .build(); | 74 | .build(); |
64 | 75 | ||
65 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, friend), | 76 | var store = ModelStore.builder() |
66 | Set.of(personView, friendMustView), Set.of(predicate)); | 77 | .symbols(person, friend) |
67 | QueryableModel model = store.createModel(); | 78 | .with(ViatraModelQuery.ADAPTER) |
79 | .queries(predicate) | ||
80 | .build(); | ||
81 | |||
82 | var model = store.createModel(); | ||
83 | var personInterpretation = model.getInterpretation(person); | ||
84 | var friendInterpretation = model.getInterpretation(friend); | ||
85 | var queryEngine = model.getAdapter(ModelQuery.ADAPTER); | ||
86 | var predicateResultSet = queryEngine.getResultSet(predicate); | ||
68 | 87 | ||
69 | assertEquals(0, model.countResults(predicate)); | 88 | assertEquals(0, predicateResultSet.countResults()); |
70 | 89 | ||
71 | model.put(person, Tuple.of(0), true); | 90 | personInterpretation.put(Tuple.of(0), true); |
72 | model.put(person, Tuple.of(1), true); | 91 | personInterpretation.put(Tuple.of(1), true); |
73 | model.put(person, Tuple.of(2), true); | 92 | personInterpretation.put(Tuple.of(2), true); |
74 | model.put(friend, Tuple.of(0, 1), TruthValue.TRUE); | ||
75 | model.put(friend, Tuple.of(1, 0), TruthValue.TRUE); | ||
76 | model.put(friend, Tuple.of(1, 2), TruthValue.TRUE); | ||
77 | 93 | ||
78 | assertEquals(0, model.countResults(predicate)); | 94 | friendInterpretation.put(Tuple.of(0, 1), TruthValue.TRUE); |
95 | friendInterpretation.put(Tuple.of(1, 0), TruthValue.TRUE); | ||
96 | friendInterpretation.put(Tuple.of(1, 2), TruthValue.TRUE); | ||
79 | 97 | ||
80 | model.flushChanges(); | 98 | assertEquals(0, predicateResultSet.countResults()); |
81 | assertEquals(3, model.countResults(predicate)); | 99 | |
82 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(1, 0), Tuple.of(1, 2))); | 100 | queryEngine.flushChanges(); |
101 | assertEquals(3, predicateResultSet.countResults()); | ||
102 | compareMatchSets(predicateResultSet.allResults(), Set.of(Tuple.of(0, 1), Tuple.of(1, 0), Tuple.of(1, 2))); | ||
83 | } | 103 | } |
84 | 104 | ||
85 | @Test | 105 | @Test |
86 | void andTest() { | 106 | void andTest() { |
87 | Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false); | 107 | var person = new Symbol<>("Person", 1, Boolean.class, false); |
88 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.class, TruthValue.FALSE); | 108 | var friend = new Symbol<>("friend", 2, TruthValue.class, TruthValue.FALSE); |
89 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 109 | var personView = new KeyOnlyRelationView<>(person); |
90 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", | 110 | var friendMustView = new FilteredRelationView<>(friend, "must", TruthValue::must); |
91 | TruthValue::must); | 111 | |
92 | 112 | var p1 = new Variable("p1"); | |
93 | Variable p1 = new Variable("p1"); | 113 | var p2 = new Variable("p2"); |
94 | Variable p2 = new Variable("p2"); | 114 | var predicate = DNF.builder("RelationConstraint") |
95 | DNF predicate = DNF.builder("RelationConstraint") | ||
96 | .parameters(p1, p2) | 115 | .parameters(p1, p2) |
97 | .clause( | 116 | .clause( |
98 | new RelationViewAtom(personView, p1), | 117 | new RelationViewAtom(personView, p1), |
@@ -102,45 +121,52 @@ class QueryTest { | |||
102 | ) | 121 | ) |
103 | .build(); | 122 | .build(); |
104 | 123 | ||
105 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, friend), | 124 | var store = ModelStore.builder() |
106 | Set.of(personView, friendMustView), Set.of(predicate)); | 125 | .symbols(person, friend) |
107 | QueryableModel model = store.createModel(); | 126 | .with(ViatraModelQuery.ADAPTER) |
127 | .queries(predicate) | ||
128 | .build(); | ||
129 | |||
130 | var model = store.createModel(); | ||
131 | var personInterpretation = model.getInterpretation(person); | ||
132 | var friendInterpretation = model.getInterpretation(friend); | ||
133 | var queryEngine = model.getAdapter(ModelQuery.ADAPTER); | ||
134 | var predicateResultSet = queryEngine.getResultSet(predicate); | ||
108 | 135 | ||
109 | assertEquals(0, model.countResults(predicate)); | 136 | assertEquals(0, predicateResultSet.countResults()); |
110 | 137 | ||
111 | model.put(person, Tuple.of(0), true); | 138 | personInterpretation.put(Tuple.of(0), true); |
112 | model.put(person, Tuple.of(1), true); | 139 | personInterpretation.put(Tuple.of(1), true); |
113 | model.put(person, Tuple.of(2), true); | 140 | personInterpretation.put(Tuple.of(2), true); |
114 | 141 | ||
115 | model.put(friend, Tuple.of(0, 1), TruthValue.TRUE); | 142 | friendInterpretation.put(Tuple.of(0, 1), TruthValue.TRUE); |
116 | model.put(friend, Tuple.of(0, 2), TruthValue.TRUE); | 143 | friendInterpretation.put(Tuple.of(0, 2), TruthValue.TRUE); |
117 | 144 | ||
118 | model.flushChanges(); | 145 | queryEngine.flushChanges(); |
119 | assertEquals(0, model.countResults(predicate)); | 146 | assertEquals(0, predicateResultSet.countResults()); |
120 | 147 | ||
121 | model.put(friend, Tuple.of(1, 0), TruthValue.TRUE); | 148 | friendInterpretation.put(Tuple.of(1, 0), TruthValue.TRUE); |
122 | model.flushChanges(); | 149 | queryEngine.flushChanges(); |
123 | assertEquals(2, model.countResults(predicate)); | 150 | assertEquals(2, predicateResultSet.countResults()); |
124 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(1, 0))); | 151 | compareMatchSets(predicateResultSet.allResults(), Set.of(Tuple.of(0, 1), Tuple.of(1, 0))); |
125 | 152 | ||
126 | model.put(friend, Tuple.of(2, 0), TruthValue.TRUE); | 153 | friendInterpretation.put(Tuple.of(2, 0), TruthValue.TRUE); |
127 | model.flushChanges(); | 154 | queryEngine.flushChanges(); |
128 | assertEquals(4, model.countResults(predicate)); | 155 | assertEquals(4, predicateResultSet.countResults()); |
129 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(1, 0), Tuple.of(0, 2), | 156 | compareMatchSets(predicateResultSet.allResults(), Set.of(Tuple.of(0, 1), Tuple.of(1, 0), Tuple.of(0, 2), |
130 | Tuple.of(2, 0))); | 157 | Tuple.of(2, 0))); |
131 | } | 158 | } |
132 | 159 | ||
133 | @Test | 160 | @Test |
134 | void existTest() { | 161 | void existTest() { |
135 | Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false); | 162 | var person = new Symbol<>("Person", 1, Boolean.class, false); |
136 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.class, TruthValue.FALSE); | 163 | var friend = new Symbol<>("friend", 2, TruthValue.class, TruthValue.FALSE); |
137 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 164 | var personView = new KeyOnlyRelationView<>(person); |
138 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", | 165 | var friendMustView = new FilteredRelationView<>(friend, "must", TruthValue::must); |
139 | TruthValue::must); | 166 | |
140 | 167 | var p1 = new Variable("p1"); | |
141 | Variable p1 = new Variable("p1"); | 168 | var p2 = new Variable("p2"); |
142 | Variable p2 = new Variable("p2"); | 169 | var predicate = DNF.builder("RelationConstraint") |
143 | DNF predicate = DNF.builder("RelationConstraint") | ||
144 | .parameters(p1) | 170 | .parameters(p1) |
145 | .clause( | 171 | .clause( |
146 | new RelationViewAtom(personView, p1), | 172 | new RelationViewAtom(personView, p1), |
@@ -149,39 +175,45 @@ class QueryTest { | |||
149 | ) | 175 | ) |
150 | .build(); | 176 | .build(); |
151 | 177 | ||
152 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, friend), | 178 | var store = ModelStore.builder() |
153 | Set.of(personView, friendMustView), Set.of(predicate)); | 179 | .symbols(person, friend) |
154 | QueryableModel model = store.createModel(); | 180 | .with(ViatraModelQuery.ADAPTER) |
181 | .queries(predicate) | ||
182 | .build(); | ||
183 | |||
184 | var model = store.createModel(); | ||
185 | var personInterpretation = model.getInterpretation(person); | ||
186 | var friendInterpretation = model.getInterpretation(friend); | ||
187 | var queryEngine = model.getAdapter(ModelQuery.ADAPTER); | ||
188 | var predicateResultSet = queryEngine.getResultSet(predicate); | ||
155 | 189 | ||
156 | assertEquals(0, model.countResults(predicate)); | 190 | personInterpretation.put(Tuple.of(0), true); |
191 | personInterpretation.put(Tuple.of(1), true); | ||
192 | personInterpretation.put(Tuple.of(2), true); | ||
157 | 193 | ||
158 | model.put(person, Tuple.of(0), true); | 194 | friendInterpretation.put(Tuple.of(0, 1), TruthValue.TRUE); |
159 | model.put(person, Tuple.of(1), true); | 195 | friendInterpretation.put(Tuple.of(1, 0), TruthValue.TRUE); |
160 | model.put(person, Tuple.of(2), true); | 196 | friendInterpretation.put(Tuple.of(1, 2), TruthValue.TRUE); |
161 | model.put(friend, Tuple.of(0, 1), TruthValue.TRUE); | ||
162 | model.put(friend, Tuple.of(1, 0), TruthValue.TRUE); | ||
163 | model.put(friend, Tuple.of(1, 2), TruthValue.TRUE); | ||
164 | 197 | ||
165 | assertEquals(0, model.countResults(predicate)); | 198 | assertEquals(0, predicateResultSet.countResults()); |
166 | 199 | ||
167 | model.flushChanges(); | 200 | queryEngine.flushChanges(); |
168 | assertEquals(2, model.countResults(predicate)); | 201 | assertEquals(2, predicateResultSet.countResults()); |
169 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0), Tuple.of(1))); | 202 | compareMatchSets(predicateResultSet.allResults(), Set.of(Tuple.of(0), Tuple.of(1))); |
170 | } | 203 | } |
171 | 204 | ||
172 | @Test | 205 | @Test |
173 | void orTest() { | 206 | void orTest() { |
174 | Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false); | 207 | var person = new Symbol<>("Person", 1, Boolean.class, false); |
175 | Relation<Boolean> animal = new Relation<>("Animal", 1, Boolean.class, false); | 208 | var animal = new Symbol<>("Animal", 1, Boolean.class, false); |
176 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.class, TruthValue.FALSE); | 209 | var friend = new Symbol<>("friend", 2, TruthValue.class, TruthValue.FALSE); |
177 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 210 | var personView = new KeyOnlyRelationView<>(person); |
178 | RelationView<Boolean> animalView = new KeyOnlyRelationView(animal); | 211 | var animalView = new KeyOnlyRelationView<>(animal); |
179 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", | 212 | var friendMustView = new FilteredRelationView<>(friend, "must", TruthValue::must); |
180 | TruthValue::must); | 213 | |
181 | 214 | var p1 = new Variable("p1"); | |
182 | Variable p1 = new Variable("p1"); | 215 | var p2 = new Variable("p2"); |
183 | Variable p2 = new Variable("p2"); | 216 | var predicate = DNF.builder("Or") |
184 | DNF predicate = DNF.builder("Or") | ||
185 | .parameters(p1, p2) | 217 | .parameters(p1, p2) |
186 | .clause( | 218 | .clause( |
187 | new RelationViewAtom(personView, p1), | 219 | new RelationViewAtom(personView, p1), |
@@ -195,32 +227,43 @@ class QueryTest { | |||
195 | ) | 227 | ) |
196 | .build(); | 228 | .build(); |
197 | 229 | ||
198 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, animal, friend), | 230 | var store = ModelStore.builder() |
199 | Set.of(personView, animalView, friendMustView), Set.of(predicate)); | 231 | .symbols(person, animal, friend) |
200 | QueryableModel model = store.createModel(); | 232 | .with(ViatraModelQuery.ADAPTER) |
201 | 233 | .queries(predicate) | |
202 | model.put(person, Tuple.of(0), true); | 234 | .build(); |
203 | model.put(person, Tuple.of(1), true); | 235 | |
204 | model.put(animal, Tuple.of(2), true); | 236 | var model = store.createModel(); |
205 | model.put(animal, Tuple.of(3), true); | 237 | var personInterpretation = model.getInterpretation(person); |
206 | model.put(friend, Tuple.of(0, 1), TruthValue.TRUE); | 238 | var animalInterpretation = model.getInterpretation(animal); |
207 | model.put(friend, Tuple.of(0, 2), TruthValue.TRUE); | 239 | var friendInterpretation = model.getInterpretation(friend); |
208 | model.put(friend, Tuple.of(2, 3), TruthValue.TRUE); | 240 | var queryEngine = model.getAdapter(ModelQuery.ADAPTER); |
209 | model.put(friend, Tuple.of(3, 0), TruthValue.TRUE); | 241 | var predicateResultSet = queryEngine.getResultSet(predicate); |
210 | 242 | ||
211 | model.flushChanges(); | 243 | personInterpretation.put(Tuple.of(0), true); |
212 | assertEquals(2, model.countResults(predicate)); | 244 | personInterpretation.put(Tuple.of(1), true); |
213 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(2, 3))); | 245 | |
246 | animalInterpretation.put(Tuple.of(2), true); | ||
247 | animalInterpretation.put(Tuple.of(3), true); | ||
248 | |||
249 | friendInterpretation.put(Tuple.of(0, 1), TruthValue.TRUE); | ||
250 | friendInterpretation.put(Tuple.of(0, 2), TruthValue.TRUE); | ||
251 | friendInterpretation.put(Tuple.of(2, 3), TruthValue.TRUE); | ||
252 | friendInterpretation.put(Tuple.of(3, 0), TruthValue.TRUE); | ||
253 | |||
254 | queryEngine.flushChanges(); | ||
255 | assertEquals(2, predicateResultSet.countResults()); | ||
256 | compareMatchSets(predicateResultSet.allResults(), Set.of(Tuple.of(0, 1), Tuple.of(2, 3))); | ||
214 | } | 257 | } |
215 | 258 | ||
216 | @Test | 259 | @Test |
217 | void equalityTest() { | 260 | void equalityTest() { |
218 | Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false); | 261 | var person = new Symbol<>("Person", 1, Boolean.class, false); |
219 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 262 | var personView = new KeyOnlyRelationView<>(person); |
220 | 263 | ||
221 | Variable p1 = new Variable("p1"); | 264 | var p1 = new Variable("p1"); |
222 | Variable p2 = new Variable("p2"); | 265 | var p2 = new Variable("p2"); |
223 | DNF predicate = DNF.builder("Equality") | 266 | var predicate = DNF.builder("Equality") |
224 | .parameters(p1, p2) | 267 | .parameters(p1, p2) |
225 | .clause( | 268 | .clause( |
226 | new RelationViewAtom(personView, p1), | 269 | new RelationViewAtom(personView, p1), |
@@ -229,30 +272,37 @@ class QueryTest { | |||
229 | ) | 272 | ) |
230 | .build(); | 273 | .build(); |
231 | 274 | ||
232 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person), Set.of(personView), Set.of(predicate)); | 275 | var store = ModelStore.builder() |
233 | QueryableModel model = store.createModel(); | 276 | .symbols(person) |
277 | .with(ViatraModelQuery.ADAPTER) | ||
278 | .queries(predicate) | ||
279 | .build(); | ||
280 | |||
281 | var model = store.createModel(); | ||
282 | var personInterpretation = model.getInterpretation(person); | ||
283 | var queryEngine = model.getAdapter(ModelQuery.ADAPTER); | ||
284 | var predicateResultSet = queryEngine.getResultSet(predicate); | ||
234 | 285 | ||
235 | model.put(person, Tuple.of(0), true); | 286 | personInterpretation.put(Tuple.of(0), true); |
236 | model.put(person, Tuple.of(1), true); | 287 | personInterpretation.put(Tuple.of(1), true); |
237 | model.put(person, Tuple.of(2), true); | 288 | personInterpretation.put(Tuple.of(2), true); |
238 | 289 | ||
239 | model.flushChanges(); | 290 | queryEngine.flushChanges(); |
240 | assertEquals(3, model.countResults(predicate)); | 291 | assertEquals(3, predicateResultSet.countResults()); |
241 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 0), Tuple.of(1, 1), Tuple.of(2, 2))); | 292 | compareMatchSets(predicateResultSet.allResults(), Set.of(Tuple.of(0, 0), Tuple.of(1, 1), Tuple.of(2, 2))); |
242 | } | 293 | } |
243 | 294 | ||
244 | @Test | 295 | @Test |
245 | void inequalityTest() { | 296 | void inequalityTest() { |
246 | Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false); | 297 | var person = new Symbol<>("Person", 1, Boolean.class, false); |
247 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.class, TruthValue.FALSE); | 298 | var friend = new Symbol<>("friend", 2, TruthValue.class, TruthValue.FALSE); |
248 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 299 | var personView = new KeyOnlyRelationView<>(person); |
249 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", | 300 | var friendMustView = new FilteredRelationView<>(friend, "must", TruthValue::must); |
250 | TruthValue::must); | 301 | |
251 | 302 | var p1 = new Variable("p1"); | |
252 | Variable p1 = new Variable("p1"); | 303 | var p2 = new Variable("p2"); |
253 | Variable p2 = new Variable("p2"); | 304 | var p3 = new Variable("p3"); |
254 | Variable p3 = new Variable("p3"); | 305 | var predicate = DNF.builder("Inequality") |
255 | DNF predicate = DNF.builder("Inequality") | ||
256 | .parameters(p1, p2, p3) | 306 | .parameters(p1, p2, p3) |
257 | .clause( | 307 | .clause( |
258 | new RelationViewAtom(personView, p1), | 308 | new RelationViewAtom(personView, p1), |
@@ -263,32 +313,40 @@ class QueryTest { | |||
263 | ) | 313 | ) |
264 | .build(); | 314 | .build(); |
265 | 315 | ||
266 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, friend), | 316 | var store = ModelStore.builder() |
267 | Set.of(personView, friendMustView), Set.of(predicate)); | 317 | .symbols(person, friend) |
268 | QueryableModel model = store.createModel(); | 318 | .with(ViatraModelQuery.ADAPTER) |
319 | .queries(predicate) | ||
320 | .build(); | ||
321 | |||
322 | var model = store.createModel(); | ||
323 | var personInterpretation = model.getInterpretation(person); | ||
324 | var friendInterpretation = model.getInterpretation(friend); | ||
325 | var queryEngine = model.getAdapter(ModelQuery.ADAPTER); | ||
326 | var predicateResultSet = queryEngine.getResultSet(predicate); | ||
327 | |||
328 | personInterpretation.put(Tuple.of(0), true); | ||
329 | personInterpretation.put(Tuple.of(1), true); | ||
330 | personInterpretation.put(Tuple.of(2), true); | ||
269 | 331 | ||
270 | model.put(person, Tuple.of(0), true); | 332 | friendInterpretation.put(Tuple.of(0, 2), TruthValue.TRUE); |
271 | model.put(person, Tuple.of(1), true); | 333 | friendInterpretation.put(Tuple.of(1, 2), TruthValue.TRUE); |
272 | model.put(person, Tuple.of(2), true); | ||
273 | model.put(friend, Tuple.of(0, 2), TruthValue.TRUE); | ||
274 | model.put(friend, Tuple.of(1, 2), TruthValue.TRUE); | ||
275 | 334 | ||
276 | model.flushChanges(); | 335 | queryEngine.flushChanges(); |
277 | assertEquals(2, model.countResults(predicate)); | 336 | assertEquals(2, predicateResultSet.countResults()); |
278 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1, 2), Tuple.of(1, 0, 2))); | 337 | compareMatchSets(predicateResultSet.allResults(), Set.of(Tuple.of(0, 1, 2), Tuple.of(1, 0, 2))); |
279 | } | 338 | } |
280 | 339 | ||
281 | @Test | 340 | @Test |
282 | void patternCallTest() { | 341 | void patternCallTest() { |
283 | Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false); | 342 | var person = new Symbol<>("Person", 1, Boolean.class, false); |
284 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.class, TruthValue.FALSE); | 343 | var friend = new Symbol<>("friend", 2, TruthValue.class, TruthValue.FALSE); |
285 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 344 | var personView = new KeyOnlyRelationView<>(person); |
286 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", | 345 | var friendMustView = new FilteredRelationView<>(friend, "must", TruthValue::must); |
287 | TruthValue::must); | 346 | |
288 | 347 | var p1 = new Variable("p1"); | |
289 | Variable p1 = new Variable("p1"); | 348 | var p2 = new Variable("p2"); |
290 | Variable p2 = new Variable("p2"); | 349 | var friendPredicate = DNF.builder("RelationConstraint") |
291 | DNF friendPredicate = DNF.builder("RelationConstraint") | ||
292 | .parameters(p1, p2) | 350 | .parameters(p1, p2) |
293 | .clause( | 351 | .clause( |
294 | new RelationViewAtom(personView, p1), | 352 | new RelationViewAtom(personView, p1), |
@@ -297,44 +355,51 @@ class QueryTest { | |||
297 | ) | 355 | ) |
298 | .build(); | 356 | .build(); |
299 | 357 | ||
300 | Variable p3 = new Variable("p3"); | 358 | var p3 = new Variable("p3"); |
301 | Variable p4 = new Variable("p4"); | 359 | var p4 = new Variable("p4"); |
302 | DNF predicate = DNF.builder("PositivePatternCall") | 360 | var predicate = DNF.builder("PositivePatternCall") |
303 | .parameters(p3, p4) | 361 | .parameters(p3, p4) |
304 | .clause( | 362 | .clause( |
305 | new RelationViewAtom(personView, p3), | 363 | new RelationViewAtom(personView, p3), |
306 | new RelationViewAtom(personView, p4), | 364 | new RelationViewAtom(personView, p4), |
307 | new CallAtom<>(friendPredicate, p3, p4) | 365 | new DNFCallAtom(friendPredicate, p3, p4) |
308 | ) | 366 | ) |
309 | .build(); | 367 | .build(); |
310 | 368 | ||
311 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, friend), | 369 | var store = ModelStore.builder() |
312 | Set.of(personView, friendMustView), Set.of(friendPredicate, predicate)); | 370 | .symbols(person, friend) |
313 | QueryableModel model = store.createModel(); | 371 | .with(ViatraModelQuery.ADAPTER) |
372 | .queries(predicate) | ||
373 | .build(); | ||
374 | |||
375 | var model = store.createModel(); | ||
376 | var personInterpretation = model.getInterpretation(person); | ||
377 | var friendInterpretation = model.getInterpretation(friend); | ||
378 | var queryEngine = model.getAdapter(ModelQuery.ADAPTER); | ||
379 | var predicateResultSet = queryEngine.getResultSet(predicate); | ||
314 | 380 | ||
315 | model.put(person, Tuple.of(0), true); | 381 | personInterpretation.put(Tuple.of(0), true); |
316 | model.put(person, Tuple.of(1), true); | 382 | personInterpretation.put(Tuple.of(1), true); |
317 | model.put(person, Tuple.of(2), true); | 383 | personInterpretation.put(Tuple.of(2), true); |
318 | model.put(friend, Tuple.of(0, 1), TruthValue.TRUE); | ||
319 | model.put(friend, Tuple.of(1, 0), TruthValue.TRUE); | ||
320 | model.put(friend, Tuple.of(1, 2), TruthValue.TRUE); | ||
321 | 384 | ||
322 | model.flushChanges(); | 385 | friendInterpretation.put(Tuple.of(0, 1), TruthValue.TRUE); |
386 | friendInterpretation.put(Tuple.of(1, 0), TruthValue.TRUE); | ||
387 | friendInterpretation.put(Tuple.of(1, 2), TruthValue.TRUE); | ||
323 | 388 | ||
324 | assertEquals(3, model.countResults(friendPredicate)); | 389 | queryEngine.flushChanges(); |
390 | assertEquals(3, predicateResultSet.countResults()); | ||
325 | } | 391 | } |
326 | 392 | ||
327 | @Test | 393 | @Test |
328 | void negativePatternCallTest() { | 394 | void negativePatternCallTest() { |
329 | Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false); | 395 | var person = new Symbol<>("Person", 1, Boolean.class, false); |
330 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.class, TruthValue.FALSE); | 396 | var friend = new Symbol<>("friend", 2, TruthValue.class, TruthValue.FALSE); |
331 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 397 | var personView = new KeyOnlyRelationView<>(person); |
332 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", | 398 | var friendMustView = new FilteredRelationView<>(friend, "must", TruthValue::must); |
333 | TruthValue::must); | 399 | |
334 | 400 | var p1 = new Variable("p1"); | |
335 | Variable p1 = new Variable("p1"); | 401 | var p2 = new Variable("p2"); |
336 | Variable p2 = new Variable("p2"); | 402 | var friendPredicate = DNF.builder("RelationConstraint") |
337 | DNF friendPredicate = DNF.builder("RelationConstraint") | ||
338 | .parameters(p1, p2) | 403 | .parameters(p1, p2) |
339 | .clause( | 404 | .clause( |
340 | new RelationViewAtom(personView, p1), | 405 | new RelationViewAtom(personView, p1), |
@@ -343,44 +408,52 @@ class QueryTest { | |||
343 | ) | 408 | ) |
344 | .build(); | 409 | .build(); |
345 | 410 | ||
346 | Variable p3 = new Variable("p3"); | 411 | var p3 = new Variable("p3"); |
347 | Variable p4 = new Variable("p4"); | 412 | var p4 = new Variable("p4"); |
348 | DNF predicate = DNF.builder("NegativePatternCall") | 413 | var predicate = DNF.builder("NegativePatternCall") |
349 | .parameters(p3, p4) | 414 | .parameters(p3, p4) |
350 | .clause( | 415 | .clause( |
351 | new RelationViewAtom(personView, p3), | 416 | new RelationViewAtom(personView, p3), |
352 | new RelationViewAtom(personView, p4), | 417 | new RelationViewAtom(personView, p4), |
353 | new CallAtom<>(false, friendPredicate, p3, p4) | 418 | new DNFCallAtom(false, friendPredicate, p3, p4) |
354 | ) | 419 | ) |
355 | .build(); | 420 | .build(); |
356 | 421 | ||
357 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, friend), | 422 | var store = ModelStore.builder() |
358 | Set.of(personView, friendMustView), Set.of(friendPredicate, predicate)); | 423 | .symbols(person, friend) |
359 | QueryableModel model = store.createModel(); | 424 | .with(ViatraModelQuery.ADAPTER) |
425 | .queries(predicate) | ||
426 | .build(); | ||
427 | |||
428 | var model = store.createModel(); | ||
429 | var personInterpretation = model.getInterpretation(person); | ||
430 | var friendInterpretation = model.getInterpretation(friend); | ||
431 | var queryEngine = model.getAdapter(ModelQuery.ADAPTER); | ||
432 | var predicateResultSet = queryEngine.getResultSet(predicate); | ||
433 | |||
434 | personInterpretation.put(Tuple.of(0), true); | ||
435 | personInterpretation.put(Tuple.of(1), true); | ||
436 | personInterpretation.put(Tuple.of(2), true); | ||
360 | 437 | ||
361 | model.put(person, Tuple.of(0), true); | 438 | friendInterpretation.put(Tuple.of(0, 1), TruthValue.TRUE); |
362 | model.put(person, Tuple.of(1), true); | 439 | friendInterpretation.put(Tuple.of(1, 0), TruthValue.TRUE); |
363 | model.put(person, Tuple.of(2), true); | 440 | friendInterpretation.put(Tuple.of(1, 2), TruthValue.TRUE); |
364 | model.put(friend, Tuple.of(0, 1), TruthValue.TRUE); | ||
365 | model.put(friend, Tuple.of(1, 0), TruthValue.TRUE); | ||
366 | model.put(friend, Tuple.of(1, 2), TruthValue.TRUE); | ||
367 | 441 | ||
368 | model.flushChanges(); | 442 | queryEngine.flushChanges(); |
369 | assertEquals(6, model.countResults(predicate)); | 443 | assertEquals(6, predicateResultSet.countResults()); |
370 | } | 444 | } |
371 | 445 | ||
372 | @Test | 446 | @Test |
373 | void negativeWithQuantificationTest() { | 447 | void negativeWithQuantificationTest() { |
374 | Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false); | 448 | var person = new Symbol<>("Person", 1, Boolean.class, false); |
375 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.class, TruthValue.FALSE); | 449 | var friend = new Symbol<>("friend", 2, TruthValue.class, TruthValue.FALSE); |
376 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 450 | var personView = new KeyOnlyRelationView<>(person); |
377 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", | 451 | var friendMustView = new FilteredRelationView<>(friend, "must", TruthValue::must); |
378 | TruthValue::must); | ||
379 | 452 | ||
380 | Variable p1 = new Variable("p1"); | 453 | var p1 = new Variable("p1"); |
381 | Variable p2 = new Variable("p2"); | 454 | var p2 = new Variable("p2"); |
382 | 455 | ||
383 | DNF called = DNF.builder("Called") | 456 | var called = DNF.builder("Called") |
384 | .parameters(p1, p2) | 457 | .parameters(p1, p2) |
385 | .clause( | 458 | .clause( |
386 | new RelationViewAtom(personView, p1), | 459 | new RelationViewAtom(personView, p1), |
@@ -389,39 +462,47 @@ class QueryTest { | |||
389 | ) | 462 | ) |
390 | .build(); | 463 | .build(); |
391 | 464 | ||
392 | DNF predicate = DNF.builder("Count") | 465 | var predicate = DNF.builder("Count") |
393 | .parameters(p1) | 466 | .parameters(p1) |
394 | .clause( | 467 | .clause( |
395 | new RelationViewAtom(personView, p1), | 468 | new RelationViewAtom(personView, p1), |
396 | new CallAtom<>(false, called, p1, p2) | 469 | new DNFCallAtom(false, called, p1, p2) |
397 | ) | 470 | ) |
398 | .build(); | 471 | .build(); |
399 | 472 | ||
400 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, friend), | 473 | var store = ModelStore.builder() |
401 | Set.of(personView, friendMustView), Set.of(called, predicate)); | 474 | .symbols(person, friend) |
402 | QueryableModel model = store.createModel(); | 475 | .with(ViatraModelQuery.ADAPTER) |
476 | .queries(predicate) | ||
477 | .build(); | ||
478 | |||
479 | var model = store.createModel(); | ||
480 | var personInterpretation = model.getInterpretation(person); | ||
481 | var friendInterpretation = model.getInterpretation(friend); | ||
482 | var queryEngine = model.getAdapter(ModelQuery.ADAPTER); | ||
483 | var predicateResultSet = queryEngine.getResultSet(predicate); | ||
403 | 484 | ||
404 | model.put(person, Tuple.of(0), true); | 485 | personInterpretation.put(Tuple.of(0), true); |
405 | model.put(person, Tuple.of(1), true); | 486 | personInterpretation.put(Tuple.of(1), true); |
406 | model.put(person, Tuple.of(2), true); | 487 | personInterpretation.put(Tuple.of(2), true); |
407 | model.put(friend, Tuple.of(0, 1), TruthValue.TRUE); | ||
408 | model.put(friend, Tuple.of(0, 2), TruthValue.TRUE); | ||
409 | 488 | ||
410 | model.flushChanges(); | 489 | friendInterpretation.put(Tuple.of(0, 1), TruthValue.TRUE); |
411 | assertEquals(2, model.countResults(predicate)); | 490 | friendInterpretation.put(Tuple.of(0, 2), TruthValue.TRUE); |
491 | |||
492 | queryEngine.flushChanges(); | ||
493 | assertEquals(2, predicateResultSet.countResults()); | ||
412 | } | 494 | } |
413 | 495 | ||
414 | @Test | 496 | @Test |
415 | void transitivePatternCallTest() { | 497 | void transitivePatternCallTest() { |
416 | Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false); | 498 | var person = new Symbol<>("Person", 1, Boolean.class, false); |
417 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.class, TruthValue.FALSE); | 499 | var friend = new Symbol<>("friend", 2, TruthValue.class, TruthValue.FALSE); |
418 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 500 | var personView = new KeyOnlyRelationView<>(person); |
419 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", | 501 | var friendMustView = new FilteredRelationView<>(friend, "must", TruthValue::must); |
420 | TruthValue::must); | 502 | |
421 | 503 | var p1 = new Variable("p1"); | |
422 | Variable p1 = new Variable("p1"); | 504 | var p2 = new Variable("p2"); |
423 | Variable p2 = new Variable("p2"); | 505 | var friendPredicate = DNF.builder("RelationConstraint") |
424 | DNF friendPredicate = DNF.builder("RelationConstraint") | ||
425 | .parameters(p1, p2) | 506 | .parameters(p1, p2) |
426 | .clause( | 507 | .clause( |
427 | new RelationViewAtom(personView, p1), | 508 | new RelationViewAtom(personView, p1), |
@@ -430,29 +511,38 @@ class QueryTest { | |||
430 | ) | 511 | ) |
431 | .build(); | 512 | .build(); |
432 | 513 | ||
433 | Variable p3 = new Variable("p3"); | 514 | var p3 = new Variable("p3"); |
434 | Variable p4 = new Variable("p4"); | 515 | var p4 = new Variable("p4"); |
435 | DNF predicate = DNF.builder("TransitivePatternCall") | 516 | var predicate = DNF.builder("TransitivePatternCall") |
436 | .parameters(p3, p4) | 517 | .parameters(p3, p4) |
437 | .clause( | 518 | .clause( |
438 | new RelationViewAtom(personView, p3), | 519 | new RelationViewAtom(personView, p3), |
439 | new RelationViewAtom(personView, p4), | 520 | new RelationViewAtom(personView, p4), |
440 | new CallAtom<>(CallPolarity.TRANSITIVE, friendPredicate, p3, p4) | 521 | new DNFCallAtom(CallPolarity.TRANSITIVE, friendPredicate, p3, p4) |
441 | ) | 522 | ) |
442 | .build(); | 523 | .build(); |
443 | 524 | ||
444 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, friend), | 525 | var store = ModelStore.builder() |
445 | Set.of(personView, friendMustView), Set.of(friendPredicate, predicate)); | 526 | .symbols(person, friend) |
446 | QueryableModel model = store.createModel(); | 527 | .with(ViatraModelQuery.ADAPTER) |
528 | .queries(predicate) | ||
529 | .build(); | ||
530 | |||
531 | var model = store.createModel(); | ||
532 | var personInterpretation = model.getInterpretation(person); | ||
533 | var friendInterpretation = model.getInterpretation(friend); | ||
534 | var queryEngine = model.getAdapter(ModelQuery.ADAPTER); | ||
535 | var predicateResultSet = queryEngine.getResultSet(predicate); | ||
536 | |||
537 | personInterpretation.put(Tuple.of(0), true); | ||
538 | personInterpretation.put(Tuple.of(1), true); | ||
539 | personInterpretation.put(Tuple.of(2), true); | ||
447 | 540 | ||
448 | model.put(person, Tuple.of(0), true); | 541 | friendInterpretation.put(Tuple.of(0, 1), TruthValue.TRUE); |
449 | model.put(person, Tuple.of(1), true); | 542 | friendInterpretation.put(Tuple.of(1, 2), TruthValue.TRUE); |
450 | model.put(person, Tuple.of(2), true); | ||
451 | model.put(friend, Tuple.of(0, 1), TruthValue.TRUE); | ||
452 | model.put(friend, Tuple.of(1, 2), TruthValue.TRUE); | ||
453 | 543 | ||
454 | model.flushChanges(); | 544 | queryEngine.flushChanges(); |
455 | assertEquals(3, model.countResults(predicate)); | 545 | assertEquals(3, predicateResultSet.countResults()); |
456 | } | 546 | } |
457 | 547 | ||
458 | static void compareMatchSets(Stream<TupleLike> matchSet, Set<Tuple> expected) { | 548 | static void compareMatchSets(Stream<TupleLike> matchSet, Set<Tuple> expected) { |
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTransactionTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTransactionTest.java index e8fa6ed1..49087a8d 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTransactionTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTransactionTest.java | |||
@@ -1,54 +1,59 @@ | |||
1 | package tools.refinery.store.query.viatra; | 1 | package tools.refinery.store.query.viatra; |
2 | 2 | ||
3 | import org.junit.jupiter.api.Test; | 3 | import org.junit.jupiter.api.Test; |
4 | import tools.refinery.store.model.representation.Relation; | 4 | import tools.refinery.store.model.ModelStore; |
5 | import tools.refinery.store.query.DNF; | 5 | import tools.refinery.store.query.DNF; |
6 | import tools.refinery.store.query.QueryableModel; | 6 | import tools.refinery.store.query.ModelQuery; |
7 | import tools.refinery.store.query.QueryableModelStore; | ||
8 | import tools.refinery.store.query.Variable; | 7 | import tools.refinery.store.query.Variable; |
9 | import tools.refinery.store.query.atom.RelationViewAtom; | 8 | import tools.refinery.store.query.atom.RelationViewAtom; |
10 | import tools.refinery.store.query.viatra.ViatraQueryableModelStore; | ||
11 | import tools.refinery.store.query.view.KeyOnlyRelationView; | 9 | import tools.refinery.store.query.view.KeyOnlyRelationView; |
12 | import tools.refinery.store.query.view.RelationView; | 10 | import tools.refinery.store.representation.Symbol; |
13 | import tools.refinery.store.tuple.Tuple; | 11 | import tools.refinery.store.tuple.Tuple; |
14 | 12 | ||
15 | import java.util.Set; | ||
16 | |||
17 | import static org.junit.jupiter.api.Assertions.assertEquals; | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; |
18 | 14 | ||
19 | class QueryTransactionTest { | 15 | class QueryTransactionTest { |
20 | @Test | 16 | @Test |
21 | void flushTest() { | 17 | void flushTest() { |
22 | Relation<Boolean> person = new Relation<>("Person", 1, Boolean.class, false); | 18 | var person = new Symbol<>("Person", 1, Boolean.class, false); |
23 | Relation<Boolean> asset = new Relation<>("Asset", 1, Boolean.class, false); | 19 | var asset = new Symbol<>("Asset", 1, Boolean.class, false); |
24 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 20 | var personView = new KeyOnlyRelationView<>(person); |
25 | 21 | ||
26 | var p1 = new Variable("p1"); | 22 | var p1 = new Variable("p1"); |
27 | DNF predicate = DNF.builder("TypeConstraint") | 23 | var predicate = DNF.builder("TypeConstraint") |
28 | .parameters(p1) | 24 | .parameters(p1) |
29 | .clause(new RelationViewAtom(personView, p1)) | 25 | .clause(new RelationViewAtom(personView, p1)) |
30 | .build(); | 26 | .build(); |
31 | 27 | ||
32 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, asset), Set.of(personView), | 28 | var store = ModelStore.builder() |
33 | Set.of(predicate)); | 29 | .symbols(person, asset) |
34 | QueryableModel model = store.createModel(); | 30 | .with(ViatraModelQuery.ADAPTER) |
31 | .queries(predicate) | ||
32 | .build(); | ||
33 | |||
34 | var model = store.createModel(); | ||
35 | var personInterpretation = model.getInterpretation(person); | ||
36 | var assetInterpretation = model.getInterpretation(asset); | ||
37 | var queryEngine = model.getAdapter(ModelQuery.ADAPTER); | ||
38 | var predicateResultSet = queryEngine.getResultSet(predicate); | ||
39 | |||
40 | assertEquals(0, predicateResultSet.countResults()); | ||
35 | 41 | ||
36 | assertEquals(0, model.countResults(predicate)); | 42 | personInterpretation.put(Tuple.of(0), true); |
43 | personInterpretation.put(Tuple.of(1), true); | ||
37 | 44 | ||
38 | model.put(person, Tuple.of(0), true); | 45 | assetInterpretation.put(Tuple.of(1), true); |
39 | model.put(person, Tuple.of(1), true); | 46 | assetInterpretation.put(Tuple.of(2), true); |
40 | model.put(asset, Tuple.of(1), true); | ||
41 | model.put(asset, Tuple.of(2), true); | ||
42 | 47 | ||
43 | assertEquals(0, model.countResults(predicate)); | 48 | assertEquals(0, predicateResultSet.countResults()); |
44 | 49 | ||
45 | model.flushChanges(); | 50 | queryEngine.flushChanges(); |
46 | assertEquals(2, model.countResults(predicate)); | 51 | assertEquals(2, predicateResultSet.countResults()); |
47 | 52 | ||
48 | model.put(person, Tuple.of(4), true); | 53 | personInterpretation.put(Tuple.of(4), true); |
49 | assertEquals(2, model.countResults(predicate)); | 54 | assertEquals(2, predicateResultSet.countResults()); |
50 | 55 | ||
51 | model.flushChanges(); | 56 | queryEngine.flushChanges(); |
52 | assertEquals(3, model.countResults(predicate)); | 57 | assertEquals(3, predicateResultSet.countResults()); |
53 | } | 58 | } |
54 | } | 59 | } |
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/internal/cardinality/UpperCardinalitySumAggregationOperatorStreamTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/internal/cardinality/UpperCardinalitySumAggregationOperatorStreamTest.java index 07869050..69491fda 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/internal/cardinality/UpperCardinalitySumAggregationOperatorStreamTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/internal/cardinality/UpperCardinalitySumAggregationOperatorStreamTest.java | |||
@@ -3,8 +3,8 @@ package tools.refinery.store.query.viatra.internal.cardinality; | |||
3 | import org.junit.jupiter.params.ParameterizedTest; | 3 | import org.junit.jupiter.params.ParameterizedTest; |
4 | import org.junit.jupiter.params.provider.Arguments; | 4 | import org.junit.jupiter.params.provider.Arguments; |
5 | import org.junit.jupiter.params.provider.MethodSource; | 5 | import org.junit.jupiter.params.provider.MethodSource; |
6 | import tools.refinery.store.model.representation.cardinality.UpperCardinalities; | 6 | import tools.refinery.store.representation.cardinality.UpperCardinalities; |
7 | import tools.refinery.store.model.representation.cardinality.UpperCardinality; | 7 | import tools.refinery.store.representation.cardinality.UpperCardinality; |
8 | 8 | ||
9 | import java.util.stream.Stream; | 9 | import java.util.stream.Stream; |
10 | 10 | ||
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/internal/cardinality/UpperCardinalitySumAggregationOperatorTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/internal/cardinality/UpperCardinalitySumAggregationOperatorTest.java index afc4a2f3..20dad543 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/internal/cardinality/UpperCardinalitySumAggregationOperatorTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/internal/cardinality/UpperCardinalitySumAggregationOperatorTest.java | |||
@@ -2,8 +2,8 @@ package tools.refinery.store.query.viatra.internal.cardinality; | |||
2 | 2 | ||
3 | import org.junit.jupiter.api.BeforeEach; | 3 | import org.junit.jupiter.api.BeforeEach; |
4 | import org.junit.jupiter.api.Test; | 4 | import org.junit.jupiter.api.Test; |
5 | import tools.refinery.store.model.representation.cardinality.UpperCardinalities; | 5 | import tools.refinery.store.representation.cardinality.UpperCardinalities; |
6 | import tools.refinery.store.model.representation.cardinality.UpperCardinality; | 6 | import tools.refinery.store.representation.cardinality.UpperCardinality; |
7 | 7 | ||
8 | import static org.hamcrest.MatcherAssert.assertThat; | 8 | import static org.hamcrest.MatcherAssert.assertThat; |
9 | import static org.hamcrest.Matchers.equalTo; | 9 | import static org.hamcrest.Matchers.equalTo; |