diff options
author | 2021-09-19 18:06:35 +0200 | |
---|---|---|
committer | 2021-09-19 18:06:35 +0200 | |
commit | 32ad0b378e2b02c7a13020d1e4d6f3d8fbffb886 (patch) | |
tree | 44dd85f9ac67dec2cfefd0f367c303f5b57de55d /model-data | |
parent | Merge branch 'web-demo' of https://github.com/viatra/VIATRA-Generator.git int... (diff) | |
download | refinery-32ad0b378e2b02c7a13020d1e4d6f3d8fbffb886.tar.gz refinery-32ad0b378e2b02c7a13020d1e4d6f3d8fbffb886.tar.zst refinery-32ad0b378e2b02c7a13020d1e4d6f3d8fbffb886.zip |
PredicateTranslator first version
Diffstat (limited to 'model-data')
-rw-r--r-- | model-data/src/main/java/org/eclipse/viatra/solver/data/query/internal/PredicateTranslator.java | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/query/internal/PredicateTranslator.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/query/internal/PredicateTranslator.java index 39fc2482..54cb4bab 100644 --- a/model-data/src/main/java/org/eclipse/viatra/solver/data/query/internal/PredicateTranslator.java +++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/query/internal/PredicateTranslator.java | |||
@@ -1,4 +1,4 @@ | |||
1 | package org.eclipse.viatra.solver.data.query; | 1 | package org.eclipse.viatra.solver.data.query.internal; |
2 | 2 | ||
3 | import java.util.ArrayList; | 3 | import java.util.ArrayList; |
4 | import java.util.HashMap; | 4 | import java.util.HashMap; |
@@ -28,16 +28,17 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | |||
28 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery; | 28 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery; |
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | 29 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; |
30 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | 30 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; |
31 | import org.eclipse.viatra.solver.data.query.RelationalScope; | ||
31 | import org.eclipse.viatra.solver.data.query.view.RelationView; | 32 | import org.eclipse.viatra.solver.data.query.view.RelationView; |
32 | 33 | ||
33 | public class RelationalQuery extends BasePQuery { | 34 | public class PredicateTranslator extends BasePQuery { |
34 | 35 | ||
35 | private final Map<String, PParameter> parameters = new HashMap<String, PParameter>(); | 36 | private final Map<String, PParameter> parameters = new HashMap<String, PParameter>(); |
36 | private String fullyQualifiedName; | 37 | private String fullyQualifiedName; |
37 | private LinkedList<PBody> bodies = new LinkedList<PBody>(); | 38 | private LinkedList<PBody> bodies = new LinkedList<PBody>(); |
38 | private List<ExportedParameter> symbolicParameters; | 39 | private List<ExportedParameter> symbolicParameters; |
39 | 40 | ||
40 | public RelationalQuery(String fullyQualifiedName) { | 41 | public PredicateTranslator(String fullyQualifiedName) { |
41 | super(PVisibility.PUBLIC); | 42 | super(PVisibility.PUBLIC); |
42 | this.fullyQualifiedName = fullyQualifiedName; | 43 | this.fullyQualifiedName = fullyQualifiedName; |
43 | PBody body = new PBody(this); | 44 | PBody body = new PBody(this); |
@@ -49,7 +50,7 @@ public class RelationalQuery extends BasePQuery { | |||
49 | return fullyQualifiedName; | 50 | return fullyQualifiedName; |
50 | } | 51 | } |
51 | 52 | ||
52 | public RelationalQuery addParameter(String name, RelationView<?> type) { | 53 | public PredicateTranslator addParameter(String name, RelationView<?> type) { |
53 | PParameter parameter = new PParameter(name); | 54 | PParameter parameter = new PParameter(name); |
54 | parameters.put(name, parameter); | 55 | parameters.put(name, parameter); |
55 | 56 | ||
@@ -68,7 +69,7 @@ public class RelationalQuery extends BasePQuery { | |||
68 | public List<PParameter> getParameters() { | 69 | public List<PParameter> getParameters() { |
69 | return new ArrayList<PParameter>(parameters.values()); | 70 | return new ArrayList<PParameter>(parameters.values()); |
70 | } | 71 | } |
71 | public <D> RelationalQuery addConstraint(RelationView<D> view, String... name) { | 72 | public <D> PredicateTranslator addConstraint(RelationView<D> view, String... name) { |
72 | if(name.length != view.getArity()) { | 73 | if(name.length != view.getArity()) { |
73 | throw new IllegalArgumentException("Arity ("+view.getArity()+") does not match parameter numbers ("+name.length+")"); | 74 | throw new IllegalArgumentException("Arity ("+view.getArity()+") does not match parameter numbers ("+name.length+")"); |
74 | } | 75 | } |
@@ -100,7 +101,7 @@ public class RelationalQuery extends BasePQuery { | |||
100 | // } | 101 | // } |
101 | 102 | ||
102 | // Create new Body | 103 | // Create new Body |
103 | public RelationalQuery or() { | 104 | public PredicateTranslator or() { |
104 | PBody body = new PBody(this); | 105 | PBody body = new PBody(this); |
105 | List<ExportedParameter> symbolicParameters = new ArrayList<>(); | 106 | List<ExportedParameter> symbolicParameters = new ArrayList<>(); |
106 | parameters.forEach((name, parameter) -> { | 107 | parameters.forEach((name, parameter) -> { |
@@ -113,7 +114,7 @@ public class RelationalQuery extends BasePQuery { | |||
113 | } | 114 | } |
114 | 115 | ||
115 | // Equality constraint | 116 | // Equality constraint |
116 | public RelationalQuery addEquality(String sourceName, String targetName) { | 117 | public PredicateTranslator addEquality(String sourceName, String targetName) { |
117 | PBody body = bodies.peekLast(); | 118 | PBody body = bodies.peekLast(); |
118 | PVariable var_source = body.getOrCreateVariableByName(sourceName); | 119 | PVariable var_source = body.getOrCreateVariableByName(sourceName); |
119 | PVariable var_target = body.getOrCreateVariableByName(targetName); | 120 | PVariable var_target = body.getOrCreateVariableByName(targetName); |
@@ -122,7 +123,7 @@ public class RelationalQuery extends BasePQuery { | |||
122 | } | 123 | } |
123 | 124 | ||
124 | // Inequality constraint | 125 | // Inequality constraint |
125 | public RelationalQuery addInequality(String sourceName, String targetName) { | 126 | public PredicateTranslator addInequality(String sourceName, String targetName) { |
126 | PBody body = bodies.peekLast(); | 127 | PBody body = bodies.peekLast(); |
127 | PVariable var_source = body.getOrCreateVariableByName(sourceName); | 128 | PVariable var_source = body.getOrCreateVariableByName(sourceName); |
128 | PVariable var_target = body.getOrCreateVariableByName(targetName); | 129 | PVariable var_target = body.getOrCreateVariableByName(targetName); |
@@ -131,7 +132,7 @@ public class RelationalQuery extends BasePQuery { | |||
131 | } | 132 | } |
132 | 133 | ||
133 | // Positive pattern call | 134 | // Positive pattern call |
134 | public RelationalQuery addPatternCall(PQuery query, String... names) { | 135 | public PredicateTranslator addPatternCall(PQuery query, String... names) { |
135 | PBody body = bodies.peekLast(); | 136 | PBody body = bodies.peekLast(); |
136 | PVariable[] vars = new PVariable[names.length]; | 137 | PVariable[] vars = new PVariable[names.length]; |
137 | for (int i = 0; i < names.length; i++) { | 138 | for (int i = 0; i < names.length; i++) { |
@@ -142,7 +143,7 @@ public class RelationalQuery extends BasePQuery { | |||
142 | } | 143 | } |
143 | 144 | ||
144 | // Negative pattern call | 145 | // Negative pattern call |
145 | public RelationalQuery addNegativePatternCall(PQuery query, String... names) { | 146 | public PredicateTranslator addNegativePatternCall(PQuery query, String... names) { |
146 | PBody body = bodies.peekLast(); | 147 | PBody body = bodies.peekLast(); |
147 | PVariable[] vars = new PVariable[names.length]; | 148 | PVariable[] vars = new PVariable[names.length]; |
148 | for (int i = 0; i < names.length; i++) { | 149 | for (int i = 0; i < names.length; i++) { |
@@ -153,7 +154,7 @@ public class RelationalQuery extends BasePQuery { | |||
153 | } | 154 | } |
154 | 155 | ||
155 | // Binary transitive closure pattern call | 156 | // Binary transitive closure pattern call |
156 | public RelationalQuery addBinaryTransitiveClosure(PQuery query, String sourceName, String targetName) { | 157 | public PredicateTranslator addBinaryTransitiveClosure(PQuery query, String sourceName, String targetName) { |
157 | PBody body = bodies.peekLast(); | 158 | PBody body = bodies.peekLast(); |
158 | PVariable var_source = body.getOrCreateVariableByName(sourceName); | 159 | PVariable var_source = body.getOrCreateVariableByName(sourceName); |
159 | PVariable var_target = body.getOrCreateVariableByName(targetName); | 160 | PVariable var_target = body.getOrCreateVariableByName(targetName); |
@@ -162,7 +163,7 @@ public class RelationalQuery extends BasePQuery { | |||
162 | } | 163 | } |
163 | 164 | ||
164 | // Binary reflexive transitive closure pattern call | 165 | // Binary reflexive transitive closure pattern call |
165 | public RelationalQuery addBinaryReflexiveTransitiveClosure(PQuery query, String sourceName, String targetName) { | 166 | public PredicateTranslator addBinaryReflexiveTransitiveClosure(PQuery query, String sourceName, String targetName) { |
166 | PBody body = bodies.peekLast(); | 167 | PBody body = bodies.peekLast(); |
167 | PVariable var_source = body.getOrCreateVariableByName(sourceName); | 168 | PVariable var_source = body.getOrCreateVariableByName(sourceName); |
168 | PVariable var_target = body.getOrCreateVariableByName(targetName); | 169 | PVariable var_target = body.getOrCreateVariableByName(targetName); |