diff options
author | 2021-10-24 01:27:41 +0200 | |
---|---|---|
committer | 2021-10-24 01:27:41 +0200 | |
commit | 0ea6d0ca347f52148b43f502ac6d6f543a4bff10 (patch) | |
tree | fac7ec633f5460a39f76724c35e68ac5a65df9b8 /store/src/test | |
parent | Querytest first final case (diff) | |
download | refinery-0ea6d0ca347f52148b43f502ac6d6f543a4bff10.tar.gz refinery-0ea6d0ca347f52148b43f502ac6d6f543a4bff10.tar.zst refinery-0ea6d0ca347f52148b43f502ac6d6f543a4bff10.zip |
QueryTest update to binery relations
Diffstat (limited to 'store/src/test')
-rw-r--r-- | store/src/test/java/tools/refinery/store/query/test/QueryTest.java | 48 |
1 files changed, 14 insertions, 34 deletions
diff --git a/store/src/test/java/tools/refinery/store/query/test/QueryTest.java b/store/src/test/java/tools/refinery/store/query/test/QueryTest.java index 5f1c3fd8..3649ed0c 100644 --- a/store/src/test/java/tools/refinery/store/query/test/QueryTest.java +++ b/store/src/test/java/tools/refinery/store/query/test/QueryTest.java | |||
@@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; | |||
4 | 4 | ||
5 | import java.util.ArrayList; | 5 | import java.util.ArrayList; |
6 | import java.util.Arrays; | 6 | import java.util.Arrays; |
7 | import java.util.Collections; | ||
8 | import java.util.HashSet; | 7 | import java.util.HashSet; |
9 | import java.util.List; | 8 | import java.util.List; |
10 | import java.util.Set; | 9 | import java.util.Set; |
@@ -21,7 +20,6 @@ import tools.refinery.store.model.Model; | |||
21 | import tools.refinery.store.model.ModelStore; | 20 | import tools.refinery.store.model.ModelStore; |
22 | import tools.refinery.store.model.ModelStoreImpl; | 21 | import tools.refinery.store.model.ModelStoreImpl; |
23 | import tools.refinery.store.model.Tuple; | 22 | import tools.refinery.store.model.Tuple; |
24 | import tools.refinery.store.model.Tuple.Tuple1; | ||
25 | import tools.refinery.store.model.representation.Relation; | 23 | import tools.refinery.store.model.representation.Relation; |
26 | import tools.refinery.store.model.representation.TruthValue; | 24 | import tools.refinery.store.model.representation.TruthValue; |
27 | import tools.refinery.store.query.QueriableModel; | 25 | import tools.refinery.store.query.QueriableModel; |
@@ -116,7 +114,6 @@ class QueryTest { | |||
116 | } | 114 | } |
117 | 115 | ||
118 | @Test | 116 | @Test |
119 | //@Disabled | ||
120 | void typeConstraintTest() { | 117 | void typeConstraintTest() { |
121 | Relation<Boolean> person = new Relation<>("Person", 1, false); | 118 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
122 | Relation<Boolean> asset = new Relation<>("Asset", 1, false); | 119 | Relation<Boolean> asset = new Relation<>("Asset", 1, false); |
@@ -126,42 +123,27 @@ class QueryTest { | |||
126 | RelationAtom personRelationAtom = new RelationAtom(persionView, parameters); | 123 | RelationAtom personRelationAtom = new RelationAtom(persionView, parameters); |
127 | DNFAnd clause = new DNFAnd(new HashSet<>(parameters), Arrays.asList(personRelationAtom)); | 124 | DNFAnd clause = new DNFAnd(new HashSet<>(parameters), Arrays.asList(personRelationAtom)); |
128 | DNFPredicate predicate = new DNFPredicate("TypeConstraint", parameters, Arrays.asList(clause)); | 125 | DNFPredicate predicate = new DNFPredicate("TypeConstraint", parameters, Arrays.asList(clause)); |
129 | //GenericQuerySpecification<RawPatternMatcher> query = DNF2PQuery.translate(predicate).build(); | 126 | |
130 | |||
131 | //ModelStore store = new ModelStoreImpl(Set.of(person, asset)); | ||
132 | QueriableModelStore store = new QueriableModelStoreImpl(Set.of(person, asset), Set.of(persionView), Set.of(predicate)); | 127 | QueriableModelStore store = new QueriableModelStoreImpl(Set.of(person, asset), Set.of(persionView), Set.of(predicate)); |
133 | QueriableModel model = store.createModel(); | 128 | QueriableModel model = store.createModel(); |
134 | 129 | ||
135 | System.out.println("Res1"); | 130 | assertEquals(0, model.countResults(predicate)); |
136 | model.allResults(predicate).forEach(x -> System.out.println(x)); | ||
137 | 131 | ||
138 | model.put(person, Tuple.of(0), true); | 132 | model.put(person, Tuple.of(0), true); |
139 | model.put(person, Tuple.of(1), true); | 133 | model.put(person, Tuple.of(1), true); |
140 | model.put(asset, Tuple.of(1), true); | 134 | model.put(asset, Tuple.of(1), true); |
141 | model.put(asset, Tuple.of(2), true); | 135 | model.put(asset, Tuple.of(2), true); |
142 | 136 | ||
143 | System.out.println("Res2"); | 137 | assertEquals(0, model.countResults(predicate)); |
144 | model.allResults(predicate).forEach(x -> System.out.println(x)); | ||
145 | 138 | ||
146 | System.out.println("Res3"); | ||
147 | model.flushChanges(); | 139 | model.flushChanges(); |
140 | assertEquals(2, model.countResults(predicate)); | ||
148 | compareMatchSets(model.allResults(predicate), Set.of( | 141 | compareMatchSets(model.allResults(predicate), Set.of( |
149 | List.of(Tuple.of(0)), | 142 | List.of(Tuple.of(0)), |
150 | List.of(Tuple.of(1)))); | 143 | List.of(Tuple.of(1)))); |
151 | System.out.println(model.countResults(predicate)); | ||
152 | model.allResults(predicate).forEach(x -> System.out.println(x)); | ||
153 | |||
154 | |||
155 | //RelationalScope scope = new RelationalScope(model, Set.of(persionView)); | ||
156 | |||
157 | //ViatraQueryEngine engine = AdvancedViatraQueryEngine.on(scope); | ||
158 | //GenericPatternMatcher matcher = engine.getMatcher(query); | ||
159 | |||
160 | //assertEquals(2, matcher.countMatches()); | ||
161 | } | 144 | } |
162 | 145 | ||
163 | @Test | 146 | @Test |
164 | @Disabled | ||
165 | void relationConstraintTest() { | 147 | void relationConstraintTest() { |
166 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 148 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); |
167 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 149 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
@@ -179,24 +161,22 @@ class QueryTest { | |||
179 | Arrays.asList(personRelationAtom1, personRelationAtom2, friendRelationAtom)); | 161 | Arrays.asList(personRelationAtom1, personRelationAtom2, friendRelationAtom)); |
180 | DNFPredicate predicate = new DNFPredicate("RelationConstraint", parameters, Arrays.asList(clause)); | 162 | DNFPredicate predicate = new DNFPredicate("RelationConstraint", parameters, Arrays.asList(clause)); |
181 | 163 | ||
182 | GenericQuerySpecification<RawPatternMatcher> query = DNF2PQuery.translate(predicate).build(); | 164 | QueriableModelStore store = new QueriableModelStoreImpl(Set.of(person, friend), Set.of(persionView,friendMustView), Set.of(predicate)); |
183 | 165 | QueriableModel model = store.createModel(); | |
184 | ModelStore store = new ModelStoreImpl(Set.of(person, friend)); | 166 | |
185 | Model model = store.createModel(); | 167 | assertEquals(0, model.countResults(predicate)); |
186 | 168 | ||
187 | model.put(person, Tuple.of(0), true); | 169 | model.put(person, Tuple.of(0), true); |
188 | model.put(person, Tuple.of(1), true); | 170 | model.put(person, Tuple.of(1), true); |
189 | model.put(person, Tuple.of(2), true); | 171 | model.put(person, Tuple.of(2), true); |
190 | model.put(friend, Tuple.of(0, 1), TruthValue.TRUE); | 172 | model.put(friend, Tuple.of(0, 1), TruthValue.TRUE); |
191 | model.put(friend, Tuple.of(1, 0), TruthValue.TRUE); | 173 | model.put(friend, Tuple.of(1, 0), TruthValue.TRUE); |
192 | model.put(friend, Tuple.of(1, 2), TruthValue.TRUE); | 174 | model.put(friend, Tuple.of(1, 2), TruthValue.TRUE); |
193 | 175 | ||
194 | RelationalScope scope = new RelationalScope(model, Set.of(persionView, friendMustView)); | 176 | assertEquals(0, model.countResults(predicate)); |
195 | 177 | ||
196 | ViatraQueryEngine engine = AdvancedViatraQueryEngine.on(scope); | 178 | model.flushChanges(); |
197 | GenericPatternMatcher matcher = engine.getMatcher(query); | 179 | assertEquals(3, model.countResults(predicate)); |
198 | |||
199 | assertEquals(3, matcher.countMatches()); | ||
200 | } | 180 | } |
201 | 181 | ||
202 | @Test | 182 | @Test |