diff options
Diffstat (limited to 'subprojects/store-query-interpreter/src')
24 files changed, 256 insertions, 113 deletions
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/QueryInterpreterBuilder.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/QueryInterpreterBuilder.java index 6e167d0d..010164e2 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/QueryInterpreterBuilder.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/QueryInterpreterBuilder.java | |||
@@ -7,9 +7,9 @@ package tools.refinery.store.query.interpreter; | |||
7 | 7 | ||
8 | import tools.refinery.store.model.ModelStore; | 8 | import tools.refinery.store.model.ModelStore; |
9 | import tools.refinery.store.query.ModelQueryBuilder; | 9 | import tools.refinery.store.query.ModelQueryBuilder; |
10 | import tools.refinery.store.query.dnf.AnyQuery; | 10 | import tools.refinery.logic.dnf.AnyQuery; |
11 | import tools.refinery.store.query.dnf.Dnf; | 11 | import tools.refinery.logic.dnf.Dnf; |
12 | import tools.refinery.store.query.rewriter.DnfRewriter; | 12 | import tools.refinery.logic.rewriter.DnfRewriter; |
13 | import tools.refinery.interpreter.api.InterpreterEngineOptions; | 13 | import tools.refinery.interpreter.api.InterpreterEngineOptions; |
14 | import tools.refinery.interpreter.matchers.backend.IQueryBackendFactory; | 14 | import tools.refinery.interpreter.matchers.backend.IQueryBackendFactory; |
15 | import tools.refinery.interpreter.matchers.backend.QueryEvaluationHint; | 15 | import tools.refinery.interpreter.matchers.backend.QueryEvaluationHint; |
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/QueryInterpreterAdapterImpl.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/QueryInterpreterAdapterImpl.java index ee527fd3..c5423223 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/QueryInterpreterAdapterImpl.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/QueryInterpreterAdapterImpl.java | |||
@@ -7,10 +7,10 @@ package tools.refinery.store.query.interpreter.internal; | |||
7 | 7 | ||
8 | import tools.refinery.store.model.Model; | 8 | import tools.refinery.store.model.Model; |
9 | import tools.refinery.store.model.ModelListener; | 9 | import tools.refinery.store.model.ModelListener; |
10 | import tools.refinery.store.query.dnf.AnyQuery; | 10 | import tools.refinery.logic.dnf.AnyQuery; |
11 | import tools.refinery.store.query.dnf.FunctionalQuery; | 11 | import tools.refinery.logic.dnf.FunctionalQuery; |
12 | import tools.refinery.store.query.dnf.Query; | 12 | import tools.refinery.logic.dnf.Query; |
13 | import tools.refinery.store.query.dnf.RelationalQuery; | 13 | import tools.refinery.logic.dnf.RelationalQuery; |
14 | import tools.refinery.store.query.resultset.AnyResultSet; | 14 | import tools.refinery.store.query.resultset.AnyResultSet; |
15 | import tools.refinery.store.query.resultset.EmptyResultSet; | 15 | import tools.refinery.store.query.resultset.EmptyResultSet; |
16 | import tools.refinery.store.query.resultset.ResultSet; | 16 | import tools.refinery.store.query.resultset.ResultSet; |
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/QueryInterpreterBuilderImpl.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/QueryInterpreterBuilderImpl.java index 4e839b43..1791e626 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/QueryInterpreterBuilderImpl.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/QueryInterpreterBuilderImpl.java | |||
@@ -9,12 +9,12 @@ import org.eclipse.emf.ecore.EPackage; | |||
9 | import tools.refinery.interpreter.rete.recipes.RecipesPackage; | 9 | import tools.refinery.interpreter.rete.recipes.RecipesPackage; |
10 | import tools.refinery.store.adapter.AbstractModelAdapterBuilder; | 10 | import tools.refinery.store.adapter.AbstractModelAdapterBuilder; |
11 | import tools.refinery.store.model.ModelStore; | 11 | import tools.refinery.store.model.ModelStore; |
12 | import tools.refinery.store.query.dnf.AnyQuery; | 12 | import tools.refinery.logic.dnf.AnyQuery; |
13 | import tools.refinery.store.query.dnf.Dnf; | 13 | import tools.refinery.logic.dnf.Dnf; |
14 | import tools.refinery.store.query.rewriter.CompositeRewriter; | 14 | import tools.refinery.logic.rewriter.CompositeRewriter; |
15 | import tools.refinery.store.query.rewriter.DnfRewriter; | 15 | import tools.refinery.logic.rewriter.DnfRewriter; |
16 | import tools.refinery.store.query.rewriter.DuplicateDnfRemover; | 16 | import tools.refinery.logic.rewriter.DuplicateDnfRemover; |
17 | import tools.refinery.store.query.rewriter.InputParameterResolver; | 17 | import tools.refinery.logic.rewriter.InputParameterResolver; |
18 | import tools.refinery.store.query.interpreter.QueryInterpreterBuilder; | 18 | import tools.refinery.store.query.interpreter.QueryInterpreterBuilder; |
19 | import tools.refinery.store.query.interpreter.internal.localsearch.FlatCostFunction; | 19 | import tools.refinery.store.query.interpreter.internal.localsearch.FlatCostFunction; |
20 | import tools.refinery.store.query.interpreter.internal.matcher.RawPatternMatcher; | 20 | import tools.refinery.store.query.interpreter.internal.matcher.RawPatternMatcher; |
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/QueryInterpreterStoreAdapterImpl.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/QueryInterpreterStoreAdapterImpl.java index 10e7a402..d1ec3e3e 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/QueryInterpreterStoreAdapterImpl.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/QueryInterpreterStoreAdapterImpl.java | |||
@@ -11,8 +11,8 @@ import tools.refinery.interpreter.api.InterpreterEngineOptions; | |||
11 | import tools.refinery.interpreter.matchers.context.IInputKey; | 11 | import tools.refinery.interpreter.matchers.context.IInputKey; |
12 | import tools.refinery.store.model.Model; | 12 | import tools.refinery.store.model.Model; |
13 | import tools.refinery.store.model.ModelStore; | 13 | import tools.refinery.store.model.ModelStore; |
14 | import tools.refinery.store.query.dnf.AnyQuery; | 14 | import tools.refinery.logic.dnf.AnyQuery; |
15 | import tools.refinery.store.query.dnf.Query; | 15 | import tools.refinery.logic.dnf.Query; |
16 | import tools.refinery.store.query.interpreter.QueryInterpreterStoreAdapter; | 16 | import tools.refinery.store.query.interpreter.QueryInterpreterStoreAdapter; |
17 | import tools.refinery.store.query.interpreter.internal.matcher.RawPatternMatcher; | 17 | import tools.refinery.store.query.interpreter.internal.matcher.RawPatternMatcher; |
18 | import tools.refinery.store.query.view.AnySymbolView; | 18 | import tools.refinery.store.query.view.AnySymbolView; |
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/context/RelationalQueryMetaContext.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/context/RelationalQueryMetaContext.java index 2b1ff2b4..117e81ba 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/context/RelationalQueryMetaContext.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/context/RelationalQueryMetaContext.java | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2021-2024 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
@@ -48,7 +48,7 @@ public class RelationalQueryMetaContext extends AbstractQueryMetaContext { | |||
48 | } | 48 | } |
49 | var symbolView = checkKey(implyingKey); | 49 | var symbolView = checkKey(implyingKey); |
50 | var relationViewImplications = symbolView.getImpliedRelationViews(); | 50 | var relationViewImplications = symbolView.getImpliedRelationViews(); |
51 | var inputKeyImplications = new HashSet<InputKeyImplication>(relationViewImplications.size()); | 51 | var inputKeyImplications = HashSet.<InputKeyImplication>newHashSet(relationViewImplications.size()); |
52 | for (var relationViewImplication : relationViewImplications) { | 52 | for (var relationViewImplication : relationViewImplications) { |
53 | if (!symbolView.equals(relationViewImplication.implyingView())) { | 53 | if (!symbolView.equals(relationViewImplication.implyingView())) { |
54 | throw new IllegalArgumentException("Relation view %s returned unrelated implication %s".formatted( | 54 | throw new IllegalArgumentException("Relation view %s returned unrelated implication %s".formatted( |
@@ -82,7 +82,7 @@ public class RelationalQueryMetaContext extends AbstractQueryMetaContext { | |||
82 | } | 82 | } |
83 | var relationView = checkKey(key); | 83 | var relationView = checkKey(key); |
84 | var functionalDependencies = relationView.getFunctionalDependencies(); | 84 | var functionalDependencies = relationView.getFunctionalDependencies(); |
85 | var flattened = new HashMap<Set<Integer>, Set<Integer>>(functionalDependencies.size()); | 85 | var flattened = HashMap.<Set<Integer>, Set<Integer>>newHashMap(functionalDependencies.size()); |
86 | for (var functionalDependency : functionalDependencies) { | 86 | for (var functionalDependency : functionalDependencies) { |
87 | var forEach = functionalDependency.forEach(); | 87 | var forEach = functionalDependency.forEach(); |
88 | checkValidIndices(relationView, forEach); | 88 | checkValidIndices(relationView, forEach); |
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/matcher/AbstractInterpretedMatcher.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/matcher/AbstractInterpretedMatcher.java index 8cec0bf6..8e6a74ed 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/matcher/AbstractInterpretedMatcher.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/matcher/AbstractInterpretedMatcher.java | |||
@@ -7,7 +7,7 @@ package tools.refinery.store.query.interpreter.internal.matcher; | |||
7 | 7 | ||
8 | import tools.refinery.interpreter.matchers.backend.IQueryResultProvider; | 8 | import tools.refinery.interpreter.matchers.backend.IQueryResultProvider; |
9 | import tools.refinery.interpreter.matchers.backend.IUpdateable; | 9 | import tools.refinery.interpreter.matchers.backend.IUpdateable; |
10 | import tools.refinery.store.query.dnf.Query; | 10 | import tools.refinery.logic.dnf.Query; |
11 | import tools.refinery.store.query.resultset.AbstractResultSet; | 11 | import tools.refinery.store.query.resultset.AbstractResultSet; |
12 | import tools.refinery.store.query.interpreter.internal.QueryInterpreterAdapterImpl; | 12 | import tools.refinery.store.query.interpreter.internal.QueryInterpreterAdapterImpl; |
13 | 13 | ||
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/matcher/InterpretedFunctionalMatcher.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/matcher/InterpretedFunctionalMatcher.java index 249664a4..bf707487 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/matcher/InterpretedFunctionalMatcher.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/matcher/InterpretedFunctionalMatcher.java | |||
@@ -11,7 +11,7 @@ import tools.refinery.interpreter.matchers.tuple.Tuples; | |||
11 | import tools.refinery.interpreter.rete.index.IterableIndexer; | 11 | import tools.refinery.interpreter.rete.index.IterableIndexer; |
12 | import tools.refinery.interpreter.rete.matcher.RetePatternMatcher; | 12 | import tools.refinery.interpreter.rete.matcher.RetePatternMatcher; |
13 | import tools.refinery.store.map.Cursor; | 13 | import tools.refinery.store.map.Cursor; |
14 | import tools.refinery.store.query.dnf.FunctionalQuery; | 14 | import tools.refinery.logic.dnf.FunctionalQuery; |
15 | import tools.refinery.store.query.interpreter.internal.QueryInterpreterAdapterImpl; | 15 | import tools.refinery.store.query.interpreter.internal.QueryInterpreterAdapterImpl; |
16 | import tools.refinery.store.tuple.Tuple; | 16 | import tools.refinery.store.tuple.Tuple; |
17 | 17 | ||
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/matcher/InterpretedRelationalMatcher.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/matcher/InterpretedRelationalMatcher.java index 9278b46d..9d9c3042 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/matcher/InterpretedRelationalMatcher.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/matcher/InterpretedRelationalMatcher.java | |||
@@ -12,7 +12,7 @@ import tools.refinery.interpreter.rete.index.Indexer; | |||
12 | import tools.refinery.interpreter.rete.matcher.RetePatternMatcher; | 12 | import tools.refinery.interpreter.rete.matcher.RetePatternMatcher; |
13 | import tools.refinery.store.map.Cursor; | 13 | import tools.refinery.store.map.Cursor; |
14 | import tools.refinery.store.map.Cursors; | 14 | import tools.refinery.store.map.Cursors; |
15 | import tools.refinery.store.query.dnf.RelationalQuery; | 15 | import tools.refinery.logic.dnf.RelationalQuery; |
16 | import tools.refinery.store.query.interpreter.internal.QueryInterpreterAdapterImpl; | 16 | import tools.refinery.store.query.interpreter.internal.QueryInterpreterAdapterImpl; |
17 | import tools.refinery.store.tuple.Tuple; | 17 | import tools.refinery.store.tuple.Tuple; |
18 | 18 | ||
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/CheckEvaluator.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/CheckEvaluator.java index 4a71e879..8cfc2226 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/CheckEvaluator.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/CheckEvaluator.java | |||
@@ -6,7 +6,7 @@ | |||
6 | package tools.refinery.store.query.interpreter.internal.pquery; | 6 | package tools.refinery.store.query.interpreter.internal.pquery; |
7 | 7 | ||
8 | import tools.refinery.interpreter.matchers.psystem.IValueProvider; | 8 | import tools.refinery.interpreter.matchers.psystem.IValueProvider; |
9 | import tools.refinery.store.query.term.Term; | 9 | import tools.refinery.logic.term.Term; |
10 | 10 | ||
11 | class CheckEvaluator extends TermEvaluator<Boolean> { | 11 | class CheckEvaluator extends TermEvaluator<Boolean> { |
12 | public CheckEvaluator(Term<Boolean> term) { | 12 | public CheckEvaluator(Term<Boolean> term) { |
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/Dnf2PQuery.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/Dnf2PQuery.java index 24205cf4..0ffaa6b2 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/Dnf2PQuery.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/Dnf2PQuery.java | |||
@@ -1,25 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2021-2024 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.query.interpreter.internal.pquery; | 6 | package tools.refinery.store.query.interpreter.internal.pquery; |
7 | 7 | ||
8 | import tools.refinery.interpreter.matchers.psystem.annotations.ParameterReference; | ||
9 | import tools.refinery.interpreter.matchers.psystem.basicdeferred.*; | ||
10 | import tools.refinery.interpreter.matchers.psystem.basicenumerables.*; | ||
11 | import tools.refinery.interpreter.matchers.psystem.basicenumerables.Connectivity; | ||
12 | import tools.refinery.store.query.Constraint; | ||
13 | import tools.refinery.store.query.dnf.Dnf; | ||
14 | import tools.refinery.store.query.dnf.DnfClause; | ||
15 | import tools.refinery.store.query.dnf.SymbolicParameter; | ||
16 | import tools.refinery.store.query.literal.*; | ||
17 | import tools.refinery.store.query.term.ConstantTerm; | ||
18 | import tools.refinery.store.query.term.StatefulAggregator; | ||
19 | import tools.refinery.store.query.term.StatelessAggregator; | ||
20 | import tools.refinery.store.query.term.Variable; | ||
21 | import tools.refinery.store.query.view.AnySymbolView; | ||
22 | import tools.refinery.store.util.CycleDetectingMapper; | ||
23 | import tools.refinery.interpreter.matchers.backend.IQueryBackendFactory; | 8 | import tools.refinery.interpreter.matchers.backend.IQueryBackendFactory; |
24 | import tools.refinery.interpreter.matchers.backend.QueryEvaluationHint; | 9 | import tools.refinery.interpreter.matchers.backend.QueryEvaluationHint; |
25 | import tools.refinery.interpreter.matchers.context.IInputKey; | 10 | import tools.refinery.interpreter.matchers.context.IInputKey; |
@@ -28,11 +13,27 @@ import tools.refinery.interpreter.matchers.psystem.PVariable; | |||
28 | import tools.refinery.interpreter.matchers.psystem.aggregations.BoundAggregator; | 13 | import tools.refinery.interpreter.matchers.psystem.aggregations.BoundAggregator; |
29 | import tools.refinery.interpreter.matchers.psystem.aggregations.IMultisetAggregationOperator; | 14 | import tools.refinery.interpreter.matchers.psystem.aggregations.IMultisetAggregationOperator; |
30 | import tools.refinery.interpreter.matchers.psystem.annotations.PAnnotation; | 15 | import tools.refinery.interpreter.matchers.psystem.annotations.PAnnotation; |
16 | import tools.refinery.interpreter.matchers.psystem.annotations.ParameterReference; | ||
17 | import tools.refinery.interpreter.matchers.psystem.basicdeferred.*; | ||
18 | import tools.refinery.interpreter.matchers.psystem.basicenumerables.Connectivity; | ||
19 | import tools.refinery.interpreter.matchers.psystem.basicenumerables.*; | ||
31 | import tools.refinery.interpreter.matchers.psystem.queries.PParameter; | 20 | import tools.refinery.interpreter.matchers.psystem.queries.PParameter; |
32 | import tools.refinery.interpreter.matchers.psystem.queries.PParameterDirection; | 21 | import tools.refinery.interpreter.matchers.psystem.queries.PParameterDirection; |
33 | import tools.refinery.interpreter.matchers.psystem.queries.PQuery; | 22 | import tools.refinery.interpreter.matchers.psystem.queries.PQuery; |
34 | import tools.refinery.interpreter.matchers.tuple.Tuple; | 23 | import tools.refinery.interpreter.matchers.tuple.Tuple; |
35 | import tools.refinery.interpreter.matchers.tuple.Tuples; | 24 | import tools.refinery.interpreter.matchers.tuple.Tuples; |
25 | import tools.refinery.logic.Constraint; | ||
26 | import tools.refinery.logic.dnf.Dnf; | ||
27 | import tools.refinery.logic.dnf.DnfClause; | ||
28 | import tools.refinery.logic.dnf.FunctionalDependency; | ||
29 | import tools.refinery.logic.dnf.SymbolicParameter; | ||
30 | import tools.refinery.logic.literal.*; | ||
31 | import tools.refinery.logic.term.ConstantTerm; | ||
32 | import tools.refinery.logic.term.StatefulAggregator; | ||
33 | import tools.refinery.logic.term.StatelessAggregator; | ||
34 | import tools.refinery.logic.term.Variable; | ||
35 | import tools.refinery.logic.util.CycleDetectingMapper; | ||
36 | import tools.refinery.store.query.view.AnySymbolView; | ||
36 | 37 | ||
37 | import java.util.ArrayList; | 38 | import java.util.ArrayList; |
38 | import java.util.HashMap; | 39 | import java.util.HashMap; |
@@ -79,15 +80,7 @@ public class Dnf2PQuery { | |||
79 | pQuery.setParameters(parameterList); | 80 | pQuery.setParameters(parameterList); |
80 | 81 | ||
81 | for (var functionalDependency : dnfQuery.getFunctionalDependencies()) { | 82 | for (var functionalDependency : dnfQuery.getFunctionalDependencies()) { |
82 | var functionalDependencyAnnotation = new PAnnotation("FunctionalDependency"); | 83 | var functionalDependencyAnnotation = getFunctionalDependencyAnnotation(functionalDependency); |
83 | for (var forEachVariable : functionalDependency.forEach()) { | ||
84 | var reference = new ParameterReference(forEachVariable.getUniqueName()); | ||
85 | functionalDependencyAnnotation.addAttribute("forEach", reference); | ||
86 | } | ||
87 | for (var uniqueVariable : functionalDependency.unique()) { | ||
88 | var reference = new ParameterReference(uniqueVariable.getUniqueName()); | ||
89 | functionalDependencyAnnotation.addAttribute("unique", reference); | ||
90 | } | ||
91 | pQuery.addAnnotation(functionalDependencyAnnotation); | 84 | pQuery.addAnnotation(functionalDependencyAnnotation); |
92 | } | 85 | } |
93 | 86 | ||
@@ -108,26 +101,33 @@ public class Dnf2PQuery { | |||
108 | return pQuery; | 101 | return pQuery; |
109 | } | 102 | } |
110 | 103 | ||
111 | private void translateLiteral(Literal literal, PBody body) { | 104 | private static PAnnotation getFunctionalDependencyAnnotation(FunctionalDependency<Variable> functionalDependency) { |
112 | if (literal instanceof EquivalenceLiteral equivalenceLiteral) { | 105 | var functionalDependencyAnnotation = new PAnnotation("FunctionalDependency"); |
113 | translateEquivalenceLiteral(equivalenceLiteral, body); | 106 | for (var forEachVariable : functionalDependency.forEach()) { |
114 | } else if (literal instanceof CallLiteral callLiteral) { | 107 | var reference = new ParameterReference(forEachVariable.getUniqueName()); |
115 | translateCallLiteral(callLiteral, body); | 108 | functionalDependencyAnnotation.addAttribute("forEach", reference); |
116 | } else if (literal instanceof ConstantLiteral constantLiteral) { | ||
117 | translateConstantLiteral(constantLiteral, body); | ||
118 | } else if (literal instanceof AssignLiteral<?> assignLiteral) { | ||
119 | translateAssignLiteral(assignLiteral, body); | ||
120 | } else if (literal instanceof CheckLiteral checkLiteral) { | ||
121 | translateCheckLiteral(checkLiteral, body); | ||
122 | } else if (literal instanceof CountLiteral countLiteral) { | ||
123 | translateCountLiteral(countLiteral, body); | ||
124 | } else if (literal instanceof AggregationLiteral<?, ?> aggregationLiteral) { | ||
125 | translateAggregationLiteral(aggregationLiteral, body); | ||
126 | } else if (literal instanceof RepresentativeElectionLiteral representativeElectionLiteral) { | ||
127 | translateRepresentativeElectionLiteral(representativeElectionLiteral, body); | ||
128 | } else { | ||
129 | throw new IllegalArgumentException("Unknown literal: " + literal.toString()); | ||
130 | } | 109 | } |
110 | for (var uniqueVariable : functionalDependency.unique()) { | ||
111 | var reference = new ParameterReference(uniqueVariable.getUniqueName()); | ||
112 | functionalDependencyAnnotation.addAttribute("unique", reference); | ||
113 | } | ||
114 | return functionalDependencyAnnotation; | ||
115 | } | ||
116 | |||
117 | private void translateLiteral(Literal literal, PBody body) { | ||
118 | switch (literal) { | ||
119 | case EquivalenceLiteral equivalenceLiteral -> translateEquivalenceLiteral(equivalenceLiteral, body); | ||
120 | case CallLiteral callLiteral -> translateCallLiteral(callLiteral, body); | ||
121 | case ConstantLiteral constantLiteral -> translateConstantLiteral(constantLiteral, body); | ||
122 | case AssignLiteral<?> assignLiteral -> translateAssignLiteral(assignLiteral, body); | ||
123 | case CheckLiteral checkLiteral -> translateCheckLiteral(checkLiteral, body); | ||
124 | case CountLiteral countLiteral -> translateCountLiteral(countLiteral, body); | ||
125 | case AggregationLiteral<?, ?> aggregationLiteral -> translateAggregationLiteral(aggregationLiteral, body); | ||
126 | case LeftJoinLiteral<?> leftJoinLiteral -> translateLeftJoinLiteral(leftJoinLiteral, body); | ||
127 | case RepresentativeElectionLiteral representativeElectionLiteral -> | ||
128 | translateRepresentativeElectionLiteral(representativeElectionLiteral, body); | ||
129 | case null, default -> throw new IllegalArgumentException("Unknown literal: " + literal); | ||
130 | } | ||
131 | } | 131 | } |
132 | 132 | ||
133 | private void translateEquivalenceLiteral(EquivalenceLiteral equivalenceLiteral, PBody body) { | 133 | private void translateEquivalenceLiteral(EquivalenceLiteral equivalenceLiteral, PBody body) { |
@@ -244,6 +244,21 @@ public class Dnf2PQuery { | |||
244 | aggregatedColumn); | 244 | aggregatedColumn); |
245 | } | 245 | } |
246 | 246 | ||
247 | private <T> void translateLeftJoinLiteral(LeftJoinLiteral<T> leftJoinLiteral, PBody body) { | ||
248 | var wrappedCall = wrapperFactory.maybeWrapConstraint(leftJoinLiteral); | ||
249 | var substitution = translateSubstitution(wrappedCall.remappedArguments(), body); | ||
250 | var placeholderVariable = body.getOrCreateVariableByName( | ||
251 | leftJoinLiteral.getPlaceholderVariable().getUniqueName()); | ||
252 | var optionalColumn = substitution.invertIndex().get(placeholderVariable); | ||
253 | if (optionalColumn == null) { | ||
254 | throw new IllegalStateException("Placeholder variable %s not found in substitution %s" | ||
255 | .formatted(placeholderVariable, substitution)); | ||
256 | } | ||
257 | var resultVariable = body.getOrCreateVariableByName(leftJoinLiteral.getResultVariable().getUniqueName()); | ||
258 | new LeftJoinConstraint(body, substitution, wrappedCall.pattern(), resultVariable, optionalColumn, | ||
259 | leftJoinLiteral.getDefaultValue()); | ||
260 | } | ||
261 | |||
247 | private void translateRepresentativeElectionLiteral(RepresentativeElectionLiteral literal, PBody body) { | 262 | private void translateRepresentativeElectionLiteral(RepresentativeElectionLiteral literal, PBody body) { |
248 | var substitution = translateSubstitution(literal.getArguments(), body); | 263 | var substitution = translateSubstitution(literal.getArguments(), body); |
249 | var pattern = wrapConstraintWithIdentityArguments(literal.getTarget()); | 264 | var pattern = wrapConstraintWithIdentityArguments(literal.getTarget()); |
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/QueryWrapperFactory.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/QueryWrapperFactory.java index a710dab3..f855f1f0 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/QueryWrapperFactory.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/QueryWrapperFactory.java | |||
@@ -16,15 +16,15 @@ import tools.refinery.interpreter.matchers.psystem.queries.PQuery; | |||
16 | import tools.refinery.interpreter.matchers.psystem.queries.PVisibility; | 16 | import tools.refinery.interpreter.matchers.psystem.queries.PVisibility; |
17 | import tools.refinery.interpreter.matchers.tuple.Tuple; | 17 | import tools.refinery.interpreter.matchers.tuple.Tuple; |
18 | import tools.refinery.interpreter.matchers.tuple.Tuples; | 18 | import tools.refinery.interpreter.matchers.tuple.Tuples; |
19 | import tools.refinery.store.query.Constraint; | 19 | import tools.refinery.logic.Constraint; |
20 | import tools.refinery.store.query.dnf.Dnf; | 20 | import tools.refinery.logic.dnf.Dnf; |
21 | import tools.refinery.store.query.dnf.DnfUtils; | 21 | import tools.refinery.logic.dnf.DnfUtils; |
22 | import tools.refinery.store.query.literal.AbstractCallLiteral; | 22 | import tools.refinery.logic.literal.AbstractCallLiteral; |
23 | import tools.refinery.store.query.term.ParameterDirection; | 23 | import tools.refinery.logic.term.ParameterDirection; |
24 | import tools.refinery.store.query.term.Variable; | 24 | import tools.refinery.logic.term.Variable; |
25 | import tools.refinery.store.query.view.AnySymbolView; | 25 | import tools.refinery.store.query.view.AnySymbolView; |
26 | import tools.refinery.store.query.view.SymbolView; | 26 | import tools.refinery.store.query.view.SymbolView; |
27 | import tools.refinery.store.util.CycleDetectingMapper; | 27 | import tools.refinery.logic.util.CycleDetectingMapper; |
28 | 28 | ||
29 | import java.util.*; | 29 | import java.util.*; |
30 | import java.util.function.ToIntFunction; | 30 | import java.util.function.ToIntFunction; |
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/StatefulMultisetAggregator.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/StatefulMultisetAggregator.java index 7552117b..936b3513 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/StatefulMultisetAggregator.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/StatefulMultisetAggregator.java | |||
@@ -6,8 +6,8 @@ | |||
6 | package tools.refinery.store.query.interpreter.internal.pquery; | 6 | package tools.refinery.store.query.interpreter.internal.pquery; |
7 | 7 | ||
8 | import tools.refinery.interpreter.matchers.psystem.aggregations.IMultisetAggregationOperator; | 8 | import tools.refinery.interpreter.matchers.psystem.aggregations.IMultisetAggregationOperator; |
9 | import tools.refinery.store.query.term.StatefulAggregate; | 9 | import tools.refinery.logic.term.StatefulAggregate; |
10 | import tools.refinery.store.query.term.StatefulAggregator; | 10 | import tools.refinery.logic.term.StatefulAggregator; |
11 | 11 | ||
12 | import java.util.stream.Stream; | 12 | import java.util.stream.Stream; |
13 | 13 | ||
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/StatelessMultisetAggregator.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/StatelessMultisetAggregator.java index 2da7ba87..01432a5b 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/StatelessMultisetAggregator.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/StatelessMultisetAggregator.java | |||
@@ -6,7 +6,7 @@ | |||
6 | package tools.refinery.store.query.interpreter.internal.pquery; | 6 | package tools.refinery.store.query.interpreter.internal.pquery; |
7 | 7 | ||
8 | import tools.refinery.interpreter.matchers.psystem.aggregations.IMultisetAggregationOperator; | 8 | import tools.refinery.interpreter.matchers.psystem.aggregations.IMultisetAggregationOperator; |
9 | import tools.refinery.store.query.term.StatelessAggregator; | 9 | import tools.refinery.logic.term.StatelessAggregator; |
10 | 10 | ||
11 | import java.util.stream.Stream; | 11 | import java.util.stream.Stream; |
12 | 12 | ||
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/TermEvaluator.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/TermEvaluator.java index ed991091..8da9ece7 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/TermEvaluator.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/TermEvaluator.java | |||
@@ -5,8 +5,8 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.query.interpreter.internal.pquery; | 6 | package tools.refinery.store.query.interpreter.internal.pquery; |
7 | 7 | ||
8 | import tools.refinery.store.query.term.Term; | 8 | import tools.refinery.logic.term.Term; |
9 | import tools.refinery.store.query.term.Variable; | 9 | import tools.refinery.logic.term.Variable; |
10 | import tools.refinery.interpreter.matchers.psystem.IExpressionEvaluator; | 10 | import tools.refinery.interpreter.matchers.psystem.IExpressionEvaluator; |
11 | import tools.refinery.interpreter.matchers.psystem.IValueProvider; | 11 | import tools.refinery.interpreter.matchers.psystem.IValueProvider; |
12 | 12 | ||
diff --git a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/ValueProviderBasedValuation.java b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/ValueProviderBasedValuation.java index 4124c9bb..a69c8bd2 100644 --- a/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/ValueProviderBasedValuation.java +++ b/subprojects/store-query-interpreter/src/main/java/tools/refinery/store/query/interpreter/internal/pquery/ValueProviderBasedValuation.java | |||
@@ -6,8 +6,8 @@ | |||
6 | package tools.refinery.store.query.interpreter.internal.pquery; | 6 | package tools.refinery.store.query.interpreter.internal.pquery; |
7 | 7 | ||
8 | import tools.refinery.interpreter.matchers.psystem.IValueProvider; | 8 | import tools.refinery.interpreter.matchers.psystem.IValueProvider; |
9 | import tools.refinery.store.query.term.DataVariable; | 9 | import tools.refinery.logic.term.DataVariable; |
10 | import tools.refinery.store.query.valuation.Valuation; | 10 | import tools.refinery.logic.valuation.Valuation; |
11 | 11 | ||
12 | public record ValueProviderBasedValuation(IValueProvider valueProvider) implements Valuation { | 12 | public record ValueProviderBasedValuation(IValueProvider valueProvider) implements Valuation { |
13 | @Override | 13 | @Override |
diff --git a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/AggregatorBatchingTest.java b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/AggregatorBatchingTest.java index d8e06d82..209d7ac0 100644 --- a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/AggregatorBatchingTest.java +++ b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/AggregatorBatchingTest.java | |||
@@ -9,10 +9,10 @@ import org.junit.jupiter.api.Test; | |||
9 | import tools.refinery.store.model.Model; | 9 | import tools.refinery.store.model.Model; |
10 | import tools.refinery.store.model.ModelStore; | 10 | import tools.refinery.store.model.ModelStore; |
11 | import tools.refinery.store.query.ModelQueryAdapter; | 11 | import tools.refinery.store.query.ModelQueryAdapter; |
12 | import tools.refinery.store.query.dnf.Query; | 12 | import tools.refinery.logic.dnf.Query; |
13 | import tools.refinery.store.query.term.StatefulAggregate; | 13 | import tools.refinery.logic.term.StatefulAggregate; |
14 | import tools.refinery.store.query.term.StatefulAggregator; | 14 | import tools.refinery.logic.term.StatefulAggregator; |
15 | import tools.refinery.store.query.term.Variable; | 15 | import tools.refinery.logic.term.Variable; |
16 | import tools.refinery.store.query.view.AnySymbolView; | 16 | import tools.refinery.store.query.view.AnySymbolView; |
17 | import tools.refinery.store.query.view.FunctionView; | 17 | import tools.refinery.store.query.view.FunctionView; |
18 | import tools.refinery.store.query.view.KeyOnlyView; | 18 | import tools.refinery.store.query.view.KeyOnlyView; |
diff --git a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/DiagonalQueryTest.java b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/DiagonalQueryTest.java index 76de8679..eba7173b 100644 --- a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/DiagonalQueryTest.java +++ b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/DiagonalQueryTest.java | |||
@@ -8,8 +8,8 @@ package tools.refinery.store.query.interpreter; | |||
8 | import tools.refinery.interpreter.matchers.backend.QueryEvaluationHint; | 8 | import tools.refinery.interpreter.matchers.backend.QueryEvaluationHint; |
9 | import tools.refinery.store.model.ModelStore; | 9 | import tools.refinery.store.model.ModelStore; |
10 | import tools.refinery.store.query.ModelQueryAdapter; | 10 | import tools.refinery.store.query.ModelQueryAdapter; |
11 | import tools.refinery.store.query.dnf.Dnf; | 11 | import tools.refinery.logic.dnf.Dnf; |
12 | import tools.refinery.store.query.dnf.Query; | 12 | import tools.refinery.logic.dnf.Query; |
13 | import tools.refinery.store.query.interpreter.tests.QueryEngineTest; | 13 | import tools.refinery.store.query.interpreter.tests.QueryEngineTest; |
14 | import tools.refinery.store.query.view.AnySymbolView; | 14 | import tools.refinery.store.query.view.AnySymbolView; |
15 | import tools.refinery.store.query.view.FunctionView; | 15 | import tools.refinery.store.query.view.FunctionView; |
@@ -21,8 +21,8 @@ import java.util.List; | |||
21 | import java.util.Map; | 21 | import java.util.Map; |
22 | import java.util.Optional; | 22 | import java.util.Optional; |
23 | 23 | ||
24 | import static tools.refinery.store.query.literal.Literals.not; | 24 | import static tools.refinery.logic.literal.Literals.not; |
25 | import static tools.refinery.store.query.term.int_.IntTerms.INT_SUM; | 25 | import static tools.refinery.logic.term.int_.IntTerms.INT_SUM; |
26 | import static tools.refinery.store.query.interpreter.tests.QueryAssertions.assertNullableResults; | 26 | import static tools.refinery.store.query.interpreter.tests.QueryAssertions.assertNullableResults; |
27 | import static tools.refinery.store.query.interpreter.tests.QueryAssertions.assertResults; | 27 | import static tools.refinery.store.query.interpreter.tests.QueryAssertions.assertResults; |
28 | 28 | ||
diff --git a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/FunctionalQueryTest.java b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/FunctionalQueryTest.java index b6c96676..c845e5ff 100644 --- a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/FunctionalQueryTest.java +++ b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/FunctionalQueryTest.java | |||
@@ -9,15 +9,15 @@ import tools.refinery.interpreter.matchers.backend.QueryEvaluationHint; | |||
9 | import tools.refinery.store.map.Cursor; | 9 | import tools.refinery.store.map.Cursor; |
10 | import tools.refinery.store.model.ModelStore; | 10 | import tools.refinery.store.model.ModelStore; |
11 | import tools.refinery.store.query.ModelQueryAdapter; | 11 | import tools.refinery.store.query.ModelQueryAdapter; |
12 | import tools.refinery.store.query.dnf.Query; | 12 | import tools.refinery.logic.dnf.Query; |
13 | import tools.refinery.store.query.term.Variable; | 13 | import tools.refinery.logic.term.Variable; |
14 | import tools.refinery.store.query.interpreter.tests.QueryEngineTest; | 14 | import tools.refinery.store.query.interpreter.tests.QueryEngineTest; |
15 | import tools.refinery.store.query.view.AnySymbolView; | 15 | import tools.refinery.store.query.view.AnySymbolView; |
16 | import tools.refinery.store.query.view.FilteredView; | 16 | import tools.refinery.store.query.view.FilteredView; |
17 | import tools.refinery.store.query.view.FunctionView; | 17 | import tools.refinery.store.query.view.FunctionView; |
18 | import tools.refinery.store.query.view.KeyOnlyView; | 18 | import tools.refinery.store.query.view.KeyOnlyView; |
19 | import tools.refinery.store.representation.Symbol; | 19 | import tools.refinery.store.representation.Symbol; |
20 | import tools.refinery.store.representation.TruthValue; | 20 | import tools.refinery.logic.term.truthvalue.TruthValue; |
21 | import tools.refinery.store.tuple.Tuple; | 21 | import tools.refinery.store.tuple.Tuple; |
22 | 22 | ||
23 | import java.util.List; | 23 | import java.util.List; |
@@ -29,8 +29,8 @@ import static org.hamcrest.Matchers.is; | |||
29 | import static org.hamcrest.Matchers.nullValue; | 29 | import static org.hamcrest.Matchers.nullValue; |
30 | import static org.junit.jupiter.api.Assertions.assertAll; | 30 | import static org.junit.jupiter.api.Assertions.assertAll; |
31 | import static org.junit.jupiter.api.Assertions.assertThrows; | 31 | import static org.junit.jupiter.api.Assertions.assertThrows; |
32 | import static tools.refinery.store.query.literal.Literals.check; | 32 | import static tools.refinery.logic.literal.Literals.check; |
33 | import static tools.refinery.store.query.term.int_.IntTerms.*; | 33 | import static tools.refinery.logic.term.int_.IntTerms.*; |
34 | import static tools.refinery.store.query.interpreter.tests.QueryAssertions.assertNullableResults; | 34 | import static tools.refinery.store.query.interpreter.tests.QueryAssertions.assertNullableResults; |
35 | import static tools.refinery.store.query.interpreter.tests.QueryAssertions.assertResults; | 35 | import static tools.refinery.store.query.interpreter.tests.QueryAssertions.assertResults; |
36 | 36 | ||
@@ -554,7 +554,6 @@ class FunctionalQueryTest { | |||
554 | friendInterpretation.put(Tuple.of(1, 2), TruthValue.TRUE); | 554 | friendInterpretation.put(Tuple.of(1, 2), TruthValue.TRUE); |
555 | 555 | ||
556 | queryEngine.flushChanges(); | 556 | queryEngine.flushChanges(); |
557 | queryEngine.flushChanges(); | ||
558 | assertNullableResults(Map.of( | 557 | assertNullableResults(Map.of( |
559 | Tuple.of(0), Optional.of(25), | 558 | Tuple.of(0), Optional.of(25), |
560 | Tuple.of(1), Optional.of(32), | 559 | Tuple.of(1), Optional.of(32), |
diff --git a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/LeftJoinTest.java b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/LeftJoinTest.java new file mode 100644 index 00000000..6633b3b1 --- /dev/null +++ b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/LeftJoinTest.java | |||
@@ -0,0 +1,129 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.query.interpreter; | ||
7 | |||
8 | import org.junit.jupiter.api.Test; | ||
9 | import tools.refinery.store.model.ModelStore; | ||
10 | import tools.refinery.store.query.ModelQueryAdapter; | ||
11 | import tools.refinery.logic.dnf.Query; | ||
12 | import tools.refinery.logic.term.int_.IntTerms; | ||
13 | import tools.refinery.store.query.view.AnySymbolView; | ||
14 | import tools.refinery.store.query.view.FunctionView; | ||
15 | import tools.refinery.store.query.view.KeyOnlyView; | ||
16 | import tools.refinery.store.representation.Symbol; | ||
17 | import tools.refinery.store.tuple.Tuple; | ||
18 | |||
19 | import java.util.List; | ||
20 | import java.util.Map; | ||
21 | import java.util.Optional; | ||
22 | |||
23 | import static tools.refinery.store.query.interpreter.tests.QueryAssertions.assertNullableResults; | ||
24 | import static tools.refinery.store.query.interpreter.tests.QueryAssertions.assertResults; | ||
25 | |||
26 | class LeftJoinTest { | ||
27 | private static final Symbol<Boolean> person = Symbol.of("Person", 1); | ||
28 | private static final Symbol<Integer> age = Symbol.of("age", 1, Integer.class); | ||
29 | private static final AnySymbolView personView = new KeyOnlyView<>(person); | ||
30 | private static final FunctionView<Integer> ageView = new FunctionView<>(age); | ||
31 | |||
32 | @Test | ||
33 | void unarySymbolTest() { | ||
34 | var query = Query.of("Query", Integer.class, (builder, p1, output) -> builder | ||
35 | .clause( | ||
36 | personView.call(p1), | ||
37 | output.assign(ageView.leftJoin(18, p1)) | ||
38 | )); | ||
39 | |||
40 | var store = ModelStore.builder() | ||
41 | .symbols(person, age) | ||
42 | .with(QueryInterpreterAdapter.builder() | ||
43 | .queries(query)) | ||
44 | .build(); | ||
45 | |||
46 | var model = store.createEmptyModel(); | ||
47 | var personInterpretation = model.getInterpretation(person); | ||
48 | var ageInterpretation = model.getInterpretation(age); | ||
49 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
50 | var queryResultSet = queryEngine.getResultSet(query); | ||
51 | |||
52 | personInterpretation.put(Tuple.of(0), true); | ||
53 | personInterpretation.put(Tuple.of(1), true); | ||
54 | personInterpretation.put(Tuple.of(2), true); | ||
55 | |||
56 | ageInterpretation.put(Tuple.of(2), 24); | ||
57 | |||
58 | queryEngine.flushChanges(); | ||
59 | assertNullableResults(Map.of( | ||
60 | Tuple.of(0), Optional.of(18), | ||
61 | Tuple.of(1), Optional.of(18), | ||
62 | Tuple.of(2), Optional.of(24), | ||
63 | Tuple.of(3), Optional.empty() | ||
64 | ), queryResultSet); | ||
65 | |||
66 | personInterpretation.put(Tuple.of(0), false); | ||
67 | |||
68 | ageInterpretation.put(Tuple.of(1), 20); | ||
69 | ageInterpretation.put(Tuple.of(2), null); | ||
70 | |||
71 | queryEngine.flushChanges(); | ||
72 | assertNullableResults(Map.of( | ||
73 | Tuple.of(0), Optional.empty(), | ||
74 | Tuple.of(1), Optional.of(20), | ||
75 | Tuple.of(2), Optional.of(18), | ||
76 | Tuple.of(3), Optional.empty() | ||
77 | ), queryResultSet); | ||
78 | } | ||
79 | |||
80 | @Test | ||
81 | void unarySymbolWithAssignmentTest() { | ||
82 | // Tests an edge case where the outer joined variable is already bound in the query plan. | ||
83 | var query = Query.of("Query", (builder, p1) -> builder | ||
84 | .clause(Integer.class, v1 -> List.of( | ||
85 | personView.call(p1), | ||
86 | v1.assign(IntTerms.constant(18)), | ||
87 | v1.assign(ageView.leftJoin(18, p1)) | ||
88 | ))); | ||
89 | |||
90 | var store = ModelStore.builder() | ||
91 | .symbols(person, age) | ||
92 | .with(QueryInterpreterAdapter.builder() | ||
93 | .queries(query)) | ||
94 | .build(); | ||
95 | |||
96 | var model = store.createEmptyModel(); | ||
97 | var personInterpretation = model.getInterpretation(person); | ||
98 | var ageInterpretation = model.getInterpretation(age); | ||
99 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
100 | var queryResultSet = queryEngine.getResultSet(query); | ||
101 | |||
102 | personInterpretation.put(Tuple.of(0), true); | ||
103 | personInterpretation.put(Tuple.of(1), true); | ||
104 | personInterpretation.put(Tuple.of(2), true); | ||
105 | |||
106 | ageInterpretation.put(Tuple.of(2), 24); | ||
107 | |||
108 | queryEngine.flushChanges(); | ||
109 | assertResults(Map.of( | ||
110 | Tuple.of(0), true, | ||
111 | Tuple.of(1), true, | ||
112 | Tuple.of(2), false, | ||
113 | Tuple.of(3), false | ||
114 | ), queryResultSet); | ||
115 | |||
116 | personInterpretation.put(Tuple.of(0), false); | ||
117 | |||
118 | ageInterpretation.put(Tuple.of(1), 20); | ||
119 | ageInterpretation.put(Tuple.of(2), null); | ||
120 | |||
121 | queryEngine.flushChanges(); | ||
122 | assertResults(Map.of( | ||
123 | Tuple.of(0), false, | ||
124 | Tuple.of(1), false, | ||
125 | Tuple.of(2), true, | ||
126 | Tuple.of(3), false | ||
127 | ), queryResultSet); | ||
128 | } | ||
129 | } | ||
diff --git a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/OrderedResultSetTest.java b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/OrderedResultSetTest.java index 96d0f302..cc3ddc10 100644 --- a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/OrderedResultSetTest.java +++ b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/OrderedResultSetTest.java | |||
@@ -8,9 +8,9 @@ package tools.refinery.store.query.interpreter; | |||
8 | import org.junit.jupiter.api.Test; | 8 | import org.junit.jupiter.api.Test; |
9 | import tools.refinery.store.model.ModelStore; | 9 | import tools.refinery.store.model.ModelStore; |
10 | import tools.refinery.store.query.ModelQueryAdapter; | 10 | import tools.refinery.store.query.ModelQueryAdapter; |
11 | import tools.refinery.store.query.dnf.Query; | 11 | import tools.refinery.logic.dnf.Query; |
12 | import tools.refinery.store.query.resultset.OrderedResultSet; | 12 | import tools.refinery.store.query.resultset.OrderedResultSet; |
13 | import tools.refinery.store.query.term.Variable; | 13 | import tools.refinery.logic.term.Variable; |
14 | import tools.refinery.store.query.view.AnySymbolView; | 14 | import tools.refinery.store.query.view.AnySymbolView; |
15 | import tools.refinery.store.query.view.KeyOnlyView; | 15 | import tools.refinery.store.query.view.KeyOnlyView; |
16 | import tools.refinery.store.representation.Symbol; | 16 | import tools.refinery.store.representation.Symbol; |
diff --git a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/QueryTest.java b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/QueryTest.java index 72728dcd..59f43147 100644 --- a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/QueryTest.java +++ b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/QueryTest.java | |||
@@ -9,26 +9,26 @@ import tools.refinery.interpreter.matchers.backend.QueryEvaluationHint; | |||
9 | import org.junit.jupiter.api.Test; | 9 | import org.junit.jupiter.api.Test; |
10 | import tools.refinery.store.model.ModelStore; | 10 | import tools.refinery.store.model.ModelStore; |
11 | import tools.refinery.store.query.ModelQueryAdapter; | 11 | import tools.refinery.store.query.ModelQueryAdapter; |
12 | import tools.refinery.store.query.dnf.Dnf; | 12 | import tools.refinery.logic.dnf.Dnf; |
13 | import tools.refinery.store.query.dnf.Query; | 13 | import tools.refinery.logic.dnf.Query; |
14 | import tools.refinery.store.query.term.ParameterDirection; | 14 | import tools.refinery.logic.term.ParameterDirection; |
15 | import tools.refinery.store.query.term.Variable; | 15 | import tools.refinery.logic.term.Variable; |
16 | import tools.refinery.store.query.interpreter.tests.QueryEngineTest; | 16 | import tools.refinery.store.query.interpreter.tests.QueryEngineTest; |
17 | import tools.refinery.store.query.view.AnySymbolView; | 17 | import tools.refinery.store.query.view.AnySymbolView; |
18 | import tools.refinery.store.query.view.FilteredView; | 18 | import tools.refinery.store.query.view.FilteredView; |
19 | import tools.refinery.store.query.view.FunctionView; | 19 | import tools.refinery.store.query.view.FunctionView; |
20 | import tools.refinery.store.query.view.KeyOnlyView; | 20 | import tools.refinery.store.query.view.KeyOnlyView; |
21 | import tools.refinery.store.representation.Symbol; | 21 | import tools.refinery.store.representation.Symbol; |
22 | import tools.refinery.store.representation.TruthValue; | 22 | import tools.refinery.logic.term.truthvalue.TruthValue; |
23 | import tools.refinery.store.tuple.Tuple; | 23 | import tools.refinery.store.tuple.Tuple; |
24 | 24 | ||
25 | import java.util.List; | 25 | import java.util.List; |
26 | import java.util.Map; | 26 | import java.util.Map; |
27 | 27 | ||
28 | import static tools.refinery.store.query.literal.Literals.check; | 28 | import static tools.refinery.logic.literal.Literals.check; |
29 | import static tools.refinery.store.query.literal.Literals.not; | 29 | import static tools.refinery.logic.literal.Literals.not; |
30 | import static tools.refinery.store.query.term.int_.IntTerms.constant; | 30 | import static tools.refinery.logic.term.int_.IntTerms.constant; |
31 | import static tools.refinery.store.query.term.int_.IntTerms.greaterEq; | 31 | import static tools.refinery.logic.term.int_.IntTerms.greaterEq; |
32 | import static tools.refinery.store.query.interpreter.tests.QueryAssertions.assertResults; | 32 | import static tools.refinery.store.query.interpreter.tests.QueryAssertions.assertResults; |
33 | 33 | ||
34 | class QueryTest { | 34 | class QueryTest { |
diff --git a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/QueryTransactionTest.java b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/QueryTransactionTest.java index 1cd05d91..eb1ed68a 100644 --- a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/QueryTransactionTest.java +++ b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/QueryTransactionTest.java | |||
@@ -9,8 +9,8 @@ import tools.refinery.interpreter.matchers.backend.QueryEvaluationHint; | |||
9 | import org.junit.jupiter.api.Test; | 9 | import org.junit.jupiter.api.Test; |
10 | import tools.refinery.store.model.ModelStore; | 10 | import tools.refinery.store.model.ModelStore; |
11 | import tools.refinery.store.query.ModelQueryAdapter; | 11 | import tools.refinery.store.query.ModelQueryAdapter; |
12 | import tools.refinery.store.query.dnf.Query; | 12 | import tools.refinery.logic.dnf.Query; |
13 | import tools.refinery.store.query.dnf.RelationalQuery; | 13 | import tools.refinery.logic.dnf.RelationalQuery; |
14 | import tools.refinery.store.query.view.AnySymbolView; | 14 | import tools.refinery.store.query.view.AnySymbolView; |
15 | import tools.refinery.store.query.view.FilteredView; | 15 | import tools.refinery.store.query.view.FilteredView; |
16 | import tools.refinery.store.query.view.FunctionView; | 16 | import tools.refinery.store.query.view.FunctionView; |
diff --git a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/StronglyConnectedComponentsTest.java b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/StronglyConnectedComponentsTest.java index edbd9aff..f8b12d19 100644 --- a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/StronglyConnectedComponentsTest.java +++ b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/StronglyConnectedComponentsTest.java | |||
@@ -6,11 +6,11 @@ | |||
6 | package tools.refinery.store.query.interpreter; | 6 | package tools.refinery.store.query.interpreter; |
7 | 7 | ||
8 | import org.junit.jupiter.api.Test; | 8 | import org.junit.jupiter.api.Test; |
9 | import tools.refinery.logic.dnf.Query; | ||
10 | import tools.refinery.logic.literal.Connectivity; | ||
11 | import tools.refinery.logic.literal.RepresentativeElectionLiteral; | ||
9 | import tools.refinery.store.model.ModelStore; | 12 | import tools.refinery.store.model.ModelStore; |
10 | import tools.refinery.store.query.ModelQueryAdapter; | 13 | import tools.refinery.store.query.ModelQueryAdapter; |
11 | import tools.refinery.store.query.dnf.Query; | ||
12 | import tools.refinery.store.query.literal.Connectivity; | ||
13 | import tools.refinery.store.query.literal.RepresentativeElectionLiteral; | ||
14 | import tools.refinery.store.query.view.AnySymbolView; | 14 | import tools.refinery.store.query.view.AnySymbolView; |
15 | import tools.refinery.store.query.view.KeyOnlyView; | 15 | import tools.refinery.store.query.view.KeyOnlyView; |
16 | import tools.refinery.store.representation.Symbol; | 16 | import tools.refinery.store.representation.Symbol; |
diff --git a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/WeaklyConnectedComponentsTest.java b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/WeaklyConnectedComponentsTest.java index 3fc85480..95b37f09 100644 --- a/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/WeaklyConnectedComponentsTest.java +++ b/subprojects/store-query-interpreter/src/test/java/tools/refinery/store/query/interpreter/WeaklyConnectedComponentsTest.java | |||
@@ -6,11 +6,11 @@ | |||
6 | package tools.refinery.store.query.interpreter; | 6 | package tools.refinery.store.query.interpreter; |
7 | 7 | ||
8 | import org.junit.jupiter.api.Test; | 8 | import org.junit.jupiter.api.Test; |
9 | import tools.refinery.logic.dnf.Query; | ||
10 | import tools.refinery.logic.literal.Connectivity; | ||
11 | import tools.refinery.logic.literal.RepresentativeElectionLiteral; | ||
9 | import tools.refinery.store.model.ModelStore; | 12 | import tools.refinery.store.model.ModelStore; |
10 | import tools.refinery.store.query.ModelQueryAdapter; | 13 | import tools.refinery.store.query.ModelQueryAdapter; |
11 | import tools.refinery.store.query.dnf.Query; | ||
12 | import tools.refinery.store.query.literal.Connectivity; | ||
13 | import tools.refinery.store.query.literal.RepresentativeElectionLiteral; | ||
14 | import tools.refinery.store.query.view.AnySymbolView; | 14 | import tools.refinery.store.query.view.AnySymbolView; |
15 | import tools.refinery.store.query.view.KeyOnlyView; | 15 | import tools.refinery.store.query.view.KeyOnlyView; |
16 | import tools.refinery.store.representation.Symbol; | 16 | import tools.refinery.store.representation.Symbol; |