aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Oszkar Semerath <semerath@mit.bme.hu>2019-07-15 17:31:00 +0200
committerLibravatar Oszkar Semerath <semerath@mit.bme.hu>2019-07-15 17:31:00 +0200
commit539618ccaedfe05d5d62971c8fd0578f5ff3d040 (patch)
tree43d07de9773db3bc6ab71021c530b205680315c4
parentaggregated partial substitution + builder (diff)
downloadVIATRA-Generator-539618ccaedfe05d5d62971c8fd0578f5ff3d040.tar.gz
VIATRA-Generator-539618ccaedfe05d5d62971c8fd0578f5ff3d040.tar.zst
VIATRA-Generator-539618ccaedfe05d5d62971c8fd0578f5ff3d040.zip
parsing count, min, max, check and eval v1
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/AggregateExpression.java23
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/LogiclanguagePackage.java75
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/AggregateExpressionImpl.java63
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/LogiclanguagePackageImpl.java12
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.aird34
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.ecore1
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.genmodel1
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicProblemBuilder.xtend40
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/META-INF/MANIFEST.MF3
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Constraint2Logic.xtend69
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/ExpressionEvaluation2Logic.xtend132
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2Logic.xtend328
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2LogicTypeInferer.xtend392
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2LogicTypeResult.xtend47
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/XExpressionExtractor.xtend24
15 files changed, 961 insertions, 283 deletions
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/AggregateExpression.java b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/AggregateExpression.java
index 4b38becf..589145c3 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/AggregateExpression.java
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/AggregateExpression.java
@@ -16,6 +16,7 @@ import org.eclipse.emf.common.util.EList;
16 * <ul> 16 * <ul>
17 * <li>{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getRelation <em>Relation</em>}</li> 17 * <li>{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getRelation <em>Relation</em>}</li>
18 * <li>{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getParameterSubstitution <em>Parameter Substitution</em>}</li> 18 * <li>{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getParameterSubstitution <em>Parameter Substitution</em>}</li>
19 * <li>{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getResultVariable <em>Result Variable</em>}</li>
19 * </ul> 20 * </ul>
20 * 21 *
21 * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage#getAggregateExpression() 22 * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage#getAggregateExpression()
@@ -61,4 +62,26 @@ public interface AggregateExpression extends Term {
61 */ 62 */
62 EList<AggregatedParameterSubstitution> getParameterSubstitution(); 63 EList<AggregatedParameterSubstitution> getParameterSubstitution();
63 64
65 /**
66 * Returns the value of the '<em><b>Result Variable</b></em>' reference.
67 * <!-- begin-user-doc -->
68 * <!-- end-user-doc -->
69 * @return the value of the '<em>Result Variable</em>' reference.
70 * @see #setResultVariable(Variable)
71 * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage#getAggregateExpression_ResultVariable()
72 * @model
73 * @generated
74 */
75 Variable getResultVariable();
76
77 /**
78 * Sets the value of the '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getResultVariable <em>Result Variable</em>}' reference.
79 * <!-- begin-user-doc -->
80 * <!-- end-user-doc -->
81 * @param value the new value of the '<em>Result Variable</em>' reference.
82 * @see #getResultVariable()
83 * @generated
84 */
85 void setResultVariable(Variable value);
86
64} // AggregateExpression 87} // AggregateExpression
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/LogiclanguagePackage.java b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/LogiclanguagePackage.java
index f5347e31..193d9bdd 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/LogiclanguagePackage.java
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/LogiclanguagePackage.java
@@ -2760,13 +2760,22 @@ public interface LogiclanguagePackage extends EPackage {
2760 int AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION = TERM_FEATURE_COUNT + 1; 2760 int AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION = TERM_FEATURE_COUNT + 1;
2761 2761
2762 /** 2762 /**
2763 * The feature id for the '<em><b>Result Variable</b></em>' reference.
2764 * <!-- begin-user-doc -->
2765 * <!-- end-user-doc -->
2766 * @generated
2767 * @ordered
2768 */
2769 int AGGREGATE_EXPRESSION__RESULT_VARIABLE = TERM_FEATURE_COUNT + 2;
2770
2771 /**
2763 * The number of structural features of the '<em>Aggregate Expression</em>' class. 2772 * The number of structural features of the '<em>Aggregate Expression</em>' class.
2764 * <!-- begin-user-doc --> 2773 * <!-- begin-user-doc -->
2765 * <!-- end-user-doc --> 2774 * <!-- end-user-doc -->
2766 * @generated 2775 * @generated
2767 * @ordered 2776 * @ordered
2768 */ 2777 */
2769 int AGGREGATE_EXPRESSION_FEATURE_COUNT = TERM_FEATURE_COUNT + 2; 2778 int AGGREGATE_EXPRESSION_FEATURE_COUNT = TERM_FEATURE_COUNT + 3;
2770 2779
2771 /** 2780 /**
2772 * The number of operations of the '<em>Aggregate Expression</em>' class. 2781 * The number of operations of the '<em>Aggregate Expression</em>' class.
@@ -2806,6 +2815,15 @@ public interface LogiclanguagePackage extends EPackage {
2806 int PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION = AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION; 2815 int PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION = AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
2807 2816
2808 /** 2817 /**
2818 * The feature id for the '<em><b>Result Variable</b></em>' reference.
2819 * <!-- begin-user-doc -->
2820 * <!-- end-user-doc -->
2821 * @generated
2822 * @ordered
2823 */
2824 int PROJECTED_AGGREGATE_EXPRESSION__RESULT_VARIABLE = AGGREGATE_EXPRESSION__RESULT_VARIABLE;
2825
2826 /**
2809 * The feature id for the '<em><b>Projection Index</b></em>' attribute. 2827 * The feature id for the '<em><b>Projection Index</b></em>' attribute.
2810 * <!-- begin-user-doc --> 2828 * <!-- begin-user-doc -->
2811 * <!-- end-user-doc --> 2829 * <!-- end-user-doc -->
@@ -2861,6 +2879,15 @@ public interface LogiclanguagePackage extends EPackage {
2861 int SUM__PARAMETER_SUBSTITUTION = PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION; 2879 int SUM__PARAMETER_SUBSTITUTION = PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
2862 2880
2863 /** 2881 /**
2882 * The feature id for the '<em><b>Result Variable</b></em>' reference.
2883 * <!-- begin-user-doc -->
2884 * <!-- end-user-doc -->
2885 * @generated
2886 * @ordered
2887 */
2888 int SUM__RESULT_VARIABLE = PROJECTED_AGGREGATE_EXPRESSION__RESULT_VARIABLE;
2889
2890 /**
2864 * The feature id for the '<em><b>Projection Index</b></em>' attribute. 2891 * The feature id for the '<em><b>Projection Index</b></em>' attribute.
2865 * <!-- begin-user-doc --> 2892 * <!-- begin-user-doc -->
2866 * <!-- end-user-doc --> 2893 * <!-- end-user-doc -->
@@ -2916,6 +2943,15 @@ public interface LogiclanguagePackage extends EPackage {
2916 int COUNT__PARAMETER_SUBSTITUTION = AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION; 2943 int COUNT__PARAMETER_SUBSTITUTION = AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
2917 2944
2918 /** 2945 /**
2946 * The feature id for the '<em><b>Result Variable</b></em>' reference.
2947 * <!-- begin-user-doc -->
2948 * <!-- end-user-doc -->
2949 * @generated
2950 * @ordered
2951 */
2952 int COUNT__RESULT_VARIABLE = AGGREGATE_EXPRESSION__RESULT_VARIABLE;
2953
2954 /**
2919 * The number of structural features of the '<em>Count</em>' class. 2955 * The number of structural features of the '<em>Count</em>' class.
2920 * <!-- begin-user-doc --> 2956 * <!-- begin-user-doc -->
2921 * <!-- end-user-doc --> 2957 * <!-- end-user-doc -->
@@ -2962,6 +2998,15 @@ public interface LogiclanguagePackage extends EPackage {
2962 int MIN__PARAMETER_SUBSTITUTION = PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION; 2998 int MIN__PARAMETER_SUBSTITUTION = PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
2963 2999
2964 /** 3000 /**
3001 * The feature id for the '<em><b>Result Variable</b></em>' reference.
3002 * <!-- begin-user-doc -->
3003 * <!-- end-user-doc -->
3004 * @generated
3005 * @ordered
3006 */
3007 int MIN__RESULT_VARIABLE = PROJECTED_AGGREGATE_EXPRESSION__RESULT_VARIABLE;
3008
3009 /**
2965 * The feature id for the '<em><b>Projection Index</b></em>' attribute. 3010 * The feature id for the '<em><b>Projection Index</b></em>' attribute.
2966 * <!-- begin-user-doc --> 3011 * <!-- begin-user-doc -->
2967 * <!-- end-user-doc --> 3012 * <!-- end-user-doc -->
@@ -3017,6 +3062,15 @@ public interface LogiclanguagePackage extends EPackage {
3017 int MAX__PARAMETER_SUBSTITUTION = PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION; 3062 int MAX__PARAMETER_SUBSTITUTION = PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
3018 3063
3019 /** 3064 /**
3065 * The feature id for the '<em><b>Result Variable</b></em>' reference.
3066 * <!-- begin-user-doc -->
3067 * <!-- end-user-doc -->
3068 * @generated
3069 * @ordered
3070 */
3071 int MAX__RESULT_VARIABLE = PROJECTED_AGGREGATE_EXPRESSION__RESULT_VARIABLE;
3072
3073 /**
3020 * The feature id for the '<em><b>Projection Index</b></em>' attribute. 3074 * The feature id for the '<em><b>Projection Index</b></em>' attribute.
3021 * <!-- begin-user-doc --> 3075 * <!-- begin-user-doc -->
3022 * <!-- end-user-doc --> 3076 * <!-- end-user-doc -->
@@ -4409,6 +4463,17 @@ public interface LogiclanguagePackage extends EPackage {
4409 EReference getAggregateExpression_ParameterSubstitution(); 4463 EReference getAggregateExpression_ParameterSubstitution();
4410 4464
4411 /** 4465 /**
4466 * Returns the meta object for the reference '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getResultVariable <em>Result Variable</em>}'.
4467 * <!-- begin-user-doc -->
4468 * <!-- end-user-doc -->
4469 * @return the meta object for the reference '<em>Result Variable</em>'.
4470 * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getResultVariable()
4471 * @see #getAggregateExpression()
4472 * @generated
4473 */
4474 EReference getAggregateExpression_ResultVariable();
4475
4476 /**
4412 * Returns the meta object for class '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Sum <em>Sum</em>}'. 4477 * Returns the meta object for class '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Sum <em>Sum</em>}'.
4413 * <!-- begin-user-doc --> 4478 * <!-- begin-user-doc -->
4414 * <!-- end-user-doc --> 4479 * <!-- end-user-doc -->
@@ -5642,6 +5707,14 @@ public interface LogiclanguagePackage extends EPackage {
5642 EReference AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION = eINSTANCE.getAggregateExpression_ParameterSubstitution(); 5707 EReference AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION = eINSTANCE.getAggregateExpression_ParameterSubstitution();
5643 5708
5644 /** 5709 /**
5710 * The meta object literal for the '<em><b>Result Variable</b></em>' reference feature.
5711 * <!-- begin-user-doc -->
5712 * <!-- end-user-doc -->
5713 * @generated
5714 */
5715 EReference AGGREGATE_EXPRESSION__RESULT_VARIABLE = eINSTANCE.getAggregateExpression_ResultVariable();
5716
5717 /**
5645 * The meta object literal for the '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.SumImpl <em>Sum</em>}' class. 5718 * The meta object literal for the '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.SumImpl <em>Sum</em>}' class.
5646 * <!-- begin-user-doc --> 5719 * <!-- begin-user-doc -->
5647 * <!-- end-user-doc --> 5720 * <!-- end-user-doc -->
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/AggregateExpressionImpl.java b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/AggregateExpressionImpl.java
index 0459af42..31155b84 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/AggregateExpressionImpl.java
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/AggregateExpressionImpl.java
@@ -7,6 +7,7 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregatedParameterS
7import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage; 7import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage;
8import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation; 8import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation;
9 9
10import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable;
10import java.util.Collection; 11import java.util.Collection;
11import org.eclipse.emf.common.notify.Notification; 12import org.eclipse.emf.common.notify.Notification;
12 13
@@ -29,6 +30,7 @@ import org.eclipse.emf.ecore.util.InternalEList;
29 * <ul> 30 * <ul>
30 * <li>{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregateExpressionImpl#getRelation <em>Relation</em>}</li> 31 * <li>{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregateExpressionImpl#getRelation <em>Relation</em>}</li>
31 * <li>{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregateExpressionImpl#getParameterSubstitution <em>Parameter Substitution</em>}</li> 32 * <li>{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregateExpressionImpl#getParameterSubstitution <em>Parameter Substitution</em>}</li>
33 * <li>{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregateExpressionImpl#getResultVariable <em>Result Variable</em>}</li>
32 * </ul> 34 * </ul>
33 * 35 *
34 * @generated 36 * @generated
@@ -55,6 +57,16 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
55 protected EList<AggregatedParameterSubstitution> parameterSubstitution; 57 protected EList<AggregatedParameterSubstitution> parameterSubstitution;
56 58
57 /** 59 /**
60 * The cached value of the '{@link #getResultVariable() <em>Result Variable</em>}' reference.
61 * <!-- begin-user-doc -->
62 * <!-- end-user-doc -->
63 * @see #getResultVariable()
64 * @generated
65 * @ordered
66 */
67 protected Variable resultVariable;
68
69 /**
58 * <!-- begin-user-doc --> 70 * <!-- begin-user-doc -->
59 * <!-- end-user-doc --> 71 * <!-- end-user-doc -->
60 * @generated 72 * @generated
@@ -132,6 +144,46 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
132 * @generated 144 * @generated
133 */ 145 */
134 @Override 146 @Override
147 public Variable getResultVariable() {
148 if (resultVariable != null && resultVariable.eIsProxy()) {
149 InternalEObject oldResultVariable = (InternalEObject)resultVariable;
150 resultVariable = (Variable)eResolveProxy(oldResultVariable);
151 if (resultVariable != oldResultVariable) {
152 if (eNotificationRequired())
153 eNotify(new ENotificationImpl(this, Notification.RESOLVE, LogiclanguagePackage.AGGREGATE_EXPRESSION__RESULT_VARIABLE, oldResultVariable, resultVariable));
154 }
155 }
156 return resultVariable;
157 }
158
159 /**
160 * <!-- begin-user-doc -->
161 * <!-- end-user-doc -->
162 * @generated
163 */
164 public Variable basicGetResultVariable() {
165 return resultVariable;
166 }
167
168 /**
169 * <!-- begin-user-doc -->
170 * <!-- end-user-doc -->
171 * @generated
172 */
173 @Override
174 public void setResultVariable(Variable newResultVariable) {
175 Variable oldResultVariable = resultVariable;
176 resultVariable = newResultVariable;
177 if (eNotificationRequired())
178 eNotify(new ENotificationImpl(this, Notification.SET, LogiclanguagePackage.AGGREGATE_EXPRESSION__RESULT_VARIABLE, oldResultVariable, resultVariable));
179 }
180
181 /**
182 * <!-- begin-user-doc -->
183 * <!-- end-user-doc -->
184 * @generated
185 */
186 @Override
135 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { 187 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
136 switch (featureID) { 188 switch (featureID) {
137 case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION: 189 case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION:
@@ -153,6 +205,9 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
153 return basicGetRelation(); 205 return basicGetRelation();
154 case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION: 206 case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION:
155 return getParameterSubstitution(); 207 return getParameterSubstitution();
208 case LogiclanguagePackage.AGGREGATE_EXPRESSION__RESULT_VARIABLE:
209 if (resolve) return getResultVariable();
210 return basicGetResultVariable();
156 } 211 }
157 return super.eGet(featureID, resolve, coreType); 212 return super.eGet(featureID, resolve, coreType);
158 } 213 }
@@ -173,6 +228,9 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
173 getParameterSubstitution().clear(); 228 getParameterSubstitution().clear();
174 getParameterSubstitution().addAll((Collection<? extends AggregatedParameterSubstitution>)newValue); 229 getParameterSubstitution().addAll((Collection<? extends AggregatedParameterSubstitution>)newValue);
175 return; 230 return;
231 case LogiclanguagePackage.AGGREGATE_EXPRESSION__RESULT_VARIABLE:
232 setResultVariable((Variable)newValue);
233 return;
176 } 234 }
177 super.eSet(featureID, newValue); 235 super.eSet(featureID, newValue);
178 } 236 }
@@ -191,6 +249,9 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
191 case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION: 249 case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION:
192 getParameterSubstitution().clear(); 250 getParameterSubstitution().clear();
193 return; 251 return;
252 case LogiclanguagePackage.AGGREGATE_EXPRESSION__RESULT_VARIABLE:
253 setResultVariable((Variable)null);
254 return;
194 } 255 }
195 super.eUnset(featureID); 256 super.eUnset(featureID);
196 } 257 }
@@ -207,6 +268,8 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
207 return relation != null; 268 return relation != null;
208 case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION: 269 case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION:
209 return parameterSubstitution != null && !parameterSubstitution.isEmpty(); 270 return parameterSubstitution != null && !parameterSubstitution.isEmpty();
271 case LogiclanguagePackage.AGGREGATE_EXPRESSION__RESULT_VARIABLE:
272 return resultVariable != null;
210 } 273 }
211 return super.eIsSet(featureID); 274 return super.eIsSet(featureID);
212 } 275 }
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/LogiclanguagePackageImpl.java b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/LogiclanguagePackageImpl.java
index 64ebdde1..03a679e4 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/LogiclanguagePackageImpl.java
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/LogiclanguagePackageImpl.java
@@ -1892,6 +1892,16 @@ public class LogiclanguagePackageImpl extends EPackageImpl implements Logiclangu
1892 * @generated 1892 * @generated
1893 */ 1893 */
1894 @Override 1894 @Override
1895 public EReference getAggregateExpression_ResultVariable() {
1896 return (EReference)aggregateExpressionEClass.getEStructuralFeatures().get(2);
1897 }
1898
1899 /**
1900 * <!-- begin-user-doc -->
1901 * <!-- end-user-doc -->
1902 * @generated
1903 */
1904 @Override
1895 public EClass getSum() { 1905 public EClass getSum() {
1896 return sumEClass; 1906 return sumEClass;
1897 } 1907 }
@@ -2180,6 +2190,7 @@ public class LogiclanguagePackageImpl extends EPackageImpl implements Logiclangu
2180 aggregateExpressionEClass = createEClass(AGGREGATE_EXPRESSION); 2190 aggregateExpressionEClass = createEClass(AGGREGATE_EXPRESSION);
2181 createEReference(aggregateExpressionEClass, AGGREGATE_EXPRESSION__RELATION); 2191 createEReference(aggregateExpressionEClass, AGGREGATE_EXPRESSION__RELATION);
2182 createEReference(aggregateExpressionEClass, AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION); 2192 createEReference(aggregateExpressionEClass, AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION);
2193 createEReference(aggregateExpressionEClass, AGGREGATE_EXPRESSION__RESULT_VARIABLE);
2183 2194
2184 sumEClass = createEClass(SUM); 2195 sumEClass = createEClass(SUM);
2185 2196
@@ -2476,6 +2487,7 @@ public class LogiclanguagePackageImpl extends EPackageImpl implements Logiclangu
2476 initEClass(aggregateExpressionEClass, AggregateExpression.class, "AggregateExpression", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); 2487 initEClass(aggregateExpressionEClass, AggregateExpression.class, "AggregateExpression", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
2477 initEReference(getAggregateExpression_Relation(), this.getRelation(), null, "relation", null, 0, 1, AggregateExpression.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); 2488 initEReference(getAggregateExpression_Relation(), this.getRelation(), null, "relation", null, 0, 1, AggregateExpression.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
2478 initEReference(getAggregateExpression_ParameterSubstitution(), this.getAggregatedParameterSubstitution(), null, "parameterSubstitution", null, 0, -1, AggregateExpression.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); 2489 initEReference(getAggregateExpression_ParameterSubstitution(), this.getAggregatedParameterSubstitution(), null, "parameterSubstitution", null, 0, -1, AggregateExpression.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
2490 initEReference(getAggregateExpression_ResultVariable(), this.getVariable(), null, "resultVariable", null, 0, 1, AggregateExpression.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
2479 2491
2480 initEClass(sumEClass, Sum.class, "Sum", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); 2492 initEClass(sumEClass, Sum.class, "Sum", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
2481 2493
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.aird b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.aird
index 0a49e388..e96b4586 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.aird
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.aird
@@ -9146,6 +9146,22 @@
9146 <sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="__oOVoKJfEemXzuA5M0BZIw" id="(0.6082949308755761,1.0)"/> 9146 <sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="__oOVoKJfEemXzuA5M0BZIw" id="(0.6082949308755761,1.0)"/>
9147 <targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="__oOVoaJfEemXzuA5M0BZIw" id="(1.0,0.3076923076923077)"/> 9147 <targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="__oOVoaJfEemXzuA5M0BZIw" id="(1.0,0.3076923076923077)"/>
9148 </edges> 9148 </edges>
9149 <edges xmi:type="notation:Edge" xmi:id="_QZPVkKJ9EemXzuA5M0BZIw" type="4001" element="_QYZBAKJ9EemXzuA5M0BZIw" source="_rsImoG6WEemSyfDlsGAqLA" target="_l6XSGLdnEeau1vMV3Bsx4w">
9150 <children xmi:type="notation:Node" xmi:id="_QZP8oKJ9EemXzuA5M0BZIw" type="6001">
9151 <layoutConstraint xmi:type="notation:Bounds" xmi:id="_QZP8oaJ9EemXzuA5M0BZIw" x="-12" y="-10"/>
9152 </children>
9153 <children xmi:type="notation:Node" xmi:id="_QZP8oqJ9EemXzuA5M0BZIw" type="6002">
9154 <layoutConstraint xmi:type="notation:Bounds" xmi:id="_QZP8o6J9EemXzuA5M0BZIw" x="4" y="10"/>
9155 </children>
9156 <children xmi:type="notation:Node" xmi:id="_QZQjsKJ9EemXzuA5M0BZIw" type="6003">
9157 <layoutConstraint xmi:type="notation:Bounds" xmi:id="_QZQjsaJ9EemXzuA5M0BZIw" x="-4" y="10"/>
9158 </children>
9159 <styles xmi:type="notation:ConnectorStyle" xmi:id="_QZPVkaJ9EemXzuA5M0BZIw" routing="Rectilinear"/>
9160 <styles xmi:type="notation:FontStyle" xmi:id="_QZPVkqJ9EemXzuA5M0BZIw" fontColor="7490599" fontName="Segoe UI" fontHeight="8"/>
9161 <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_QZPVk6J9EemXzuA5M0BZIw" points="[-36, 0, 206, -76]$[-36, 89, 206, 13]$[-242, 89, 0, 13]"/>
9162 <sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_QZQjsqJ9EemXzuA5M0BZIw" id="(0.2706766917293233,1.0)"/>
9163 <targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_QZQjs6J9EemXzuA5M0BZIw" id="(1.0,0.6153846153846154)"/>
9164 </edges>
9149 </data> 9165 </data>
9150 </ownedAnnotationEntries> 9166 </ownedAnnotationEntries>
9151 <ownedDiagramElements xmi:type="diagram:DNodeList" uid="_l6ZIGbdnEeau1vMV3Bsx4w" name="Term" tooltipText="" outgoingEdges="_l6ZufbdnEeau1vMV3Bsx4w" incomingEdges="_l6Zt6bdnEeau1vMV3Bsx4w _l6Zt9bdnEeau1vMV3Bsx4w _l6Zt-bdnEeau1vMV3Bsx4w _l6Zt_bdnEeau1vMV3Bsx4w _l6ZuAbdnEeau1vMV3Bsx4w _l6ZuBbdnEeau1vMV3Bsx4w _l6ZuCbdnEeau1vMV3Bsx4w _l6ZuDbdnEeau1vMV3Bsx4w _l6ZuEbdnEeau1vMV3Bsx4w _l6ZuFbdnEeau1vMV3Bsx4w _l6ZuGbdnEeau1vMV3Bsx4w _l6ZuHbdnEeau1vMV3Bsx4w _l6ZuIbdnEeau1vMV3Bsx4w _l6ZuJbdnEeau1vMV3Bsx4w _l6ZuKbdnEeau1vMV3Bsx4w _l6ZuLbdnEeau1vMV3Bsx4w _l6ZuMbdnEeau1vMV3Bsx4w _l6ZuNbdnEeau1vMV3Bsx4w _l6ZuObdnEeau1vMV3Bsx4w _l6ZuPbdnEeau1vMV3Bsx4w _l6ZuQbdnEeau1vMV3Bsx4w _l6ZuRbdnEeau1vMV3Bsx4w _l6ZuhbdnEeau1vMV3Bsx4w _l6ZuibdnEeau1vMV3Bsx4w _l6ZunbdnEeau1vMV3Bsx4w _l6ZuqbdnEeau1vMV3Bsx4w _l6ZuwbdnEeau1vMV3Bsx4w _l6Zu3bdnEeau1vMV3Bsx4w _l6ZvHbdnEeau1vMV3Bsx4w _l6ZvIbdnEeau1vMV3Bsx4w _l6ZvJbdnEeau1vMV3Bsx4w _l6ZvKbdnEeau1vMV3Bsx4w _l6ZvZ7dnEeau1vMV3Bsx4w _kQZhsLd1Eeau1vMV3Bsx4w _BoaVwLqxEeau1vMV3Bsx4w _Vi5psIKgEeeAppuRs-roLg _YRIxkIKgEeeAppuRs-roLg _sGSk0IKlEeeAppuRs-roLg _za0wsm6WEemSyfDlsGAqLA" width="12" height="10"> 9167 <ownedDiagramElements xmi:type="diagram:DNodeList" uid="_l6ZIGbdnEeau1vMV3Bsx4w" name="Term" tooltipText="" outgoingEdges="_l6ZufbdnEeau1vMV3Bsx4w" incomingEdges="_l6Zt6bdnEeau1vMV3Bsx4w _l6Zt9bdnEeau1vMV3Bsx4w _l6Zt-bdnEeau1vMV3Bsx4w _l6Zt_bdnEeau1vMV3Bsx4w _l6ZuAbdnEeau1vMV3Bsx4w _l6ZuBbdnEeau1vMV3Bsx4w _l6ZuCbdnEeau1vMV3Bsx4w _l6ZuDbdnEeau1vMV3Bsx4w _l6ZuEbdnEeau1vMV3Bsx4w _l6ZuFbdnEeau1vMV3Bsx4w _l6ZuGbdnEeau1vMV3Bsx4w _l6ZuHbdnEeau1vMV3Bsx4w _l6ZuIbdnEeau1vMV3Bsx4w _l6ZuJbdnEeau1vMV3Bsx4w _l6ZuKbdnEeau1vMV3Bsx4w _l6ZuLbdnEeau1vMV3Bsx4w _l6ZuMbdnEeau1vMV3Bsx4w _l6ZuNbdnEeau1vMV3Bsx4w _l6ZuObdnEeau1vMV3Bsx4w _l6ZuPbdnEeau1vMV3Bsx4w _l6ZuQbdnEeau1vMV3Bsx4w _l6ZuRbdnEeau1vMV3Bsx4w _l6ZuhbdnEeau1vMV3Bsx4w _l6ZuibdnEeau1vMV3Bsx4w _l6ZunbdnEeau1vMV3Bsx4w _l6ZuqbdnEeau1vMV3Bsx4w _l6ZuwbdnEeau1vMV3Bsx4w _l6Zu3bdnEeau1vMV3Bsx4w _l6ZvHbdnEeau1vMV3Bsx4w _l6ZvIbdnEeau1vMV3Bsx4w _l6ZvJbdnEeau1vMV3Bsx4w _l6ZvKbdnEeau1vMV3Bsx4w _l6ZvZ7dnEeau1vMV3Bsx4w _kQZhsLd1Eeau1vMV3Bsx4w _BoaVwLqxEeau1vMV3Bsx4w _Vi5psIKgEeeAppuRs-roLg _YRIxkIKgEeeAppuRs-roLg _sGSk0IKlEeeAppuRs-roLg _za0wsm6WEemSyfDlsGAqLA" width="12" height="10">
@@ -9240,7 +9256,7 @@
9240 <actualMapping xmi:type="description_1:NodeMapping" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EClass']/@subNodeMappings[name='EC%20EAttribute']"/> 9256 <actualMapping xmi:type="description_1:NodeMapping" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EClass']/@subNodeMappings[name='EC%20EAttribute']"/>
9241 </ownedElements> 9257 </ownedElements>
9242 </ownedDiagramElements> 9258 </ownedDiagramElements>
9243 <ownedDiagramElements xmi:type="diagram:DNodeList" uid="_l6ZIL7dnEeau1vMV3Bsx4w" name="Variable" tooltipText="" outgoingEdges="_JfkfULd8Eeau1vMV3Bsx4w _e1jg0IKgEeeAppuRs-roLg" incomingEdges="_l6Zt8bdnEeau1vMV3Bsx4w __nLz2aJfEemXzuA5M0BZIw" width="12" height="10"> 9259 <ownedDiagramElements xmi:type="diagram:DNodeList" uid="_l6ZIL7dnEeau1vMV3Bsx4w" name="Variable" tooltipText="" outgoingEdges="_JfkfULd8Eeau1vMV3Bsx4w _e1jg0IKgEeeAppuRs-roLg" incomingEdges="_l6Zt8bdnEeau1vMV3Bsx4w __nLz2aJfEemXzuA5M0BZIw _QYZBAKJ9EemXzuA5M0BZIw" width="12" height="10">
9244 <target xmi:type="ecore:EClass" href="logiclanguage.ecore#//Variable"/> 9260 <target xmi:type="ecore:EClass" href="logiclanguage.ecore#//Variable"/>
9245 <semanticElements xmi:type="ecore:EClass" href="logiclanguage.ecore#//Variable"/> 9261 <semanticElements xmi:type="ecore:EClass" href="logiclanguage.ecore#//Variable"/>
9246 <arrangeConstraints>KEEP_LOCATION</arrangeConstraints> 9262 <arrangeConstraints>KEEP_LOCATION</arrangeConstraints>
@@ -10514,7 +10530,7 @@
10514 </ownedStyle> 10530 </ownedStyle>
10515 <actualMapping xmi:type="description_1:EdgeMapping" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@edgeMappings[name='EC%20ESupertypes']"/> 10531 <actualMapping xmi:type="description_1:EdgeMapping" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@edgeMappings[name='EC%20ESupertypes']"/>
10516 </ownedDiagramElements> 10532 </ownedDiagramElements>
10517 <ownedDiagramElements xmi:type="diagram:DNodeList" uid="_rrY_wG6WEemSyfDlsGAqLA" name="AggregateExpression" tooltipText="" outgoingEdges="_za0wsm6WEemSyfDlsGAqLA _hJ8ymW6cEemSyfDlsGAqLA _uI5YDKJfEemXzuA5M0BZIw" incomingEdges="_wovb6G6cEemSyfDlsGAqLA _OKfpkm6dEemSyfDlsGAqLA" width="12" height="10"> 10533 <ownedDiagramElements xmi:type="diagram:DNodeList" uid="_rrY_wG6WEemSyfDlsGAqLA" name="AggregateExpression" tooltipText="" outgoingEdges="_za0wsm6WEemSyfDlsGAqLA _hJ8ymW6cEemSyfDlsGAqLA _uI5YDKJfEemXzuA5M0BZIw _QYZBAKJ9EemXzuA5M0BZIw" incomingEdges="_wovb6G6cEemSyfDlsGAqLA _OKfpkm6dEemSyfDlsGAqLA" width="12" height="10">
10518 <target xmi:type="ecore:EClass" href="logiclanguage.ecore#//AggregateExpression"/> 10534 <target xmi:type="ecore:EClass" href="logiclanguage.ecore#//AggregateExpression"/>
10519 <semanticElements xmi:type="ecore:EClass" href="logiclanguage.ecore#//AggregateExpression"/> 10535 <semanticElements xmi:type="ecore:EClass" href="logiclanguage.ecore#//AggregateExpression"/>
10520 <arrangeConstraints>KEEP_LOCATION</arrangeConstraints> 10536 <arrangeConstraints>KEEP_LOCATION</arrangeConstraints>
@@ -10714,6 +10730,20 @@
10714 </ownedStyle> 10730 </ownedStyle>
10715 <actualMapping xmi:type="description_1:EdgeMapping" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@edgeMappings[name='EC_EReference']"/> 10731 <actualMapping xmi:type="description_1:EdgeMapping" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@edgeMappings[name='EC_EReference']"/>
10716 </ownedDiagramElements> 10732 </ownedDiagramElements>
10733 <ownedDiagramElements xmi:type="diagram:DEdge" uid="_QYZBAKJ9EemXzuA5M0BZIw" name="[0..1] resultVariable" sourceNode="_rrY_wG6WEemSyfDlsGAqLA" targetNode="_l6ZIL7dnEeau1vMV3Bsx4w">
10734 <target xmi:type="ecore:EReference" href="logiclanguage.ecore#//AggregateExpression/resultVariable"/>
10735 <semanticElements xmi:type="ecore:EReference" href="logiclanguage.ecore#//AggregateExpression/resultVariable"/>
10736 <ownedStyle xmi:type="diagram:EdgeStyle" uid="_QYZBAaJ9EemXzuA5M0BZIw" routingStyle="manhattan" strokeColor="0,0,0">
10737 <description xmi:type="style:EdgeStyleDescription" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@edgeMappings[name='EC_EReference']/@style"/>
10738 <centerLabelStyle xmi:type="diagram:CenterLabelStyle" uid="_QYZBA6J9EemXzuA5M0BZIw" showIcon="false">
10739 <customFeatures>labelSize</customFeatures>
10740 </centerLabelStyle>
10741 <endLabelStyle xmi:type="diagram:EndLabelStyle" uid="_QYZBAqJ9EemXzuA5M0BZIw" showIcon="false" labelColor="39,76,114">
10742 <customFeatures>labelSize</customFeatures>
10743 </endLabelStyle>
10744 </ownedStyle>
10745 <actualMapping xmi:type="description_1:EdgeMapping" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@edgeMappings[name='EC_EReference']"/>
10746 </ownedDiagramElements>
10717 <description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']"/> 10747 <description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']"/>
10718 <filterVariableHistory xmi:type="diagram:FilterVariableHistory" uid="_l6Zva7dnEeau1vMV3Bsx4w"/> 10748 <filterVariableHistory xmi:type="diagram:FilterVariableHistory" uid="_l6Zva7dnEeau1vMV3Bsx4w"/>
10719 <activatedLayers xmi:type="description_1:Layer" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer"/> 10749 <activatedLayers xmi:type="description_1:Layer" href="platform:/plugin/org.eclipse.emf.ecoretools.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer"/>
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.ecore b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.ecore
index fb94b598..a91d4407 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.ecore
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.ecore
@@ -217,6 +217,7 @@
217 <eStructuralFeatures xsi:type="ecore:EReference" name="relation" eType="#//Relation"/> 217 <eStructuralFeatures xsi:type="ecore:EReference" name="relation" eType="#//Relation"/>
218 <eStructuralFeatures xsi:type="ecore:EReference" name="parameterSubstitution" 218 <eStructuralFeatures xsi:type="ecore:EReference" name="parameterSubstitution"
219 upperBound="-1" eType="#//AggregatedParameterSubstitution" containment="true"/> 219 upperBound="-1" eType="#//AggregatedParameterSubstitution" containment="true"/>
220 <eStructuralFeatures xsi:type="ecore:EReference" name="resultVariable" eType="#//Variable"/>
220 </eClassifiers> 221 </eClassifiers>
221 <eClassifiers xsi:type="ecore:EClass" name="Sum" eSuperTypes="#//ProjectedAggregateExpression"/> 222 <eClassifiers xsi:type="ecore:EClass" name="Sum" eSuperTypes="#//ProjectedAggregateExpression"/>
222 <eClassifiers xsi:type="ecore:EClass" name="Count" eSuperTypes="#//AggregateExpression"/> 223 <eClassifiers xsi:type="ecore:EClass" name="Count" eSuperTypes="#//AggregateExpression"/>
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.genmodel b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.genmodel
index cb14ae5b..0f35db7c 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.genmodel
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/model/logiclanguage.genmodel
@@ -169,6 +169,7 @@
169 <genClasses image="false" ecoreClass="logiclanguage.ecore#//AggregateExpression"> 169 <genClasses image="false" ecoreClass="logiclanguage.ecore#//AggregateExpression">
170 <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference logiclanguage.ecore#//AggregateExpression/relation"/> 170 <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference logiclanguage.ecore#//AggregateExpression/relation"/>
171 <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference logiclanguage.ecore#//AggregateExpression/parameterSubstitution"/> 171 <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference logiclanguage.ecore#//AggregateExpression/parameterSubstitution"/>
172 <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference logiclanguage.ecore#//AggregateExpression/resultVariable"/>
172 </genClasses> 173 </genClasses>
173 <genClasses ecoreClass="logiclanguage.ecore#//Sum"/> 174 <genClasses ecoreClass="logiclanguage.ecore#//Sum"/>
174 <genClasses ecoreClass="logiclanguage.ecore#//Count"/> 175 <genClasses ecoreClass="logiclanguage.ecore#//Count"/>
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicProblemBuilder.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicProblemBuilder.xtend
index 09bfbb39..a231af3c 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicProblemBuilder.xtend
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicProblemBuilder.xtend
@@ -478,6 +478,7 @@ class LogicProblemBuilder{
478 def %(TermDescription left, TermDescription right) { Modulo(left,right) } 478 def %(TermDescription left, TermDescription right) { Modulo(left,right) }
479 def Modulo(TermDescription left, TermDescription right) { createMod => [leftOperand = left.toTerm rightOperand = right.toTerm]} 479 def Modulo(TermDescription left, TermDescription right) { createMod => [leftOperand = left.toTerm rightOperand = right.toTerm]}
480 480
481 def Pow(TermDescription left, TermDescription right) {createPow => [leftOperand = left.toTerm rightOperand = right.toTerm]}
481 def asTerm(boolean value) { createBoolLiteral => [x|x.value = value] } 482 def asTerm(boolean value) { createBoolLiteral => [x|x.value = value] }
482 def asTerm(int value) { createIntLiteral => [x|x.value = value] } 483 def asTerm(int value) { createIntLiteral => [x|x.value = value] }
483 def asTerm(double value) { BigDecimal.valueOf(value).asTerm } 484 def asTerm(double value) { BigDecimal.valueOf(value).asTerm }
@@ -530,27 +531,28 @@ class LogicProblemBuilder{
530 531
531 // AggregatedExpression 532 // AggregatedExpression
532 533
533 private def <T extends AggregateExpression> configureAggregateExpression(T expression, Relation referred, List<Variable> terms) { 534 private def <T extends AggregateExpression> configureAggregateExpression(T expression, Relation referred, List<Variable> terms, Variable target) {
534 if(terms.size != referred.parameters.size) { 535 if(terms.size != referred.parameters.size) {
535 throw new LogicProblemBuilderException( 536 throw new LogicProblemBuilderException(
536 '''The function called has «referred.parameters.size» parameters but it is called with «terms.size»!''') 537 '''The function called has «referred.parameters.size» parameters but it is called with «terms.size»!''')
537 } else { 538 } else {
538 expression.relation = referred 539 expression.relation = referred
540 expression.resultVariable = target
539 for(var i=0; i<referred.parameters.size;i++) { 541 for(var i=0; i<referred.parameters.size;i++) {
540 val target = terms.get(i) 542 val targetRelation = terms.get(i)
541 val substitution = createAggregatedParameterSubstitution => [it.variable = target] 543 val substitution = createAggregatedParameterSubstitution => [it.variable = targetRelation]
542 expression.parameterSubstitution += substitution 544 expression.parameterSubstitution += substitution
543 } 545 }
544 return expression 546 return expression
545 } 547 }
546 } 548 }
547 private def <T extends ProjectedAggregateExpression> configureProjectedAggregateExpression(T expression, Relation referred, List<Variable> terms, int projection) { 549 private def <T extends ProjectedAggregateExpression> configureProjectedAggregateExpression(T expression, Relation referred, List<Variable> terms, Variable target, int projection) {
548 if(projection < 0 || projection >= referred.parameters.size) { 550 if(projection < 0 || projection >= referred.parameters.size) {
549 throw new LogicProblemBuilderException( 551 throw new LogicProblemBuilderException(
550 '''The function called has «referred.parameters.size» parameters but it is called with «terms.size»!''') 552 '''The function called has «referred.parameters.size» parameters but it is called with «terms.size»!''')
551 } else { 553 } else {
552 val res = expression.configureAggregateExpression(referred, terms) 554 val res = expression.configureAggregateExpression(referred, terms,target)
553 if(res.parameterSubstitution.get(projection) !== null) { 555 if(res.parameterSubstitution.get(projection).variable !== null) {
554 throw new LogicProblemBuilderException( 556 throw new LogicProblemBuilderException(
555 '''Projection over set variable!''') 557 '''Projection over set variable!''')
556 } 558 }
@@ -564,10 +566,18 @@ class LogicProblemBuilder{
564 } 566 }
565 567
566 } 568 }
567 def Count(Relation referred, List<Variable> terms) { createCount.configureAggregateExpression(referred,terms) } 569 def Count(Relation referred, List<Variable> terms, Variable result) {
568 def Sum(Relation referred, List<Variable> terms, int projection) { createSum.configureProjectedAggregateExpression(referred,terms,projection) } 570 createCount.configureAggregateExpression(referred,terms,result)
569 def Min(Relation referred, List<Variable> terms, int projection) { createMin.configureProjectedAggregateExpression(referred,terms,projection) } 571 }
570 def Max(Relation referred, List<Variable> terms, int projection) { createMax.configureProjectedAggregateExpression(referred,terms,projection) } 572 def Sum(Relation referred, List<Variable> terms, int projection, Variable result) {
573 createSum.configureProjectedAggregateExpression(referred,terms,result,projection)
574 }
575 def Min(Relation referred, List<Variable> terms, int projection, Variable result) {
576 createMin.configureProjectedAggregateExpression(referred,terms,result,projection)
577 }
578 def Max(Relation referred, List<Variable> terms, int projection, Variable result) {
579 createMax.configureProjectedAggregateExpression(referred,terms,result,projection)
580 }
571 581
572 // Function calls 582 // Function calls
573 def call(Function function, TermDescription... substitutions) { 583 def call(Function function, TermDescription... substitutions) {
@@ -592,17 +602,19 @@ class LogicProblemBuilder{
592 def call(Relation relation, TermDescription... substitution) { relation.call(substitution as Iterable<? extends TermDescription>)} 602 def call(Relation relation, TermDescription... substitution) { relation.call(substitution as Iterable<? extends TermDescription>)}
593 def call(Relation relation, Iterable<? extends TermDescription> substitution) { 603 def call(Relation relation, Iterable<? extends TermDescription> substitution) {
594 val relationReference = createSymbolicValue 604 val relationReference = createSymbolicValue
605 if(relation === null) {
606 throw new LogicProblemBuilderException('''Call is referring to null!''')
607 }
595 relationReference.symbolicReference = relation 608 relationReference.symbolicReference = relation
596 //println('''«relation.name»(«substitution.size»->«relation.parameters»)''')
597 for(value : substitution) 609 for(value : substitution)
598 relationReference.parameterSubstitutions += value.toTerm 610 relationReference.parameterSubstitutions += value.toTerm
599 relationReference.checkRelationCall(relation) 611 relationReference.checkRelationCall(relation)
600 return relationReference 612 return relationReference
601 } 613 }
602 def private checkRelationCall(SymbolicValue value, Relation referredRelation) { 614 def private checkRelationCall(SymbolicValue value, Relation referredRelation) {
603// if(value === null || referredRelation === null) { 615 if(value === null || referredRelation === null) {
604// println("gebasz") 616 throw new LogicProblemBuilderException('''Call is referring to null!''')
605// } 617 }
606 if(value.parameterSubstitutions.size != referredRelation.parameters.size) { 618 if(value.parameterSubstitutions.size != referredRelation.parameters.size) {
607 throw new LogicProblemBuilderException( 619 throw new LogicProblemBuilderException(
608 '''The relation "«referredRelation.name»" called has «referredRelation.parameters.size» parameters but it is called with «value.parameterSubstitutions.size»!''') 620 '''The relation "«referredRelation.name»" called has «referredRelation.parameters.size» parameters but it is called with «value.parameterSubstitutions.size»!''')
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/META-INF/MANIFEST.MF b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/META-INF/MANIFEST.MF
index 8fa4517d..6aa9b63e 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/META-INF/MANIFEST.MF
+++ b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/META-INF/MANIFEST.MF
@@ -18,7 +18,8 @@ Require-Bundle: com.google.guava,
18 hu.bme.mit.inf.dslreasoner.logic.model;bundle-version="1.0.0";visibility:=reexport, 18 hu.bme.mit.inf.dslreasoner.logic.model;bundle-version="1.0.0";visibility:=reexport,
19 org.eclipse.viatra.query.runtime.base.itc;bundle-version="1.5.0", 19 org.eclipse.viatra.query.runtime.base.itc;bundle-version="1.5.0",
20 org.eclipse.viatra.query.patternlanguage.emf;bundle-version="2.0.0", 20 org.eclipse.viatra.query.patternlanguage.emf;bundle-version="2.0.0",
21 org.eclipse.xtext 21 org.eclipse.xtext,
22 org.eclipse.xtext.xbase;bundle-version="2.18.0"
22Bundle-ActivationPolicy: lazy 23Bundle-ActivationPolicy: lazy
23Export-Package: hu.bme.mit.inf.dslreasoner.viatra2logic, 24Export-Package: hu.bme.mit.inf.dslreasoner.viatra2logic,
24 hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations, 25 hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations,
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Constraint2Logic.xtend b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Constraint2Logic.xtend
index 3e8b3366..ffbca0af 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Constraint2Logic.xtend
+++ b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Constraint2Logic.xtend
@@ -30,10 +30,20 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeCo
30 30
31import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* 31import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint 32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint
34import org.eclipse.viatra.query.runtime.matchers.aggregators.DoubleSumOperator
35import org.eclipse.viatra.query.runtime.matchers.aggregators.IntegerSumOperator
36import org.eclipse.viatra.query.runtime.matchers.aggregators.LongSumOperator
37import org.eclipse.viatra.query.runtime.matchers.aggregators.ExtremumOperator
38import org.eclipse.viatra.query.runtime.matchers.aggregators.ExtremumOperator.Extreme
39import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter
40import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation
33 41
34class Constraint2Logic { 42class Constraint2Logic {
35 val extension LogicProblemBuilder builder = new LogicProblemBuilder 43 val extension LogicProblemBuilder builder = new LogicProblemBuilder
36 val Ecore2Logic ecore2Logic 44 val Ecore2Logic ecore2Logic
45 val ExpressionEvaluation2Logic expressionEvaliation2Logic = new ExpressionEvaluation2Logic
46 val expressionExtractor = new XExpressionExtractor
37 47
38 new(Ecore2Logic ecore2Logic) { 48 new(Ecore2Logic ecore2Logic) {
39 this.ecore2Logic = ecore2Logic 49 this.ecore2Logic = ecore2Logic
@@ -269,6 +279,65 @@ class Constraint2Logic {
269 } else throw new IllegalArgumentException('''unknown tuple: «tuple»''') 279 } else throw new IllegalArgumentException('''unknown tuple: «tuple»''')
270 } 280 }
271 281
282 def dispatch Term transformConstraint(AggregatorConstraint constraint,
283 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace,
284 Viatra2LogicTrace viatra2LogicTrace,
285 Map<PVariable, Variable> variable2Variable,
286 Viatra2LogicConfiguration config)
287 {
288 val logicReferred = constraint.referredQuery.lookup(viatra2LogicTrace.query2Relation)
289 val parameterSubstitution = new LinkedList
290 for(index : 0..<constraint.actualParametersTuple.size) {
291 val term = (constraint.actualParametersTuple.get(index) as PVariable).lookup(variable2Variable)
292 parameterSubstitution += term
293 }
294 val aggregatorIndex = constraint.aggregatedColumn
295 val logicResultVariable = constraint.resultVariable.lookup(variable2Variable)
296 val type = constraint.aggregator.operator
297 if(type === null) {
298 return Count(logicReferred,parameterSubstitution,logicResultVariable)
299 } else if(type instanceof IntegerSumOperator || type instanceof DoubleSumOperator || type instanceof LongSumOperator){
300 return Sum(logicReferred,parameterSubstitution,aggregatorIndex,logicResultVariable)
301 } else if(type instanceof ExtremumOperator) {
302 if(type.name == Extreme.MIN.name.toLowerCase) {
303 return Min(logicReferred,parameterSubstitution,aggregatorIndex,logicResultVariable)
304 } else if(type.name == Extreme.MAX.name.toLowerCase){
305 return Max(logicReferred,parameterSubstitution,aggregatorIndex,logicResultVariable)
306 } else {
307 throw new UnsupportedOperationException('''Unkown Extremum aggregator type: «type.name»''')
308 }
309 } else {
310 throw new UnsupportedOperationException('''Unkown aggregator type: «type.name»''')
311 }
312 }
313
314 def dispatch Term transformConstraint(PatternMatchCounter constraint,
315 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace,
316 Viatra2LogicTrace viatra2LogicTrace,
317 Map<PVariable, Variable> variable2Variable,
318 Viatra2LogicConfiguration config)
319 {
320 val logicReferred = constraint.referredQuery.lookup(viatra2LogicTrace.query2Relation)
321 val parameterSubstitution = new LinkedList
322 for(index : 0..<constraint.actualParametersTuple.size) {
323 val term = (constraint.actualParametersTuple.get(index) as PVariable).lookup(variable2Variable)
324 parameterSubstitution += term
325 }
326 val logicResultVariable = constraint.resultVariable.lookup(variable2Variable)
327 return Count(logicReferred,parameterSubstitution,logicResultVariable)
328 }
329
330 def dispatch Term transformConstraint(ExpressionEvaluation constraint,
331 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace,
332 Viatra2LogicTrace viatra2LogicTrace,
333 Map<PVariable, Variable> variable2Variable,
334 Viatra2LogicConfiguration config)
335 {
336 val outputVariable = constraint.outputVariable
337 val expression = expressionExtractor.extractExpression(constraint.evaluator)
338 return expressionEvaliation2Logic.transformEval(outputVariable,expression,variable2Variable)
339 }
340
272 def dispatch Term transformConstraint(PConstraint constraint, 341 def dispatch Term transformConstraint(PConstraint constraint,
273 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace, 342 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace,
274 Viatra2LogicTrace viatra2LogicTrace, 343 Viatra2LogicTrace viatra2LogicTrace,
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/ExpressionEvaluation2Logic.xtend b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/ExpressionEvaluation2Logic.xtend
new file mode 100644
index 00000000..f474ded4
--- /dev/null
+++ b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/ExpressionEvaluation2Logic.xtend
@@ -0,0 +1,132 @@
1package hu.bme.mit.inf.dslreasoner.viatra2logic
2
3import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder
4import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Term
5import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable
6import java.util.Map
7import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable
8import org.eclipse.xtext.xbase.XBinaryOperation
9import org.eclipse.xtext.xbase.XExpression
10import org.eclipse.xtext.xbase.XFeatureCall
11import org.eclipse.xtext.xbase.XMemberFeatureCall
12import org.eclipse.xtext.xbase.XNumberLiteral
13import org.eclipse.xtext.xbase.XUnaryOperation
14
15import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
16
17class ExpressionEvaluation2Logic {
18 val extension LogicProblemBuilder builder = new LogicProblemBuilder
19
20 def Term transformCheck(XExpression expression, Map<PVariable, Variable> variable2Variable) {
21 return expression.transform(variable2Variable)
22 }
23 def Term transformEval(PVariable target, XExpression expression, Map<PVariable, Variable> variable2Variable) {
24 return target.lookup(variable2Variable) == expression.transform(variable2Variable)
25 }
26
27 static val N_Base = "org.eclipse.xtext.xbase.lib."
28
29 static val N_PLUS1 = "operator_plus"
30 static val N_MINUS1 = "operator_minus"
31
32 static val N_MINUS2 = "operator_minus"
33 static val N_PLUS2 = "operator_plus"
34 static val N_POWER = "operator_power"
35 static val N_MULTIPLY = "operator_multiply"
36 static val N_DIVIDE = "operator_divide"
37 static val N_MODULO = "operator_modulo"
38 static val N_LESSTHAN = "operator_lessThan"
39 static val N_LESSEQUALSTHAN = "operator_lessEqualsThan"
40 static val N_GREATERTHAN = "operator_greaterThan"
41 static val N_GREATEREQUALTHAN = "operator_greaterEqualsThan"
42 static val N_EQUALS = "operator_equals"
43 static val N_NOTEQUALS = "operator_notEquals"
44 static val N_EQUALS3 = "operator_tripleEquals"
45 static val N_NOTEQUALS3 = "operator_tripleNotEquals"
46
47
48
49 protected def isN(String name, String s) {
50 val res = name.startsWith(N_Base) && name.endsWith(s)
51 //println('''[«res»] «name» ?= «N_Base»*«s»''')
52 return res
53 }
54
55 static val N_POWER2 = "java.lang.Math.pow"
56
57 def protected dispatch Term transform(XBinaryOperation e, Map<PVariable, Variable> variable2Variable) {
58 val left = e.leftOperand.transform(variable2Variable)
59 val right = e.rightOperand.transform(variable2Variable)
60 val feature = e.feature.qualifiedName
61 if(feature.isN(N_MINUS2)) { return Minus(left,right) }
62 else if(feature.isN(N_PLUS2)) { return Plus(left,right) }
63 else if(feature.isN(N_POWER)) { return Pow(left,right) }
64 else if(feature.isN(N_MULTIPLY)) { return Multiply(left,right) }
65 else if(feature.isN(N_DIVIDE)) { return Divide(left,right) }
66 else if(feature.isN(N_MODULO)) { return Modulo(left,right) }
67 else if(feature.isN(N_LESSTHAN)) { return LessThan(left,right) }
68 else if(feature.isN(N_LESSEQUALSTHAN)) { return LessOrEqual(left,right) }
69 else if(feature.isN(N_GREATERTHAN)) { return MoreThan(left,right) }
70 else if(feature.isN(N_GREATEREQUALTHAN)) { return MoreOrEqual(left,right) }
71 else if(feature.isN(N_EQUALS)) { return Equals(left,right) }
72 else if(feature.isN(N_NOTEQUALS)) { return Distinct(left,right) }
73 else if(feature.isN(N_EQUALS3)) { return Equals(left,right) }
74 else if(feature.isN(N_NOTEQUALS3)) { return Distinct(left,right) }
75 else {
76 println("-> " + e.feature+","+e.class)
77 println("-> " + e.leftOperand)
78 println("-> " + e.rightOperand)
79 println("-> " + e.feature.qualifiedName)
80 throw new UnsupportedOperationException('''Unsupported binary operator feature: "«e.feature.class.simpleName»" - «e»''')
81 }
82 }
83
84 def protected dispatch Term transform(XUnaryOperation e, Map<PVariable, Variable> variable2Variable) {
85 val operand = e.operand.transform(variable2Variable)
86 val feature = e.feature.qualifiedName
87 if(feature.isN(N_MINUS1)) { return Minus(0.asTerm,operand)}
88 else if(feature.isN(N_PLUS1)) { return operand}
89 else{
90 println("-> " + e.feature+","+e.class)
91 println("-> " + e.operand)
92 println("-> " + e.feature.qualifiedName)
93 throw new UnsupportedOperationException('''Unsupported unary operator feature: "«e.feature.class.simpleName»" - «e»''')
94 }
95 }
96
97 def protected dispatch Term transform(XMemberFeatureCall e, Map<PVariable, Variable> variable2Variable) {
98 val transformedArguments = e.actualArguments.map[transform(variable2Variable)]
99 val feature = e.feature.qualifiedName
100 if(feature == N_POWER2) {
101 return Pow(transformedArguments.get(0),transformedArguments.get(1))
102 }else {
103 println(e.feature+","+e.class)
104 println(e.actualArguments.join(", "))
105 println(e.feature.qualifiedName)
106 throw new UnsupportedOperationException('''Unsupported feature call: "«e.feature.qualifiedName»" - «e»''')
107 }
108 }
109
110 def protected dispatch Term transform(XFeatureCall e, Map<PVariable,Variable> variable2Variable) {
111 val featureName = e.feature.qualifiedName
112 val entryWithName = variable2Variable.entrySet.filter[it.key.name == featureName].head
113 if(entryWithName !== null) {
114 return entryWithName.value.toTerm
115 } else {
116 throw new IllegalArgumentException('''Feature call reference to unavailable variable "«featureName»"''')
117 }
118 }
119
120 def protected dispatch Term transform(XNumberLiteral l, Map<PVariable, Variable> variable2Variable) {
121 val s = l.value
122 try{ return Integer.parseInt(s).asTerm } catch(NumberFormatException e){}
123 try{ return Short.parseShort(s).asTerm } catch(NumberFormatException e){}
124 try{ return Double.parseDouble(s).asTerm } catch(NumberFormatException e){}
125 try{ return Float.parseFloat(s).asTerm } catch(NumberFormatException e){}
126 throw new UnsupportedOperationException('''Unsupported numeric type: "«s»"''')
127 }
128
129 def protected dispatch Term transform(XExpression e, Map<PVariable, Variable> variable2Variable) {
130 throw new UnsupportedOperationException('''Unsupported expression: "«e.class.simpleName»" - «e»''')
131 }
132} \ No newline at end of file
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2Logic.xtend b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2Logic.xtend
index 3b828170..0f97d3fe 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2Logic.xtend
+++ b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2Logic.xtend
@@ -4,48 +4,36 @@ import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic
4import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace 4import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace
5import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder 5import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder
6import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput 6import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput
7import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ComplexTypeReference
8import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.PrimitiveTypeReference
9import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDefinition 7import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDefinition
10import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type
11import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeReference
12import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable 8import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable
13import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem 9import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
14import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.TransfomedViatraQuery 10import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.TransfomedViatraQuery
15import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.Viatra2LogicAnnotationsFactory 11import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.Viatra2LogicAnnotationsFactory
16import java.util.ArrayList 12import java.util.ArrayList
17import java.util.HashMap 13import java.util.HashMap
18import java.util.HashSet
19import java.util.LinkedList 14import java.util.LinkedList
20import java.util.List 15import java.util.List
21import java.util.Map 16import java.util.Map
22import java.util.Set 17import java.util.Set
23import org.eclipse.emf.ecore.EAttribute 18import org.eclipse.emf.ecore.EAttribute
24import org.eclipse.emf.ecore.EClassifier
25import org.eclipse.emf.ecore.EEnum
26import org.eclipse.emf.ecore.EReference 19import org.eclipse.emf.ecore.EReference
27import org.eclipse.emf.ecore.EStructuralFeature 20import org.eclipse.emf.ecore.EStructuralFeature
28import org.eclipse.emf.ecore.EcorePackage 21import org.eclipse.emf.ecore.util.EcoreUtil
29import org.eclipse.viatra.query.runtime.api.IQuerySpecification 22import org.eclipse.viatra.query.runtime.api.IQuerySpecification
30import org.eclipse.viatra.query.runtime.emf.EMFQueryMetaContext 23import org.eclipse.viatra.query.runtime.emf.EMFQueryMetaContext
31import org.eclipse.viatra.query.runtime.emf.types.BaseEMFTypeKey
32import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey
33import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey
34import org.eclipse.viatra.query.runtime.matchers.context.IInputKey
35import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey
36import org.eclipse.viatra.query.runtime.matchers.planning.helpers.TypeHelper
37import org.eclipse.viatra.query.runtime.matchers.psystem.PBody 24import org.eclipse.viatra.query.runtime.matchers.psystem.PBody
25import org.eclipse.viatra.query.runtime.matchers.psystem.PConstraint
38import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable 26import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable
27import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint
39import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall 28import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall
29import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter
30import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PDisjunction
40import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter 31import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery 32import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery
42import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PBodyNormalizer 33import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PBodyNormalizer
43import org.eclipse.xtend.lib.annotations.Data 34import org.eclipse.xtend.lib.annotations.Data
44 35
45import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* 36import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
46import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PDisjunction
47import org.eclipse.emf.ecore.util.EcoreUtil
48import org.eclipse.viatra.query.runtime.emf.types.EClassUnscopedTransitiveInstancesKey
49 37
50@Data class ViatraQuerySetDescriptor { 38@Data class ViatraQuerySetDescriptor {
51 val List<? extends IQuerySpecification<?>> patterns 39 val List<? extends IQuerySpecification<?>> patterns
@@ -57,24 +45,24 @@ class Viatra2LogicTrace {
57 public val Map<PQuery, RelationDefinition> query2Relation = new HashMap 45 public val Map<PQuery, RelationDefinition> query2Relation = new HashMap
58 public val Map<PQuery, TransfomedViatraQuery> query2Annotation = new HashMap 46 public val Map<PQuery, TransfomedViatraQuery> query2Annotation = new HashMap
59 public val Map<Pair<PQuery,PParameter>, Variable> parameter2Variable = new HashMap 47 public val Map<Pair<PQuery,PParameter>, Variable> parameter2Variable = new HashMap
60 //public val Map<PVariable, Variable> variable2Variable = new HashMap
61} 48}
62class Viatra2LogicConfiguration { 49class Viatra2LogicConfiguration {
63 public var normalize = true 50 public var normalize = true
64 public var transitiveClosureDepth = 3
65} 51}
66 52
67class Viatra2Logic { 53class Viatra2Logic {
68 val extension LogicProblemBuilder builder = new LogicProblemBuilder 54 val extension LogicProblemBuilder builder = new LogicProblemBuilder
69 val extension Viatra2LogicAnnotationsFactory factory = Viatra2LogicAnnotationsFactory.eINSTANCE 55 val extension Viatra2LogicAnnotationsFactory factory = Viatra2LogicAnnotationsFactory.eINSTANCE
70 val normalizer = new PBodyNormalizer(EMFQueryMetaContext.DEFAULT) 56 val normalizer = new PBodyNormalizer(EMFQueryMetaContext.DEFAULT)
57 val Viatra2LogicTypeInferer typeInferer
71 58
72 val Ecore2Logic ecore2Logic 59 val Ecore2Logic ecore2Logic
73 Constraint2Logic constraint2Logic 60 Constraint2Logic constraint2Logic
74 61
75 new(Ecore2Logic ecore2Logic) { 62 new(Ecore2Logic ecore2Logic) {
76 this.ecore2Logic = ecore2Logic 63 this.ecore2Logic = ecore2Logic
77 constraint2Logic = new Constraint2Logic(ecore2Logic) 64 this.typeInferer = new Viatra2LogicTypeInferer(ecore2Logic)
65 this.constraint2Logic = new Constraint2Logic(ecore2Logic)
78 } 66 }
79 67
80 def TracedOutput<LogicProblem,Viatra2LogicTrace> transformQueries( 68 def TracedOutput<LogicProblem,Viatra2LogicTrace> transformQueries(
@@ -82,65 +70,55 @@ class Viatra2Logic {
82 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace, 70 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace,
83 Viatra2LogicConfiguration config) 71 Viatra2LogicConfiguration config)
84 { 72 {
73 // Create trace
85 val viatra2LogicTrace = new Viatra2LogicTrace 74 val viatra2LogicTrace = new Viatra2LogicTrace
86 val typeAlanysis = new HashMap 75
76 // Translation works on PQueries. QuerySpecification -> PQuery.
87 val pQueries = queries.patterns.map[it.internalQueryRepresentation] 77 val pQueries = queries.patterns.map[it.internalQueryRepresentation]
88 78
89 for(query: pQueries) { 79 // If requested, the queries are normalized
90 val disjunction = normalizer.rewrite(query) 80 for(query: pQueries) {
81 val disjunction = normalizer.rewrite(query)
91 viatra2LogicTrace.query2Disjunction.put(query,disjunction) 82 viatra2LogicTrace.query2Disjunction.put(query,disjunction)
92 } 83 }
93 84
94 for(query: pQueries) { 85 // The types are calculated
95 val types = query.lookup(viatra2LogicTrace.query2Disjunction).bodies.toInvertedMap[ 86 val types = typeInferer.inferTypes(pQueries,ecore2LogicTrace,viatra2LogicTrace)
96 TypeHelper::inferUnaryTypesFor(it.uniqueVariables,it.constraints,EMFQueryMetaContext.DEFAULT)
97 ]
98// for(m : types.values) {
99// for(n: m.entrySet) {
100// val variable = n.key
101// println(''' - «variable.name»''')
102// for(type : n.value) {
103// println('''«variable.name» - «type»''')
104// }
105// }
106//
107// }
108
109 typeAlanysis.put(query,types)
110 }
111 87
88 // First, the signature of the queries are translated, ...
112 for(query: pQueries) { 89 for(query: pQueries) {
113 try { 90 try {
114 this.transformQueryHeader(query,query.lookup(typeAlanysis),ecore2LogicTrace,viatra2LogicTrace,config) 91 this.transformQueryHeader(query,types,ecore2LogicTrace,viatra2LogicTrace,config)
115 } catch(IllegalArgumentException e) { 92 } catch(IllegalArgumentException e) {
116 throw new IllegalArgumentException(''' 93 throw new IllegalArgumentException('''
117 Unable to translate query "«query.fullyQualifiedName»". 94 Unable to translate query "«query.fullyQualifiedName»".
118 Reason: «e.class.simpleName», «e.message»''',e) 95 Reason: «e.class.simpleName», «e.message»''',e)
119 } 96 }
120 } 97 }
98
99 // ...then the bodies, ...
121 for(query: pQueries) { 100 for(query: pQueries) {
122 try { 101 try {
123 this.transformQuerySpecification(query,query.lookup(typeAlanysis),ecore2LogicTrace,viatra2LogicTrace,config) 102 this.transformQuerySpecification(query,types,ecore2LogicTrace,viatra2LogicTrace,config)
124 } catch (IllegalArgumentException e){ 103 } catch (IllegalArgumentException e){
125 throw new IllegalArgumentException(''' 104 throw new IllegalArgumentException('''
126 Unable to translate query "«query.fullyQualifiedName»". 105 Unable to translate query "«query.fullyQualifiedName»".
127 Reason: «e.class.simpleName», «e.message»''',e) 106 Reason: «e.class.simpleName», «e.message»''',e)
128 } 107 }
129 } 108 }
130 /*for(d : viatra2LogicTrace.query2Relation.values) {
131 checkDefinition(d)
132 }*/
133 109
110 // ... and finally, the annotations.
134 transformQueryConstraints( 111 transformQueryConstraints(
135 queries.validationPatterns.map[internalQueryRepresentation], 112 queries.validationPatterns.map[internalQueryRepresentation],
136 queries.derivedFeatures, 113 queries.derivedFeatures,
137 ecore2LogicTrace,viatra2LogicTrace) 114 ecore2LogicTrace,viatra2LogicTrace)
115
138 return new TracedOutput(ecore2LogicTrace.output,viatra2LogicTrace) 116 return new TracedOutput(ecore2LogicTrace.output,viatra2LogicTrace)
139 } 117 }
140 118
141 def protected transformQueryHeader( 119 def protected transformQueryHeader(
142 PQuery pquery, 120 PQuery pquery,
143 Map<PBody, Map<PVariable, Set<IInputKey>>> types, 121 Viatra2LogicTypeResult types,
144 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace, 122 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace,
145 Viatra2LogicTrace viatra2LogicTrace, 123 Viatra2LogicTrace viatra2LogicTrace,
146 Viatra2LogicConfiguration config) 124 Viatra2LogicConfiguration config)
@@ -149,7 +127,7 @@ class Viatra2Logic {
149 val parameters = new ArrayList<Variable>(pquery.parameters.size) 127 val parameters = new ArrayList<Variable>(pquery.parameters.size)
150 for(vParam: pquery.parameters) { 128 for(vParam: pquery.parameters) {
151 val parameterName = '''parameter «vParam.name»''' 129 val parameterName = '''parameter «vParam.name»'''
152 val parameterType = getType(vParam,types,ecore2LogicTrace) 130 val parameterType = types.getType(pquery,vParam)
153 if(parameterType === null) { 131 if(parameterType === null) {
154 throw new AssertionError('''null type for parameter «vParam.name» in pattern «pquery.fullyQualifiedName»''') 132 throw new AssertionError('''null type for parameter «vParam.name» in pattern «pquery.fullyQualifiedName»''')
155 } 133 }
@@ -175,7 +153,7 @@ class Viatra2Logic {
175 153
176 def protected transformQuerySpecification( 154 def protected transformQuerySpecification(
177 PQuery pquery, 155 PQuery pquery,
178 Map<PBody, Map<PVariable, Set<IInputKey>>> types, 156 Viatra2LogicTypeResult types,
179 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace, 157 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace,
180 Viatra2LogicTrace viatra2LogicTrace, 158 Viatra2LogicTrace viatra2LogicTrace,
181 Viatra2LogicConfiguration config) 159 Viatra2LogicConfiguration config)
@@ -233,7 +211,7 @@ class Viatra2Logic {
233 } 211 }
234 212
235 def transformBody(PBody body, 213 def transformBody(PBody body,
236 Map<PBody, Map<PVariable, Set<IInputKey>>> types, 214 Viatra2LogicTypeResult types,
237 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace, 215 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace,
238 Viatra2LogicTrace viatra2LogicTrace, 216 Viatra2LogicTrace viatra2LogicTrace,
239 Viatra2LogicConfiguration config) 217 Viatra2LogicConfiguration config)
@@ -248,19 +226,29 @@ class Viatra2Logic {
248 // Inner Variables 226 // Inner Variables
249 val innerPositiveVariables = new LinkedList 227 val innerPositiveVariables = new LinkedList
250 val innerNegativeVariables = new LinkedList 228 val innerNegativeVariables = new LinkedList
229 val innerAggreatedVariables = new LinkedList
230 //println(body.uniqueVariables)
251 for(innerVariable : body.uniqueVariables) { 231 for(innerVariable : body.uniqueVariables) {
252 232
253 if(!variable2Variable.containsKey(innerVariable)) { 233 if(!variable2Variable.containsKey(innerVariable)) {
254 val name = '''variable «innerVariable.name.normalizeName»''' 234 if(innerVariable.aggregateOnly) {
255 //println(body.pattern.fullyQualifiedName + "-") 235 // do not create variable
256 val logicType = getType(innerVariable,types,ecore2LogicTrace) 236 innerAggreatedVariables.add(innerVariable)
257 val logicVariable = createVar(name,logicType) 237 variable2Variable.put(innerVariable,null)
258 if(innerVariable.isPositiveVariable) {
259 innerPositiveVariables += logicVariable
260 } else { 238 } else {
261 innerNegativeVariables += logicVariable 239 val name = '''variable «innerVariable.name.normalizeName»'''
240 val logicType = types.getType(body,innerVariable)
241 if(logicType === null) {
242 throw new IllegalArgumentException('''Variable «innerVariable.name.normalizeName» has no type!''')
243 }
244 val logicVariable = createVar(name,logicType)
245 if(innerVariable.negativeOnly) {
246 innerNegativeVariables += logicVariable
247 } else {
248 innerPositiveVariables += logicVariable
249 }
250 variable2Variable.put(innerVariable,logicVariable)
262 } 251 }
263 variable2Variable.put(innerVariable,logicVariable)
264 } 252 }
265 } 253 }
266 254
@@ -282,226 +270,36 @@ class Viatra2Logic {
282 270
283 return allVariablesAreExisting 271 return allVariablesAreExisting
284 } 272 }
285// def toTypeJudgement(PVariable v, IInputKey key) {
286// new TypeJudgement(key,new Tuple1)
287// }
288 273
289 def private normalizeName(String variableName) { 274 def private normalizeName(String variableName) {
290 return variableName.replaceAll("[\\W]|_", "") 275 return variableName.replaceAll("[\\W]|_", "")
291 } 276 }
292
293 /**
294 * Translates the type of a parameter variable in a pattern
295 */
296 def TypeReference getType(PParameter v, Map<PBody, Map<PVariable, Set<IInputKey>>> types, TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) {
297 // If parameter type is specified then the specified type is used
298 if(v.declaredUnaryType !== null) {
299 val res = transformTypeReference(v.declaredUnaryType,ecore2LogicTrace)
300 if(res === null) {
301 throw new AssertionError('''
302 Unable to translate declared type «v.declaredUnaryType».
303 ''')
304 } else {
305 return res
306 }
307 }
308 // Otherwise, calculate the type based on the type of the variable in the bodies
309 else {
310 val bodies = types.keySet
311 val typesFromBodies = new ArrayList(bodies.size)
312 for(body : bodies) {
313 // collect the variable in the body
314 val exported = body.symbolicParameters.filter[it.patternParameter === v]
315 if(exported.size !== 1) {
316 throw new AssertionError('''Parameter «v.name» has no reference in body!''')
317 }
318 val variable = exported.head.parameterVariable
319 typesFromBodies+=variable.getType(types,ecore2LogicTrace)
320 }
321 return typesFromBodies.calculateCommonSupertype
322 }
323 }
324
325 /**
326 * Translates the type of a variable in a pattern body
327 */
328 def TypeReference getType(PVariable v, Map<PBody, Map<PVariable, Set<IInputKey>>> types ,TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) {
329 if (v.isPositiveVariable) {
330 val keys = getTypesFromCollection(v,types)
331 val logicTypes = keys.map[transformTypeReference(it,ecore2LogicTrace)].filterNull
332 return logicTypes.calculateCommonSubtype
333 } else {
334 val onlyConstraint = v.referringConstraints.head as NegativePatternCall
335 val indexOfVariable = v.lookup(onlyConstraint.actualParametersTuple.invertIndex)
336 val parameter = onlyConstraint.referredQuery.parameters.get(indexOfVariable)
337 val declaredUnaryType = parameter.declaredUnaryType as BaseEMFTypeKey<? extends EClassifier>
338 if (declaredUnaryType === null) {
339 throw new UnsupportedOperationException(
340 '''parameter «parameter.name» in pattern «onlyConstraint.referredQuery.fullyQualifiedName» does not have type!''')
341 } else
342 return declaredUnaryType.transformTypeReference(ecore2LogicTrace)
343 }
344 }
345
346 def getTypesFromCollection(PVariable v, Map<PBody, Map<PVariable, Set<IInputKey>>> types) {
347 for(entry : types.entrySet) {
348 if(entry.key.uniqueVariables.contains(v)) {
349 return v.lookup(entry.value)
350 }
351 }
352 throw new IllegalArgumentException('''Variable «v.name» is not present in neither of the bodies!''')
353 }
354
355 277
356 def TypeReference calculateCommonSubtype(Iterable<TypeReference> types) { 278 def isNegativeOnly(PVariable variable) {
357 val primitiveTypeReferences = types.filter(PrimitiveTypeReference) 279 if(variable.referringConstraints.size == 1) {
358 val complexTypeReferences = types.filter(ComplexTypeReference) 280 val PConstraint onlyConstraint = variable.referringConstraints.head
359 if(complexTypeReferences.isEmpty) { 281 if(onlyConstraint instanceof NegativePatternCall) {
360 val head = primitiveTypeReferences.head 282 return true
361 if(primitiveTypeReferences.exists[it.eClass !== head.eClass]) { 283 } else {
362 throw new IllegalArgumentException('''Inconsistent types: «primitiveTypeReferences.map[eClass.name].toSet.toList»''') 284 return false
363 }
364 return head
365 } else if(primitiveTypeReferences.isEmpty) {
366 val complexTypes = complexTypeReferences.map[it.referred].toSet
367 if(complexTypes.size === 1) {
368 return builder.toTypeReference(complexTypes.head)
369 }
370 // Collect possible subtypes
371 val subtypeSets = complexTypes.map[it.transitiveClosureStar[it.subtypes].toSet]
372 val commonTypeSet = new HashSet(subtypeSets.head)
373 val otherSets = subtypeSets.tail
374 for(otherSet : otherSets) {
375 commonTypeSet.retainAll(otherSet)
376 }
377 if(commonTypeSet.empty) {
378 throw new IllegalArgumentException('''Inconsistent types: «complexTypes.map[name].toList»''')
379 }
380
381 return calculateCommonComplexSupertype(commonTypeSet)
382
383 } else {
384 throw new IllegalArgumentException('''
385 Inconsistent types, mixing primitive and complex types:
386 «primitiveTypeReferences.map[eClass.name].toSet.toList»
387 and
388 «complexTypeReferences.map[it.referred].toSet.map[name].toList»''')
389
390 }
391 }
392 def TypeReference calculateCommonSupertype(Iterable<TypeReference> types) {
393 val primitiveTypeReferences = types.filter(PrimitiveTypeReference)
394 val complexTypeReferences = types.filter(ComplexTypeReference)
395 if(complexTypeReferences.isEmpty) {
396 val head = primitiveTypeReferences.head
397 if(primitiveTypeReferences.exists[it.eClass !== head.eClass]) {
398 throw new IllegalArgumentException('''Inconsistent types: «primitiveTypeReferences.map[eClass.name].toSet.toList»''')
399 }
400 return head
401 } else if(primitiveTypeReferences.isEmpty) {
402 val complexTypes = complexTypeReferences.map[it.referred].toSet
403 return calculateCommonComplexSupertype(complexTypes)
404
405 } else {
406 throw new IllegalArgumentException('''
407 Inconsistent types, mixing primitive and complex types:
408 «primitiveTypeReferences.map[eClass.name].toSet.toList»
409 and
410 «complexTypeReferences.map[it.referred].toSet.map[name].toList»''')
411
412 }
413 }
414 def TypeReference calculateCommonComplexSupertype(Set<Type> complexTypes) {
415 if(complexTypes.size === 1) {
416 return builder.toTypeReference(complexTypes.head)
417 }
418 // Collect possible supertypes
419 val supertypeSets = complexTypes.map[it.transitiveClosureStar[it.supertypes].toSet]
420 val commonTypeSet = new HashSet(supertypeSets.head)
421 val otherSets = supertypeSets.tail
422 for(otherSet : otherSets) {
423 commonTypeSet.retainAll(otherSet)
424 }
425 if(commonTypeSet.empty) {
426 throw new IllegalArgumentException('''Inconsistent types: «complexTypes.map[name].toList»''')
427 }
428 // Remove type that already have covered
429 val coveredTypes = commonTypeSet.map[it.supertypes].flatten
430 commonTypeSet.removeAll(coveredTypes)
431 return builder.toTypeReference(commonTypeSet.head)
432 }
433
434 /**
435 * Transforms a Viatra type reference to a logic type.
436 */
437 def dispatch TypeReference transformTypeReference(EDataTypeInSlotsKey k,TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) {
438 val w = k.wrappedKey
439 if(w == EcorePackage.Literals.EINT || w == EcorePackage.Literals.ESHORT || w == EcorePackage.Literals.ELONG) {
440 return builder.LogicInt
441 } else if(w == EcorePackage.Literals.EDOUBLE || w == EcorePackage.Literals.EFLOAT) {
442 return builder.LogicReal
443 } else if(w == EcorePackage.Literals.EBOOLEAN) {
444 return builder.LogicBool
445 } else if(w == EcorePackage.Literals.ESTRING) {
446 return builder.LogicString
447 } else if(w instanceof EEnum) {
448 val c = this.ecore2Logic.TypeofEEnum(ecore2LogicTrace.trace,w)
449 return builder.toTypeReference(c);
450 } else throw new UnsupportedOperationException('''Unknown reference type «w.class.name»''')
451 }
452 def dispatch TypeReference transformTypeReference(JavaTransitiveInstancesKey k,TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) {
453 val c = k.wrapperInstanceClass
454 if(c == Integer || c == Long || c == Short) {
455 return LogicInt
456 } else if(c == Float || c == Double) {
457 return LogicReal
458 } else if(c == Boolean) {
459 return LogicBool
460 } else if(c == String) {
461 return LogicString
462 } else if(c.superclass == java.lang.Enum){
463 val enums = ecore2Logic.allEnumsInScope(ecore2LogicTrace.trace)
464 for(enum : enums) {
465 if(c == enum.instanceClass) {
466 return builder.toTypeReference(ecore2Logic.TypeofEEnum(ecore2LogicTrace.trace,enum))
467 }
468 } 285 }
469 throw new IllegalArgumentException('''Enum type «c.simpleName» is not mapped to logic!''')
470 }
471 return null
472 }
473 def dispatch TypeReference transformTypeReference(EClassTransitiveInstancesKey k,TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) {
474 val c = k.wrappedKey
475
476 if(this.ecore2Logic.allClassesInScope(ecore2LogicTrace.trace).toList.contains(c)) {
477 return builder.toTypeReference(this.ecore2Logic.TypeofEClass(ecore2LogicTrace.trace,k.wrappedKey))
478 } else { 286 } else {
479 return null 287 return false
480 } 288 }
481 } 289 }
482 def dispatch TypeReference transformTypeReference(EClassUnscopedTransitiveInstancesKey k, TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) {
483 val c = k.wrappedKey
484
485 if(this.ecore2Logic.allClassesInScope(ecore2LogicTrace.trace).toList.contains(c)) {
486 return builder.toTypeReference(this.ecore2Logic.TypeofEClass(ecore2LogicTrace.trace,k.wrappedKey))
487 } else {
488 return null
489 }
490 }
491
492 def dispatch TypeReference transformTypeReference(IInputKey k,TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) {
493 //println(k)
494 throw new IllegalArgumentException('''Unsupported type: «k.class.simpleName»''')
495 }
496 290
497 def boolean isPositiveVariable(PVariable v) { 291 def isAggregateOnly(PVariable variable) {
498 val constraints = v.referringConstraints 292 if(variable.referringConstraints.size == 1) {
499 if(constraints.size == 1) { 293 val PConstraint onlyConstraint = variable.referringConstraints.head
500 val onlyConstraint = constraints.head 294 if(onlyConstraint instanceof AggregatorConstraint) {
501 if(onlyConstraint instanceof NegativePatternCall) { 295 return true
296 } else if(onlyConstraint instanceof PatternMatchCounter) {
297 return true
298 } else {
502 return false 299 return false
503 } 300 }
301 } else {
302 return false
504 } 303 }
505 return true
506 } 304 }
507} \ No newline at end of file 305} \ No newline at end of file
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2LogicTypeInferer.xtend b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2LogicTypeInferer.xtend
new file mode 100644
index 00000000..b8a6b9c1
--- /dev/null
+++ b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2LogicTypeInferer.xtend
@@ -0,0 +1,392 @@
1package hu.bme.mit.inf.dslreasoner.viatra2logic
2
3import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic
4import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace
5import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder
6import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput
7import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ComplexTypeReference
8import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntTypeReference
9import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.PrimitiveTypeReference
10import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealTypeReference
11import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type
12import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeReference
13import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
14import java.util.HashMap
15import java.util.HashSet
16import java.util.List
17import java.util.Set
18import org.eclipse.emf.ecore.EEnum
19import org.eclipse.emf.ecore.EcorePackage
20import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup
21import org.eclipse.viatra.query.patternlanguage.emf.specification.XBaseEvaluator
22import org.eclipse.viatra.query.runtime.emf.EMFQueryMetaContext
23import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey
24import org.eclipse.viatra.query.runtime.emf.types.EClassUnscopedTransitiveInstancesKey
25import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey
26import org.eclipse.viatra.query.runtime.matchers.context.IInputKey
27import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey
28import org.eclipse.viatra.query.runtime.matchers.planning.helpers.TypeHelper
29import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator
30import org.eclipse.viatra.query.runtime.matchers.psystem.PBody
31import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternCallBasedDeferred
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery
38import org.eclipse.xtext.xbase.XExpression
39import org.eclipse.xtext.xbase.typesystem.IBatchTypeResolver
40import org.eclipse.xtext.xbase.typesystem.references.UnknownTypeReference
41
42import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
43import org.eclipse.xtext.xbase.typesystem.references.InnerTypeReference
44
45class Viatra2LogicTypeInferer{
46 val Ecore2Logic ecore2Logic
47 val extension LogicProblemBuilder builder = new LogicProblemBuilder
48 /**Typeresolver uses the same resolver as EMFPatternLanguageStandaloneSetup.*/
49 val IBatchTypeResolver typeResolver =
50 (new EMFPatternLanguageStandaloneSetup).createInjector.getInstance(IBatchTypeResolver)
51 val expressionExtractor = new XExpressionExtractor
52
53 new(Ecore2Logic ecore2Logic) {
54 this.ecore2Logic = ecore2Logic
55 }
56
57 def Viatra2LogicTypeResult inferTypes(List<PQuery> pQueries, TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace, Viatra2LogicTrace viatra2LogicTrace) {
58 val Viatra2LogicTypeResult result = new Viatra2LogicTypeResult(new HashMap,new HashMap);
59 for(query : pQueries) {
60 for(body: query.lookup(viatra2LogicTrace.query2Disjunction).bodies) {
61 for(variable : body.uniqueVariables) {
62 getOrMakeTypeDecision(result,variable,body,ecore2LogicTrace,viatra2LogicTrace,emptySet)
63 }
64 }
65 for(parameter: query.parameters) {
66 getOrMakeTypeDecision(result,query,parameter,ecore2LogicTrace,viatra2LogicTrace,emptySet)
67 }
68 }
69 return result
70 }
71
72 private def TypeReference getOrMakeTypeDecision(
73 Viatra2LogicTypeResult result,
74 PVariable variable, PBody body,
75 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace,
76 Viatra2LogicTrace viatra2LogicTrace,
77 Set<? extends PParameter> checkedInDecisionMaking)
78 {
79 if(result.containsSolution(body,variable)) {
80 return result.getType(body,variable)
81 } else {
82 val inferredTypesByViatra = TypeHelper::inferUnaryTypesFor(body.uniqueVariables, body.constraints, EMFQueryMetaContext.DEFAULT)
83 val constraintsForVariable = variable.lookup(inferredTypesByViatra)
84
85 val typeConstraintsDerivedByTypeHelper = constraintsForVariable.map[transformTypeReference(ecore2LogicTrace)]
86 val typesFromEval = variable.getTypesFromEval(typeResolver)
87 val typesFromAggregatorResult = variable.getTypeFromPassivePatternCallConstraintResult(
88 result,
89 ecore2LogicTrace,
90 viatra2LogicTrace,
91 checkedInDecisionMaking)
92
93 val typesFromPositiveReasoning = (typeConstraintsDerivedByTypeHelper + typesFromEval + typesFromAggregatorResult).filterNull
94
95 val types = if(!typesFromPositiveReasoning.empty) {
96 typesFromPositiveReasoning
97 } else {
98 variable.getTypeFromPassivePatternCallConstraints(
99 result,
100 ecore2LogicTrace,
101 viatra2LogicTrace,
102 checkedInDecisionMaking)
103 }
104
105 val commonSubtype = this.calculateCommonSubtype(types)
106
107 result.addType(body,variable,commonSubtype)
108 return commonSubtype
109 }
110 }
111
112 private def TypeReference getOrMakeTypeDecision(
113 Viatra2LogicTypeResult result,
114 PQuery query,
115 PParameter parameter,
116 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace,
117 Viatra2LogicTrace viatra2LogicTrace,
118 Set<? extends PParameter> checkedInDecisionMaking)
119 {
120 if(checkedInDecisionMaking.contains(parameter)) {
121 return null
122 }
123 if(result.containsSolution(parameter)) {
124 return result.getType(query, parameter)
125 }
126
127 var TypeReference typeReference;
128
129 if(parameter.declaredUnaryType !== null) {
130 val key = parameter.declaredUnaryType
131 typeReference = key.transformTypeReference(ecore2LogicTrace)
132 } else {
133 val bodies = query.lookup(viatra2LogicTrace.query2Disjunction).bodies
134 val newChecked = new HashSet(checkedInDecisionMaking) => [add(parameter)]
135 val Iterable<TypeReference> variableTypes = bodies.map[body|
136 val symbolicParameter = body.symbolicParameters.filter[patternParameter === parameter].head
137 val variable = symbolicParameter.parameterVariable
138 getOrMakeTypeDecision(result,variable,body,ecore2LogicTrace,viatra2LogicTrace,newChecked)
139 ]
140 typeReference = calculateCommonSupertype(variableTypes)
141 }
142 result.addType(query,parameter,typeReference)
143 return typeReference
144 }
145
146 private def Iterable<? extends TypeReference> getTypesFromEval(PVariable v, IBatchTypeResolver typeResolver) {
147 val constraints = v.getReferringConstraintsOfType(
148 typeof(ExpressionEvaluation)
149 ).filter[
150 it.outputVariable === v
151 ]
152 val res = constraints.map[getTypeFromEval]
153 return res
154 }
155
156 def TypeReference getTypeFromEval(ExpressionEvaluation evaluation) {
157 val XExpression expression = expressionExtractor.extractExpression(evaluation.evaluator)
158 val returnType = typeResolver.resolveTypes(expression).getReturnType(expression);
159 if(returnType === null || returnType instanceof UnknownTypeReference) {
160 return null
161 } else {
162 val javaIdentifier = returnType.wrapperTypeIfPrimitive.javaIdentifier
163 if(javaIdentifier == Boolean.name) {
164 return LogicBool
165 } else if(javaIdentifier == Integer.name || javaIdentifier == Short.name) {
166 return LogicInt
167 } else if(javaIdentifier == Double.name || javaIdentifier == Float.name){
168 return LogicReal
169 } else if(javaIdentifier == String.name) {
170 return LogicString
171 } else {
172 throw new UnsupportedOperationException('''Unsupported eval type: "«javaIdentifier»"!''')
173 }
174 }
175 }
176
177 private def getTypeFromPassivePatternCallConstraintResult(
178 PVariable v,
179 Viatra2LogicTypeResult result,
180 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace,
181 Viatra2LogicTrace viatra2LogicTrace,
182 Set<? extends PParameter> checkedInDecisionMaking
183 ) {
184 val referringConstraints = v.referringConstraints
185
186 val referringCountMatcherTargeting = referringConstraints
187 .filter(PatternMatchCounter)
188 .filter[it.resultVariable === v]
189 .map[builder.LogicInt]
190 val referringAggregatorConstraintsTargeting = referringConstraints
191 .filter(AggregatorConstraint)
192 .filter[it.resultVariable === v]
193 .map[ // get the type of the referred column
194 getOrMakeTypeDecision(
195 result,
196 it.referredQuery,
197 it.referredQuery.parameters.get(aggregatedColumn),
198 ecore2LogicTrace,
199 viatra2LogicTrace,
200 checkedInDecisionMaking)]
201
202 return referringCountMatcherTargeting + referringAggregatorConstraintsTargeting
203 }
204
205 private def getTypeFromPassivePatternCallConstraints(
206 PVariable v,
207 Viatra2LogicTypeResult result,
208 TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace,
209 Viatra2LogicTrace viatra2LogicTrace,
210 Set<? extends PParameter> checkedInDecisionMaking
211 ) {
212 val referringConstraints = v.referringConstraints
213 if(referringConstraints.size === 1) {
214 val onlyConstraint = referringConstraints.head
215
216 if(onlyConstraint instanceof PatternCallBasedDeferred) {
217 val indexOfVariable = v.lookup(onlyConstraint.actualParametersTuple.invertIndex)
218 val parameter = onlyConstraint.referredQuery.parameters.get(indexOfVariable)
219 val res = getOrMakeTypeDecision(result, onlyConstraint.referredQuery, parameter, ecore2LogicTrace,viatra2LogicTrace,checkedInDecisionMaking)
220 return #[res]
221 } else {
222 throw new IllegalArgumentException('''A non-PatternCallBasedDeferred type constraint is referring to the variable "«v.name»"!''')
223 }
224 } else {
225 throw new IllegalArgumentException('''Multiple («referringConstraints.size», «FOR c:referringConstraints SEPARATOR ", "»«c»«ENDFOR») constraints are referring to variable "«v.name»", but no type is inferred!''')
226 }
227 }
228
229 def TypeReference calculateCommonSubtype(Iterable<TypeReference> types) {
230 val primitiveTypeReferences = types.filter(PrimitiveTypeReference)
231 val complexTypeReferences = types.filter(ComplexTypeReference)
232 if(complexTypeReferences.isEmpty) {
233 // If there is an int type, ...
234 if(primitiveTypeReferences.exists[it instanceof IntTypeReference]) {
235 // ... and all types are either real or int, then return int!
236 if(primitiveTypeReferences.forall[it instanceof RealTypeReference || it instanceof IntTypeReference]) {
237 return primitiveTypeReferences.filter(IntTypeReference).head
238 }
239 // Otherwise, the types are inconsistent, because they mixing numeric and non-numeric types.
240 else throw new IllegalArgumentException('''Inconsistent types: «primitiveTypeReferences.map[eClass.name].toSet.toList»''')
241 }
242 // If there is no Real, then the types should be homogenious
243 val head = primitiveTypeReferences.head
244 if(primitiveTypeReferences.exists[it.eClass !== head.eClass]) {
245 throw new IllegalArgumentException('''Inconsistent types: «primitiveTypeReferences.map[eClass.name].toSet.toList»''')
246 }
247 return head
248 } else if(primitiveTypeReferences.isEmpty) {
249 val complexTypes = complexTypeReferences.map[it.referred].toSet
250 if(complexTypes.size === 1) {
251 return builder.toTypeReference(complexTypes.head)
252 }
253 // Collect possible subtypes
254 val subtypeSets = complexTypes.map[it.transitiveClosureStar[it.subtypes].toSet]
255 val commonTypeSet = new HashSet(subtypeSets.head)
256 val otherSets = subtypeSets.tail
257 for(otherSet : otherSets) {
258 commonTypeSet.retainAll(otherSet)
259 }
260 if(commonTypeSet.empty) {
261 throw new IllegalArgumentException('''Inconsistent types: «complexTypes.map[name].toList»''')
262 }
263
264
265 return calculateCommonComplexSupertype(commonTypeSet)
266
267 } else {
268 throw new IllegalArgumentException('''
269 Inconsistent types, mixing primitive and complex types:
270 «primitiveTypeReferences.map[eClass.name].toSet.toList»
271 and
272 «complexTypeReferences.map[it.referred].toSet.map[name].toList»''')
273
274 }
275 }
276
277
278 def TypeReference calculateCommonSupertype(Iterable<TypeReference> types) {
279 val primitiveTypeReferences = types.filter(PrimitiveTypeReference)
280 val complexTypeReferences = types.filter(ComplexTypeReference)
281 if(complexTypeReferences.isEmpty) {
282 // If there is a real type, ...
283 if(primitiveTypeReferences.exists[it instanceof RealTypeReference]) {
284 // ... and all types are either real or int, then return real!
285 if(primitiveTypeReferences.forall[it instanceof RealTypeReference || it instanceof IntTypeReference]) {
286 return primitiveTypeReferences.filter(RealTypeReference).head
287 }
288 // Otherwise, the types are inconsistent, because they mixing numeric and non-numeric types.
289 else throw new IllegalArgumentException('''Inconsistent types: «primitiveTypeReferences.map[eClass.name].toSet.toList»''')
290 }
291 // If there is no Real, then the types should be homogenious
292 val head = primitiveTypeReferences.head
293 if(primitiveTypeReferences.exists[it.eClass !== head.eClass]) {
294 throw new IllegalArgumentException('''Inconsistent types: «primitiveTypeReferences.map[eClass.name].toSet.toList»''')
295 }
296 return head
297 } else if(primitiveTypeReferences.isEmpty) {
298 val complexTypes = complexTypeReferences.map[it.referred].toSet
299 return calculateCommonComplexSupertype(complexTypes)
300
301 } else {
302 throw new IllegalArgumentException('''
303 Inconsistent types, mixing primitive and complex types:
304 «primitiveTypeReferences.map[eClass.name].toSet.toList»
305 and
306 «complexTypeReferences.map[it.referred].toSet.map[name].toList»''')
307
308 }
309 }
310 def TypeReference calculateCommonComplexSupertype(Set<Type> complexTypes) {
311 if(complexTypes.size === 1) {
312 return builder.toTypeReference(complexTypes.head)
313 }
314 // Collect possible supertypes
315 val supertypeSets = complexTypes.map[it.transitiveClosureStar[it.supertypes].toSet]
316 val commonTypeSet = new HashSet(supertypeSets.head)
317 val otherSets = supertypeSets.tail
318 for(otherSet : otherSets) {
319 commonTypeSet.retainAll(otherSet)
320 }
321 if(commonTypeSet.empty) {
322 throw new IllegalArgumentException('''Inconsistent types: «complexTypes.map[name].toList»''')
323 }
324 // Remove type that already have covered
325 val coveredTypes = commonTypeSet.map[it.supertypes].flatten
326 commonTypeSet.removeAll(coveredTypes)
327 return builder.toTypeReference(commonTypeSet.head)
328 }
329
330 /**
331 * Transforms a Viatra type reference to a logic type.
332 */
333 def dispatch TypeReference transformTypeReference(EDataTypeInSlotsKey k,TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) {
334 val w = k.wrappedKey
335 if(w == EcorePackage.Literals.EINT || w == EcorePackage.Literals.ESHORT || w == EcorePackage.Literals.ELONG) {
336 return builder.LogicInt
337 } else if(w == EcorePackage.Literals.EDOUBLE || w == EcorePackage.Literals.EFLOAT) {
338 return builder.LogicReal
339 } else if(w == EcorePackage.Literals.EBOOLEAN) {
340 return builder.LogicBool
341 } else if(w == EcorePackage.Literals.ESTRING) {
342 return builder.LogicString
343 } else if(w instanceof EEnum) {
344 val c = this.ecore2Logic.TypeofEEnum(ecore2LogicTrace.trace,w)
345 return builder.toTypeReference(c);
346 } else throw new UnsupportedOperationException('''Unknown reference type «w.class.name»''')
347 }
348 def dispatch TypeReference transformTypeReference(JavaTransitiveInstancesKey k,TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) {
349 val c = k.wrapperInstanceClass
350 if(c == Integer || c == Long || c == Short) {
351 return LogicInt
352 } else if(c == Float || c == Double) {
353 return LogicReal
354 } else if(c == Boolean) {
355 return LogicBool
356 } else if(c == String) {
357 return LogicString
358 } else if(c.superclass == Enum){
359 val enums = ecore2Logic.allEnumsInScope(ecore2LogicTrace.trace)
360 for(enum : enums) {
361 if(c == enum.instanceClass) {
362 return builder.toTypeReference(ecore2Logic.TypeofEEnum(ecore2LogicTrace.trace,enum))
363 }
364 }
365 throw new IllegalArgumentException('''Enum type «c.simpleName» is not mapped to logic!''')
366 } else {
367 return null
368 }
369 }
370 def dispatch TypeReference transformTypeReference(EClassTransitiveInstancesKey k,TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) {
371 val c = k.wrappedKey
372
373 if(this.ecore2Logic.allClassesInScope(ecore2LogicTrace.trace).toList.contains(c)) {
374 return builder.toTypeReference(this.ecore2Logic.TypeofEClass(ecore2LogicTrace.trace,k.wrappedKey))
375 } else {
376 return null
377 }
378 }
379 def dispatch TypeReference transformTypeReference(EClassUnscopedTransitiveInstancesKey k, TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) {
380 val c = k.wrappedKey
381
382 if(this.ecore2Logic.allClassesInScope(ecore2LogicTrace.trace).toList.contains(c)) {
383 return builder.toTypeReference(this.ecore2Logic.TypeofEClass(ecore2LogicTrace.trace,k.wrappedKey))
384 } else {
385 return null
386 }
387 }
388
389 def dispatch TypeReference transformTypeReference(IInputKey k,TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace) {
390 throw new IllegalArgumentException('''Unsupported type: «k.class.simpleName»''')
391 }
392} \ No newline at end of file
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2LogicTypeResult.xtend b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2LogicTypeResult.xtend
new file mode 100644
index 00000000..7ba90724
--- /dev/null
+++ b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2LogicTypeResult.xtend
@@ -0,0 +1,47 @@
1package hu.bme.mit.inf.dslreasoner.viatra2logic
2
3import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeReference
4import java.util.Map
5import org.eclipse.viatra.query.runtime.matchers.psystem.PBody
6import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable
7import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter
8import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery
9import org.eclipse.xtend.lib.annotations.Data
10import org.eclipse.xtext.xbase.lib.Functions.Function0
11import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
12import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ComplexTypeReference
13import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory
14import org.eclipse.emf.ecore.util.EcoreUtil
15import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.PrimitiveTypeReference
16
17@Data class Viatra2LogicTypeResult{
18 Map<Pair<PQuery,PParameter>,Function0<TypeReference>> typesInParameters
19 Map<Pair<PBody,PVariable>,Function0<TypeReference>> typesInBodies;
20
21 def addType(PBody body, PVariable variable, TypeReference typeConstructor) {
22 typesInBodies.put(body->variable,typeConstructor.createTypeConstructor)
23 }
24 def addType(PQuery query, PParameter variable, TypeReference typeConstructor) {
25 typesInParameters.put(query->variable,typeConstructor.createTypeConstructor)
26 }
27 def getType(PBody body, PVariable variable) {
28 return (body->variable).lookup(typesInBodies).apply
29 }
30 def getType(PQuery query, PParameter variable) {
31 return (query->variable).lookup(typesInParameters).apply
32 }
33
34 def containsSolution(PBody body, PVariable variable) {
35 return typesInBodies.containsKey(body->variable)
36 }
37 def containsSolution(PParameter variable) {
38 return typesInParameters.containsKey(variable)
39 }
40
41 def dispatch Function0<TypeReference> createTypeConstructor(ComplexTypeReference ref) {
42 return [LogiclanguageFactory.eINSTANCE.createComplexTypeReference=>[it.referred = ref.referred]]
43 }
44 def dispatch Function0<TypeReference> createTypeConstructor(PrimitiveTypeReference ref) {
45 return [EcoreUtil.copy(ref)]
46 }
47} \ No newline at end of file
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/XExpressionExtractor.xtend b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/XExpressionExtractor.xtend
new file mode 100644
index 00000000..ea8d0b23
--- /dev/null
+++ b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/XExpressionExtractor.xtend
@@ -0,0 +1,24 @@
1package hu.bme.mit.inf.dslreasoner.viatra2logic
2
3import org.eclipse.viatra.query.patternlanguage.emf.specification.XBaseEvaluator
4import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator
5import org.eclipse.xtext.xbase.XExpression
6
7class XExpressionExtractor {
8 def dispatch XExpression extractExpression(XBaseEvaluator evaluator) { evaluator.expression }
9 def dispatch XExpression extractExpression(IExpressionEvaluator evaluator) {
10 val clazz = evaluator.class
11 if(clazz.name == "org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.VariableMappingExpressionEvaluatorWrapper") {
12 val field = clazz.declaredFields.filter[it.name == "wrapped"].head
13 if(field === null) {
14 throw new IllegalArgumentException('''Class «clazz.simpleName» has no field "wrapped"!''')
15 } else {
16 field.setAccessible(true);
17 val wrappedEvaluator = field.get(evaluator) as XBaseEvaluator
18 return wrappedEvaluator.extractExpression
19 }
20 } else {
21 throw new IllegalArgumentException('''Unsupported expression evaluation form: «clazz.simpleName»!''')
22 }
23 }
24} \ No newline at end of file