diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-09-27 02:08:44 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-10-03 20:06:52 +0200 |
commit | 7a310819cbbdd70767a9ed17e1bf84c2add9faed (patch) | |
tree | a381add842a69115d778ac902b47b40159a7feaf /subprojects/store-query-viatra/src | |
parent | refactor: remove viatra dependency from store (diff) | |
download | refinery-7a310819cbbdd70767a9ed17e1bf84c2add9faed.tar.gz refinery-7a310819cbbdd70767a9ed17e1bf84c2add9faed.tar.zst refinery-7a310819cbbdd70767a9ed17e1bf84c2add9faed.zip |
refactor: tuples in QueryableModel
Diffstat (limited to 'subprojects/store-query-viatra/src')
9 files changed, 103 insertions, 74 deletions
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraTupleLike.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraTupleLike.java new file mode 100644 index 00000000..46c28434 --- /dev/null +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraTupleLike.java | |||
@@ -0,0 +1,18 @@ | |||
1 | package tools.refinery.store.query.viatra; | ||
2 | |||
3 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; | ||
4 | import tools.refinery.store.tuple.Tuple1; | ||
5 | import tools.refinery.store.tuple.TupleLike; | ||
6 | |||
7 | public record ViatraTupleLike(ITuple wrappedTuple) implements TupleLike { | ||
8 | @Override | ||
9 | public int getSize() { | ||
10 | return wrappedTuple.getSize(); | ||
11 | } | ||
12 | |||
13 | @Override | ||
14 | public int get(int element) { | ||
15 | var wrappedValue = (Tuple1) wrappedTuple.get(element); | ||
16 | return wrappedValue.value0(); | ||
17 | } | ||
18 | } | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RawPatternMatcher.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RawPatternMatcher.java index be348a63..2c488319 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RawPatternMatcher.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RawPatternMatcher.java | |||
@@ -2,8 +2,9 @@ package tools.refinery.store.query.viatra.internal; | |||
2 | 2 | ||
3 | import org.eclipse.viatra.query.runtime.api.GenericPatternMatcher; | 3 | import org.eclipse.viatra.query.runtime.api.GenericPatternMatcher; |
4 | import org.eclipse.viatra.query.runtime.api.GenericQuerySpecification; | 4 | import org.eclipse.viatra.query.runtime.api.GenericQuerySpecification; |
5 | import org.eclipse.viatra.query.runtime.matchers.tuple.AbstractTuple; | 5 | import tools.refinery.store.query.viatra.ViatraTupleLike; |
6 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | 6 | import tools.refinery.store.tuple.Tuple; |
7 | import tools.refinery.store.tuple.TupleLike; | ||
7 | 8 | ||
8 | import java.util.Optional; | 9 | import java.util.Optional; |
9 | import java.util.stream.Stream; | 10 | import java.util.stream.Stream; |
@@ -13,39 +14,50 @@ public class RawPatternMatcher extends GenericPatternMatcher { | |||
13 | 14 | ||
14 | public RawPatternMatcher(GenericQuerySpecification<? extends GenericPatternMatcher> specification) { | 15 | public RawPatternMatcher(GenericQuerySpecification<? extends GenericPatternMatcher> specification) { |
15 | super(specification); | 16 | super(specification); |
16 | this.empty = new Object[specification.getParameterNames().size()]; | 17 | empty = new Object[specification.getParameterNames().size()]; |
17 | } | 18 | } |
18 | 19 | ||
19 | public boolean hasResult() { | 20 | public boolean hasResult() { |
20 | return hasResult(empty); | 21 | return backend.hasMatch(empty); |
21 | } | 22 | } |
22 | 23 | ||
23 | public boolean hasResult(Object[] parameters) { | 24 | public boolean hasResult(Tuple parameters) { |
24 | return this.backend.hasMatch(parameters); | 25 | return backend.hasMatch(toParametersArray(parameters)); |
25 | } | 26 | } |
26 | 27 | ||
27 | public Optional<Object[]> oneResult() { | 28 | public Optional<TupleLike> oneResult() { |
28 | return oneResult(empty); | 29 | return backend.getOneArbitraryMatch(empty).map(ViatraTupleLike::new); |
29 | } | 30 | } |
30 | 31 | ||
31 | public Optional<Object[]> oneResult(Object[] parameters) { | 32 | public Optional<TupleLike> oneResult(Tuple parameters) { |
32 | Optional<Tuple> tuple = this.backend.getOneArbitraryMatch(parameters); | 33 | return backend.getOneArbitraryMatch(toParametersArray(parameters)).map(ViatraTupleLike::new); |
33 | return tuple.map(AbstractTuple::getElements); | ||
34 | } | 34 | } |
35 | 35 | ||
36 | public Stream<Object[]> allResults() { | 36 | public Stream<TupleLike> allResults() { |
37 | return allResults(empty); | 37 | return backend.getAllMatches(empty).map(ViatraTupleLike::new); |
38 | } | 38 | } |
39 | 39 | ||
40 | public Stream<Object[]> allResults(Object[] parameters) { | 40 | public Stream<TupleLike> allResults(Tuple parameters) { |
41 | return this.backend.getAllMatches(parameters).map(AbstractTuple::getElements); | 41 | return backend.getAllMatches(toParametersArray(parameters)).map(ViatraTupleLike::new); |
42 | } | 42 | } |
43 | 43 | ||
44 | public int countResults() { | 44 | public int countResults() { |
45 | return countResults(empty); | 45 | return backend.countMatches(empty); |
46 | } | 46 | } |
47 | 47 | ||
48 | public int countResults(Object[] parameters) { | 48 | public int countResults(Tuple parameters) { |
49 | return backend.countMatches(parameters); | 49 | return backend.countMatches(toParametersArray(parameters)); |
50 | } | ||
51 | |||
52 | private Object[] toParametersArray(Tuple tuple) { | ||
53 | int size = tuple.getSize(); | ||
54 | var array = new Object[tuple.getSize()]; | ||
55 | for (int i = 0; i < size; i++) { | ||
56 | var value = tuple.get(i); | ||
57 | if (value >= 0) { | ||
58 | array[i] = Tuple.of(value); | ||
59 | } | ||
60 | } | ||
61 | return array; | ||
50 | } | 62 | } |
51 | } | 63 | } |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java index 8dfa22e0..5ddad67d 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java | |||
@@ -6,7 +6,7 @@ import org.eclipse.viatra.query.runtime.api.scope.IEngineContext; | |||
6 | import org.eclipse.viatra.query.runtime.api.scope.IIndexingErrorListener; | 6 | import org.eclipse.viatra.query.runtime.api.scope.IIndexingErrorListener; |
7 | import org.eclipse.viatra.query.runtime.api.scope.QueryScope; | 7 | import org.eclipse.viatra.query.runtime.api.scope.QueryScope; |
8 | import tools.refinery.store.model.Model; | 8 | import tools.refinery.store.model.Model; |
9 | import tools.refinery.store.model.Tuple; | 9 | import tools.refinery.store.tuple.Tuple; |
10 | import tools.refinery.store.model.representation.Relation; | 10 | import tools.refinery.store.model.representation.Relation; |
11 | import tools.refinery.store.query.viatra.internal.context.RelationalEngineContext; | 11 | import tools.refinery.store.query.viatra.internal.context.RelationalEngineContext; |
12 | import tools.refinery.store.query.viatra.internal.viewupdate.ModelUpdateListener; | 12 | import tools.refinery.store.query.viatra.internal.viewupdate.ModelUpdateListener; |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java index 3803702d..1c15e8f9 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java | |||
@@ -8,12 +8,13 @@ import tools.refinery.store.map.Cursor; | |||
8 | import tools.refinery.store.map.DiffCursor; | 8 | import tools.refinery.store.map.DiffCursor; |
9 | import tools.refinery.store.model.Model; | 9 | import tools.refinery.store.model.Model; |
10 | import tools.refinery.store.model.ModelDiffCursor; | 10 | import tools.refinery.store.model.ModelDiffCursor; |
11 | import tools.refinery.store.model.Tuple; | ||
12 | import tools.refinery.store.model.representation.DataRepresentation; | 11 | import tools.refinery.store.model.representation.DataRepresentation; |
13 | import tools.refinery.store.model.representation.Relation; | 12 | import tools.refinery.store.model.representation.Relation; |
14 | import tools.refinery.store.query.QueryableModel; | 13 | import tools.refinery.store.query.QueryableModel; |
15 | import tools.refinery.store.query.QueryableModelStore; | 14 | import tools.refinery.store.query.QueryableModelStore; |
16 | import tools.refinery.store.query.building.DNFPredicate; | 15 | import tools.refinery.store.query.building.DNFPredicate; |
16 | import tools.refinery.store.tuple.Tuple; | ||
17 | import tools.refinery.store.tuple.TupleLike; | ||
17 | 18 | ||
18 | import java.util.HashMap; | 19 | import java.util.HashMap; |
19 | import java.util.Map; | 20 | import java.util.Map; |
@@ -124,9 +125,9 @@ public class ViatraQueryableModel implements QueryableModel { | |||
124 | return result; | 125 | return result; |
125 | } | 126 | } |
126 | 127 | ||
127 | protected void validateParameters(DNFPredicate predicate, Object[] parameters) { | 128 | protected void validateParameters(DNFPredicate predicate, Tuple parameters) { |
128 | int predicateArity = predicate.getVariables().size(); | 129 | int predicateArity = predicate.getVariables().size(); |
129 | int parameterArity = parameters.length; | 130 | int parameterArity = parameters.getSize(); |
130 | if (parameterArity != predicateArity) { | 131 | if (parameterArity != predicateArity) { |
131 | throw new IllegalArgumentException( | 132 | throw new IllegalArgumentException( |
132 | "Predicate %s with %d arity called with different number of parameters (%d)" | 133 | "Predicate %s with %d arity called with different number of parameters (%d)" |
@@ -140,29 +141,29 @@ public class ViatraQueryableModel implements QueryableModel { | |||
140 | } | 141 | } |
141 | 142 | ||
142 | @Override | 143 | @Override |
143 | public boolean hasResult(DNFPredicate predicate, Object[] parameters) { | 144 | public boolean hasResult(DNFPredicate predicate, Tuple parameters) { |
144 | validateParameters(predicate, parameters); | 145 | validateParameters(predicate, parameters); |
145 | return getMatcher(predicate).hasResult(parameters); | 146 | return getMatcher(predicate).hasResult(parameters); |
146 | } | 147 | } |
147 | 148 | ||
148 | @Override | 149 | @Override |
149 | public Optional<Object[]> oneResult(DNFPredicate predicate) { | 150 | public Optional<TupleLike> oneResult(DNFPredicate predicate) { |
150 | return getMatcher(predicate).oneResult(); | 151 | return getMatcher(predicate).oneResult(); |
151 | } | 152 | } |
152 | 153 | ||
153 | @Override | 154 | @Override |
154 | public Optional<Object[]> oneResult(DNFPredicate predicate, Object[] parameters) { | 155 | public Optional<TupleLike> oneResult(DNFPredicate predicate, Tuple parameters) { |
155 | validateParameters(predicate, parameters); | 156 | validateParameters(predicate, parameters); |
156 | return getMatcher(predicate).oneResult(parameters); | 157 | return getMatcher(predicate).oneResult(parameters); |
157 | } | 158 | } |
158 | 159 | ||
159 | @Override | 160 | @Override |
160 | public Stream<Object[]> allResults(DNFPredicate predicate) { | 161 | public Stream<TupleLike> allResults(DNFPredicate predicate) { |
161 | return getMatcher(predicate).allResults(); | 162 | return getMatcher(predicate).allResults(); |
162 | } | 163 | } |
163 | 164 | ||
164 | @Override | 165 | @Override |
165 | public Stream<Object[]> allResults(DNFPredicate predicate, Object[] parameters) { | 166 | public Stream<TupleLike> allResults(DNFPredicate predicate, Tuple parameters) { |
166 | validateParameters(predicate, parameters); | 167 | validateParameters(predicate, parameters); |
167 | return getMatcher(predicate).allResults(parameters); | 168 | return getMatcher(predicate).allResults(parameters); |
168 | } | 169 | } |
@@ -173,7 +174,7 @@ public class ViatraQueryableModel implements QueryableModel { | |||
173 | } | 174 | } |
174 | 175 | ||
175 | @Override | 176 | @Override |
176 | public int countResults(DNFPredicate predicate, Object[] parameters) { | 177 | public int countResults(DNFPredicate predicate, Tuple parameters) { |
177 | validateParameters(predicate, parameters); | 178 | validateParameters(predicate, parameters); |
178 | return getMatcher(predicate).countResults(parameters); | 179 | return getMatcher(predicate).countResults(parameters); |
179 | 180 | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java index 5a0da315..1a2fcee7 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java | |||
@@ -3,7 +3,7 @@ package tools.refinery.store.query.viatra.internal.viewupdate; | |||
3 | import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; | 3 | import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; |
4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; | 4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; |
5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; | 5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; |
6 | import tools.refinery.store.model.Tuple; | 6 | import tools.refinery.store.tuple.Tuple; |
7 | import tools.refinery.store.model.representation.Relation; | 7 | import tools.refinery.store.model.representation.Relation; |
8 | import tools.refinery.store.query.view.RelationView; | 8 | import tools.refinery.store.query.view.RelationView; |
9 | 9 | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateBuffer.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateBuffer.java index e13a9cb8..49f4c501 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateBuffer.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateBuffer.java | |||
@@ -1,6 +1,6 @@ | |||
1 | package tools.refinery.store.query.viatra.internal.viewupdate; | 1 | package tools.refinery.store.query.viatra.internal.viewupdate; |
2 | 2 | ||
3 | import tools.refinery.store.model.Tuple; | 3 | import tools.refinery.store.tuple.Tuple; |
4 | 4 | ||
5 | import java.util.ArrayList; | 5 | import java.util.ArrayList; |
6 | import java.util.Arrays; | 6 | import java.util.Arrays; |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java index 62a10e45..74d0b366 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java | |||
@@ -4,7 +4,7 @@ import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; | |||
4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; | 4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; |
5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; | 5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; |
6 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | 6 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; |
7 | import tools.refinery.store.model.Tuple; | 7 | import tools.refinery.store.tuple.Tuple; |
8 | import tools.refinery.store.query.view.RelationView; | 8 | import tools.refinery.store.query.view.RelationView; |
9 | 9 | ||
10 | import java.util.Objects; | 10 | import java.util.Objects; |
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java index 4307ab6b..d6213b02 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java | |||
@@ -1,7 +1,6 @@ | |||
1 | package tools.refinery.store.query.viatra.tests; | 1 | package tools.refinery.store.query.viatra.tests; |
2 | 2 | ||
3 | import org.junit.jupiter.api.Test; | 3 | import org.junit.jupiter.api.Test; |
4 | import tools.refinery.store.model.Tuple; | ||
5 | import tools.refinery.store.model.representation.Relation; | 4 | import tools.refinery.store.model.representation.Relation; |
6 | import tools.refinery.store.model.representation.TruthValue; | 5 | import tools.refinery.store.model.representation.TruthValue; |
7 | import tools.refinery.store.query.QueryableModel; | 6 | import tools.refinery.store.query.QueryableModel; |
@@ -11,6 +10,8 @@ import tools.refinery.store.query.viatra.ViatraQueryableModelStore; | |||
11 | import tools.refinery.store.query.view.FilteredRelationView; | 10 | import tools.refinery.store.query.view.FilteredRelationView; |
12 | import tools.refinery.store.query.view.KeyOnlyRelationView; | 11 | import tools.refinery.store.query.view.KeyOnlyRelationView; |
13 | import tools.refinery.store.query.view.RelationView; | 12 | import tools.refinery.store.query.view.RelationView; |
13 | import tools.refinery.store.tuple.Tuple; | ||
14 | import tools.refinery.store.tuple.TupleLike; | ||
14 | 15 | ||
15 | import java.util.*; | 16 | import java.util.*; |
16 | import java.util.stream.Stream; | 17 | import java.util.stream.Stream; |
@@ -40,15 +41,16 @@ class QueryTest { | |||
40 | 41 | ||
41 | model.flushChanges(); | 42 | model.flushChanges(); |
42 | assertEquals(2, model.countResults(predicate)); | 43 | assertEquals(2, model.countResults(predicate)); |
43 | compareMatchSets(model.allResults(predicate), Set.of(List.of(Tuple.of(0)), List.of(Tuple.of(1)))); | 44 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0), Tuple.of(1))); |
44 | } | 45 | } |
45 | 46 | ||
46 | @Test | 47 | @Test |
47 | void relationConstraintTest() { | 48 | void relationConstraintTest() { |
48 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 49 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
49 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 50 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
50 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 51 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
51 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 52 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
53 | TruthValue::must); | ||
52 | 54 | ||
53 | Variable p1 = new Variable("p1"); | 55 | Variable p1 = new Variable("p1"); |
54 | Variable p2 = new Variable("p2"); | 56 | Variable p2 = new Variable("p2"); |
@@ -78,16 +80,16 @@ class QueryTest { | |||
78 | 80 | ||
79 | model.flushChanges(); | 81 | model.flushChanges(); |
80 | assertEquals(3, model.countResults(predicate)); | 82 | assertEquals(3, model.countResults(predicate)); |
81 | compareMatchSets(model.allResults(predicate), Set.of(List.of(Tuple.of(0), Tuple.of(1)), | 83 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(1, 0), Tuple.of(1, 2))); |
82 | List.of(Tuple.of(1), Tuple.of(0)), List.of(Tuple.of(1), Tuple.of(2)))); | ||
83 | } | 84 | } |
84 | 85 | ||
85 | @Test | 86 | @Test |
86 | void andTest() { | 87 | void andTest() { |
87 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 88 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
88 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 89 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
89 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 90 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
90 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 91 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
92 | TruthValue::must); | ||
91 | 93 | ||
92 | Variable p1 = new Variable("p1"); | 94 | Variable p1 = new Variable("p1"); |
93 | Variable p2 = new Variable("p2"); | 95 | Variable p2 = new Variable("p2"); |
@@ -120,23 +122,22 @@ class QueryTest { | |||
120 | model.put(friend, Tuple.of(1, 0), TruthValue.TRUE); | 122 | model.put(friend, Tuple.of(1, 0), TruthValue.TRUE); |
121 | model.flushChanges(); | 123 | model.flushChanges(); |
122 | assertEquals(2, model.countResults(predicate)); | 124 | assertEquals(2, model.countResults(predicate)); |
123 | compareMatchSets(model.allResults(predicate), | 125 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(1, 0))); |
124 | Set.of(List.of(Tuple.of(0), Tuple.of(1)), List.of(Tuple.of(1), Tuple.of(0)))); | ||
125 | 126 | ||
126 | model.put(friend, Tuple.of(2, 0), TruthValue.TRUE); | 127 | model.put(friend, Tuple.of(2, 0), TruthValue.TRUE); |
127 | model.flushChanges(); | 128 | model.flushChanges(); |
128 | assertEquals(4, model.countResults(predicate)); | 129 | assertEquals(4, model.countResults(predicate)); |
129 | compareMatchSets(model.allResults(predicate), | 130 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(1, 0), Tuple.of(0, 2), |
130 | Set.of(List.of(Tuple.of(0), Tuple.of(1)), List.of(Tuple.of(1), Tuple.of(0)), | 131 | Tuple.of(2, 0))); |
131 | List.of(Tuple.of(0), Tuple.of(2)), List.of(Tuple.of(2), Tuple.of(0)))); | ||
132 | } | 132 | } |
133 | 133 | ||
134 | @Test | 134 | @Test |
135 | void existTest() { | 135 | void existTest() { |
136 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 136 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
137 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 137 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
138 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 138 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
139 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 139 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
140 | TruthValue::must); | ||
140 | 141 | ||
141 | Variable p1 = new Variable("p1"); | 142 | Variable p1 = new Variable("p1"); |
142 | Variable p2 = new Variable("p2"); | 143 | Variable p2 = new Variable("p2"); |
@@ -166,7 +167,7 @@ class QueryTest { | |||
166 | 167 | ||
167 | model.flushChanges(); | 168 | model.flushChanges(); |
168 | assertEquals(2, model.countResults(predicate)); | 169 | assertEquals(2, model.countResults(predicate)); |
169 | compareMatchSets(model.allResults(predicate), Set.of(List.of(Tuple.of(0)), List.of(Tuple.of(1)))); | 170 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0), Tuple.of(1))); |
170 | } | 171 | } |
171 | 172 | ||
172 | @Test | 173 | @Test |
@@ -176,7 +177,8 @@ class QueryTest { | |||
176 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 177 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
177 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 178 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
178 | RelationView<Boolean> animalView = new KeyOnlyRelationView(animal); | 179 | RelationView<Boolean> animalView = new KeyOnlyRelationView(animal); |
179 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 180 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
181 | TruthValue::must); | ||
180 | 182 | ||
181 | Variable p1 = new Variable("p1"); | 183 | Variable p1 = new Variable("p1"); |
182 | Variable p2 = new Variable("p2"); | 184 | Variable p2 = new Variable("p2"); |
@@ -196,8 +198,7 @@ class QueryTest { | |||
196 | DNFAnd clause2 = new DNFAnd(Collections.emptySet(), | 198 | DNFAnd clause2 = new DNFAnd(Collections.emptySet(), |
197 | Arrays.asList(animalRelationAtom1, animalRelationAtom2, friendRelationAtom2)); | 199 | Arrays.asList(animalRelationAtom1, animalRelationAtom2, friendRelationAtom2)); |
198 | 200 | ||
199 | // No inter-species friendship | 201 | // No friendship between species |
200 | |||
201 | DNFPredicate predicate = new DNFPredicate("Or", parameters, Arrays.asList(clause1, clause2)); | 202 | DNFPredicate predicate = new DNFPredicate("Or", parameters, Arrays.asList(clause1, clause2)); |
202 | 203 | ||
203 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, animal, friend), | 204 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, animal, friend), |
@@ -215,13 +216,12 @@ class QueryTest { | |||
215 | 216 | ||
216 | model.flushChanges(); | 217 | model.flushChanges(); |
217 | assertEquals(2, model.countResults(predicate)); | 218 | assertEquals(2, model.countResults(predicate)); |
218 | compareMatchSets(model.allResults(predicate), | 219 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(2, 3))); |
219 | Set.of(List.of(Tuple.of(0), Tuple.of(1)), List.of(Tuple.of(2), Tuple.of(3)))); | ||
220 | } | 220 | } |
221 | 221 | ||
222 | @Test | 222 | @Test |
223 | void equalityTest() { | 223 | void equalityTest() { |
224 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 224 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
225 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 225 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
226 | 226 | ||
227 | Variable p1 = new Variable("p1"); | 227 | Variable p1 = new Variable("p1"); |
@@ -244,16 +244,16 @@ class QueryTest { | |||
244 | 244 | ||
245 | model.flushChanges(); | 245 | model.flushChanges(); |
246 | assertEquals(3, model.countResults(predicate)); | 246 | assertEquals(3, model.countResults(predicate)); |
247 | compareMatchSets(model.allResults(predicate), Set.of(List.of(Tuple.of(0), Tuple.of(0)), | 247 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 0), Tuple.of(1, 1), Tuple.of(2, 2))); |
248 | List.of(Tuple.of(1), Tuple.of(1)), List.of(Tuple.of(2), Tuple.of(2)))); | ||
249 | } | 248 | } |
250 | 249 | ||
251 | @Test | 250 | @Test |
252 | void inequalityTest() { | 251 | void inequalityTest() { |
253 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 252 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
254 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 253 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
255 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 254 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
256 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 255 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
256 | TruthValue::must); | ||
257 | 257 | ||
258 | Variable p1 = new Variable("p1"); | 258 | Variable p1 = new Variable("p1"); |
259 | Variable p2 = new Variable("p2"); | 259 | Variable p2 = new Variable("p2"); |
@@ -281,16 +281,16 @@ class QueryTest { | |||
281 | 281 | ||
282 | model.flushChanges(); | 282 | model.flushChanges(); |
283 | assertEquals(2, model.countResults(predicate)); | 283 | assertEquals(2, model.countResults(predicate)); |
284 | compareMatchSets(model.allResults(predicate), | 284 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1, 2), Tuple.of(1, 0, 2))); |
285 | Set.of(List.of(Tuple.of(0), Tuple.of(1), Tuple.of(2)), List.of(Tuple.of(1), Tuple.of(0), Tuple.of(2)))); | ||
286 | } | 285 | } |
287 | 286 | ||
288 | @Test | 287 | @Test |
289 | void patternCallTest() { | 288 | void patternCallTest() { |
290 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 289 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
291 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 290 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
292 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 291 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
293 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 292 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
293 | TruthValue::must); | ||
294 | 294 | ||
295 | Variable p1 = new Variable("p1"); | 295 | Variable p1 = new Variable("p1"); |
296 | Variable p2 = new Variable("p2"); | 296 | Variable p2 = new Variable("p2"); |
@@ -331,10 +331,11 @@ class QueryTest { | |||
331 | 331 | ||
332 | @Test | 332 | @Test |
333 | void negativePatternCallTest() { | 333 | void negativePatternCallTest() { |
334 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 334 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
335 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 335 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
336 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 336 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
337 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 337 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
338 | TruthValue::must); | ||
338 | 339 | ||
339 | Variable p1 = new Variable("p1"); | 340 | Variable p1 = new Variable("p1"); |
340 | Variable p2 = new Variable("p2"); | 341 | Variable p2 = new Variable("p2"); |
@@ -375,10 +376,11 @@ class QueryTest { | |||
375 | 376 | ||
376 | @Test | 377 | @Test |
377 | void transitivePatternCallTest() { | 378 | void transitivePatternCallTest() { |
378 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 379 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
379 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 380 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
380 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 381 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
381 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 382 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
383 | TruthValue::must); | ||
382 | 384 | ||
383 | Variable p1 = new Variable("p1"); | 385 | Variable p1 = new Variable("p1"); |
384 | Variable p2 = new Variable("p2"); | 386 | Variable p2 = new Variable("p2"); |
@@ -415,18 +417,14 @@ class QueryTest { | |||
415 | model.flushChanges(); | 417 | model.flushChanges(); |
416 | assertEquals(3, model.countResults(predicate)); | 418 | assertEquals(3, model.countResults(predicate)); |
417 | } | 419 | } |
418 | static void compareMatchSets(Stream<Object[]> matchSet, Set<List<Tuple>> expected) { | 420 | |
419 | Set<List<Tuple>> translatedMatchSet = new HashSet<>(); | 421 | static void compareMatchSets(Stream<TupleLike> matchSet, Set<Tuple> expected) { |
422 | Set<Tuple> translatedMatchSet = new HashSet<>(); | ||
420 | var iterator = matchSet.iterator(); | 423 | var iterator = matchSet.iterator(); |
421 | while (iterator.hasNext()) { | 424 | while (iterator.hasNext()) { |
422 | var element = iterator.next(); | 425 | var element = iterator.next(); |
423 | List<Tuple> elementToTranslatedMatchSet = new ArrayList<>(); | 426 | translatedMatchSet.add(element.toTuple()); |
424 | for (Object o : element) { | ||
425 | elementToTranslatedMatchSet.add((Tuple) o); | ||
426 | } | ||
427 | translatedMatchSet.add(elementToTranslatedMatchSet); | ||
428 | } | 427 | } |
429 | |||
430 | assertEquals(expected, translatedMatchSet); | 428 | assertEquals(expected, translatedMatchSet); |
431 | } | 429 | } |
432 | } | 430 | } |
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTransactionTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTransactionTest.java index 613d0074..f57bca2b 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTransactionTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTransactionTest.java | |||
@@ -1,7 +1,7 @@ | |||
1 | package tools.refinery.store.query.viatra.tests; | 1 | package tools.refinery.store.query.viatra.tests; |
2 | 2 | ||
3 | import org.junit.jupiter.api.Test; | 3 | import org.junit.jupiter.api.Test; |
4 | import tools.refinery.store.model.Tuple; | 4 | import tools.refinery.store.tuple.Tuple; |
5 | import tools.refinery.store.model.representation.Relation; | 5 | import tools.refinery.store.model.representation.Relation; |
6 | import tools.refinery.store.query.QueryableModel; | 6 | import tools.refinery.store.query.QueryableModel; |
7 | import tools.refinery.store.query.QueryableModelStore; | 7 | import tools.refinery.store.query.QueryableModelStore; |