diff options
author | 2021-10-22 02:17:17 +0200 | |
---|---|---|
committer | 2021-10-22 02:18:25 +0200 | |
commit | 5729c9069c135f7720b36f76821e82f4b6bc01f1 (patch) | |
tree | ffa9edd03d468a5fc539148784ad36481cf63542 /store/src/main/java | |
parent | Merge branch 'graphs4value:main' into main (diff) | |
download | refinery-5729c9069c135f7720b36f76821e82f4b6bc01f1.tar.gz refinery-5729c9069c135f7720b36f76821e82f4b6bc01f1.tar.zst refinery-5729c9069c135f7720b36f76821e82f4b6bc01f1.zip |
Test compilation fixes for Query building
Diffstat (limited to 'store/src/main/java')
-rw-r--r-- | store/src/main/java/tools/refinery/store/query/internal/PredicateTranslator.java | 210 |
1 files changed, 0 insertions, 210 deletions
diff --git a/store/src/main/java/tools/refinery/store/query/internal/PredicateTranslator.java b/store/src/main/java/tools/refinery/store/query/internal/PredicateTranslator.java deleted file mode 100644 index 6b050182..00000000 --- a/store/src/main/java/tools/refinery/store/query/internal/PredicateTranslator.java +++ /dev/null | |||
@@ -1,210 +0,0 @@ | |||
1 | package tools.refinery.store.query.internal; | ||
2 | |||
3 | import java.util.ArrayList; | ||
4 | import java.util.HashMap; | ||
5 | import java.util.LinkedHashSet; | ||
6 | import java.util.LinkedList; | ||
7 | import java.util.List; | ||
8 | import java.util.Map; | ||
9 | import java.util.Set; | ||
10 | |||
11 | import org.eclipse.viatra.query.runtime.api.GenericPatternMatcher; | ||
12 | import org.eclipse.viatra.query.runtime.api.GenericQuerySpecification; | ||
13 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
14 | import org.eclipse.viatra.query.runtime.api.scope.QueryScope; | ||
15 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
16 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
17 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryReflexiveTransitiveClosure; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryTransitiveClosure; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.BasePQuery; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
31 | |||
32 | import tools.refinery.store.query.RelationalScope; | ||
33 | import tools.refinery.store.query.view.RelationView; | ||
34 | |||
35 | public class PredicateTranslator extends BasePQuery { | ||
36 | |||
37 | private final Map<String, PParameter> parameters = new HashMap<String, PParameter>(); | ||
38 | private String fullyQualifiedName; | ||
39 | private LinkedList<PBody> bodies = new LinkedList<PBody>(); | ||
40 | private List<ExportedParameter> symbolicParameters; | ||
41 | |||
42 | public PredicateTranslator(String fullyQualifiedName) { | ||
43 | super(PVisibility.PUBLIC); | ||
44 | this.fullyQualifiedName = fullyQualifiedName; | ||
45 | PBody body = new PBody(this); | ||
46 | bodies.add(body); | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public String getFullyQualifiedName() { | ||
51 | return fullyQualifiedName; | ||
52 | } | ||
53 | |||
54 | public PredicateTranslator addParameter(String name, RelationView<?> type) { | ||
55 | PParameter parameter = new PParameter(name); | ||
56 | parameters.put(name, parameter); | ||
57 | |||
58 | PBody body = bodies.peekLast(); | ||
59 | List<ExportedParameter> symbolicParameters = new ArrayList<>(); | ||
60 | parameters.forEach((pName, pParameter) -> { | ||
61 | PVariable var = body.getOrCreateVariableByName(pName); | ||
62 | symbolicParameters.add(new ExportedParameter(body, var, pParameter)); | ||
63 | }); | ||
64 | body.setSymbolicParameters(symbolicParameters); | ||
65 | |||
66 | return this; | ||
67 | } | ||
68 | |||
69 | @Override | ||
70 | public List<PParameter> getParameters() { | ||
71 | return new ArrayList<PParameter>(parameters.values()); | ||
72 | } | ||
73 | public <D> PredicateTranslator addConstraint(RelationView<D> view, String... name) { | ||
74 | if(name.length != view.getArity()) { | ||
75 | throw new IllegalArgumentException("Arity ("+view.getArity()+") does not match parameter numbers ("+name.length+")"); | ||
76 | } | ||
77 | PBody body = bodies.peekLast(); | ||
78 | Object[] variables = new Object[name.length]; | ||
79 | for(int i = 0; i<name.length; i++) { | ||
80 | variables[i] = body.getOrCreateVariableByName(name[i]); | ||
81 | } | ||
82 | new TypeConstraint(body, Tuples.flatTupleOf(variables), view); | ||
83 | return this; | ||
84 | } | ||
85 | |||
86 | // // Type constraint | ||
87 | // public RelationQuery addConstraint(String type, String name) { | ||
88 | // PBody body = bodies.peekLast(); | ||
89 | // PVariable var = body.getOrCreateVariableByName(name); | ||
90 | // new TypeConstraint(body, Tuples.flatTupleOf(var), new StringExactInstancesKey(type)); | ||
91 | // return this; | ||
92 | // } | ||
93 | // | ||
94 | // // Relation constraint | ||
95 | // public RelationQuery addConstraint(String type, String sourceName, String targetName) { | ||
96 | // PBody body = bodies.peekLast(); | ||
97 | // PVariable var_source = body.getOrCreateVariableByName(sourceName); | ||
98 | // PVariable var_target = body.getOrCreateVariableByName(targetName); | ||
99 | // new TypeConstraint(body, Tuples.flatTupleOf(var_source, var_target), | ||
100 | // new StringStructuralFeatureInstancesKey(type)); | ||
101 | // return this; | ||
102 | // } | ||
103 | |||
104 | // Create new Body | ||
105 | public PredicateTranslator or() { | ||
106 | PBody body = new PBody(this); | ||
107 | List<ExportedParameter> symbolicParameters = new ArrayList<>(); | ||
108 | parameters.forEach((name, parameter) -> { | ||
109 | PVariable var = body.getOrCreateVariableByName(name); | ||
110 | symbolicParameters.add(new ExportedParameter(body, var, parameter)); | ||
111 | }); | ||
112 | body.setSymbolicParameters(symbolicParameters); | ||
113 | bodies.add(body); | ||
114 | return this; | ||
115 | } | ||
116 | |||
117 | // Equality constraint | ||
118 | public PredicateTranslator addEquality(String sourceName, String targetName) { | ||
119 | PBody body = bodies.peekLast(); | ||
120 | PVariable var_source = body.getOrCreateVariableByName(sourceName); | ||
121 | PVariable var_target = body.getOrCreateVariableByName(targetName); | ||
122 | new Equality(body, var_source, var_target); | ||
123 | return this; | ||
124 | } | ||
125 | |||
126 | // Inequality constraint | ||
127 | public PredicateTranslator addInequality(String sourceName, String targetName) { | ||
128 | PBody body = bodies.peekLast(); | ||
129 | PVariable var_source = body.getOrCreateVariableByName(sourceName); | ||
130 | PVariable var_target = body.getOrCreateVariableByName(targetName); | ||
131 | new Inequality(body, var_source, var_target); | ||
132 | return this; | ||
133 | } | ||
134 | |||
135 | // Positive pattern call | ||
136 | public PredicateTranslator addPatternCall(PQuery query, String... names) { | ||
137 | PBody body = bodies.peekLast(); | ||
138 | PVariable[] vars = new PVariable[names.length]; | ||
139 | for (int i = 0; i < names.length; i++) { | ||
140 | vars[i] = body.getOrCreateVariableByName(names[i]); | ||
141 | } | ||
142 | new PositivePatternCall(body, Tuples.flatTupleOf(vars), query); | ||
143 | return this; | ||
144 | } | ||
145 | |||
146 | // Negative pattern call | ||
147 | public PredicateTranslator addNegativePatternCall(PQuery query, String... names) { | ||
148 | PBody body = bodies.peekLast(); | ||
149 | PVariable[] vars = new PVariable[names.length]; | ||
150 | for (int i = 0; i < names.length; i++) { | ||
151 | vars[i] = body.getOrCreateVariableByName(names[i]); | ||
152 | } | ||
153 | new NegativePatternCall(body, Tuples.flatTupleOf(vars), query); | ||
154 | return this; | ||
155 | } | ||
156 | |||
157 | // Binary transitive closure pattern call | ||
158 | public PredicateTranslator addBinaryTransitiveClosure(PQuery query, String sourceName, String targetName) { | ||
159 | PBody body = bodies.peekLast(); | ||
160 | PVariable var_source = body.getOrCreateVariableByName(sourceName); | ||
161 | PVariable var_target = body.getOrCreateVariableByName(targetName); | ||
162 | new BinaryTransitiveClosure(body, Tuples.flatTupleOf(var_source, var_target), query); | ||
163 | return this; | ||
164 | } | ||
165 | |||
166 | // Binary reflexive transitive closure pattern call | ||
167 | public PredicateTranslator addBinaryReflexiveTransitiveClosure(PQuery query, String sourceName, String targetName) { | ||
168 | PBody body = bodies.peekLast(); | ||
169 | PVariable var_source = body.getOrCreateVariableByName(sourceName); | ||
170 | PVariable var_target = body.getOrCreateVariableByName(targetName); | ||
171 | new BinaryReflexiveTransitiveClosure(body, Tuples.flatTupleOf(var_source, var_target), query, | ||
172 | query.getParameters().get(0).getDeclaredUnaryType()); | ||
173 | return this; | ||
174 | } | ||
175 | |||
176 | @Override | ||
177 | public Set<PBody> doGetContainedBodies() { | ||
178 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
179 | return new LinkedHashSet<PBody>(bodies); | ||
180 | } | ||
181 | |||
182 | public void addSymbolicParameters(ExportedParameter symbolicParameter) { | ||
183 | checkMutability(); | ||
184 | if (symbolicParameters == null) { | ||
185 | symbolicParameters = new ArrayList<>(); | ||
186 | } | ||
187 | symbolicParameters.add(symbolicParameter); | ||
188 | } | ||
189 | |||
190 | public GenericQuerySpecification<GenericPatternMatcher> build() { | ||
191 | return new GenericQuerySpecification<GenericPatternMatcher>(this) { | ||
192 | |||
193 | @Override | ||
194 | public Class<? extends QueryScope> getPreferredScopeClass() { | ||
195 | return RelationalScope.class; | ||
196 | } | ||
197 | |||
198 | @Override | ||
199 | protected GenericPatternMatcher instantiate(ViatraQueryEngine engine) { | ||
200 | return defaultInstantiate(engine); | ||
201 | } | ||
202 | |||
203 | @Override | ||
204 | public GenericPatternMatcher instantiate() { | ||
205 | return new GenericPatternMatcher(this); | ||
206 | } | ||
207 | |||
208 | }; | ||
209 | } | ||
210 | } \ No newline at end of file | ||