From 9152a660dbfbf3294964233c76d6cf22111298ff Mon Sep 17 00:00:00 2001
From: Oszkar Semerath
Date: Tue, 9 Jul 2019 20:49:10 +0200
Subject: aggregated partial substitution + builder
---
.../model/logiclanguage/AggregateExpression.java | 15 ++
.../AggregatedParameterSubstitution.java | 46 ++++++
.../model/logiclanguage/LogiclanguageFactory.java | 9 ++
.../model/logiclanguage/LogiclanguagePackage.java | 152 +++++++++++++++++++-
.../impl/AggregateExpressionImpl.java | 56 ++++++++
.../impl/AggregatedParameterSubstitutionImpl.java | 159 +++++++++++++++++++++
.../impl/LogiclanguageFactoryImpl.java | 12 ++
.../impl/LogiclanguagePackageImpl.java | 46 ++++++
.../util/LogiclanguageAdapterFactory.java | 18 +++
.../logiclanguage/util/LogiclanguageSwitch.java | 21 +++
10 files changed, 533 insertions(+), 1 deletion(-)
create mode 100644 Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/AggregatedParameterSubstitution.java
create mode 100644 Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/AggregatedParameterSubstitutionImpl.java
(limited to 'Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner')
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 be146469..4b38becf 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
@@ -2,6 +2,8 @@
*/
package hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage;
+import org.eclipse.emf.common.util.EList;
+
/**
*
@@ -13,6 +15,7 @@ package hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage;
*
*
* - {@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getRelation Relation}
+ * - {@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getParameterSubstitution Parameter Substitution}
*
*
* @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage#getAggregateExpression()
@@ -46,4 +49,16 @@ public interface AggregateExpression extends Term {
*/
void setRelation(Relation value);
+ /**
+ * Returns the value of the 'Parameter Substitution' containment reference list.
+ * The list contents are of type {@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregatedParameterSubstitution}.
+ *
+ *
+ * @return the value of the 'Parameter Substitution' containment reference list.
+ * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage#getAggregateExpression_ParameterSubstitution()
+ * @model containment="true"
+ * @generated
+ */
+ EList getParameterSubstitution();
+
} // AggregateExpression
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/AggregatedParameterSubstitution.java b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/AggregatedParameterSubstitution.java
new file mode 100644
index 00000000..94b6365d
--- /dev/null
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/AggregatedParameterSubstitution.java
@@ -0,0 +1,46 @@
+/**
+ */
+package hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ *
+ * A representation of the model object 'Aggregated Parameter Substitution'.
+ *
+ *
+ *
+ * The following features are supported:
+ *
+ *
+ * - {@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregatedParameterSubstitution#getVariable Variable}
+ *
+ *
+ * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage#getAggregatedParameterSubstitution()
+ * @model
+ * @generated
+ */
+public interface AggregatedParameterSubstitution extends EObject {
+ /**
+ * Returns the value of the 'Variable' reference.
+ *
+ *
+ * @return the value of the 'Variable' reference.
+ * @see #setVariable(Variable)
+ * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage#getAggregatedParameterSubstitution_Variable()
+ * @model
+ * @generated
+ */
+ Variable getVariable();
+
+ /**
+ * Sets the value of the '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregatedParameterSubstitution#getVariable Variable}' reference.
+ *
+ *
+ * @param value the new value of the 'Variable' reference.
+ * @see #getVariable()
+ * @generated
+ */
+ void setVariable(Variable value);
+
+} // AggregatedParameterSubstitution
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/LogiclanguageFactory.java b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/LogiclanguageFactory.java
index a6b0a790..33d79329 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/LogiclanguageFactory.java
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/LogiclanguageFactory.java
@@ -453,6 +453,15 @@ public interface LogiclanguageFactory extends EFactory {
*/
Max createMax();
+ /**
+ * Returns a new object of class 'Aggregated Parameter Substitution'.
+ *
+ *
+ * @return a new object of class 'Aggregated Parameter Substitution'.
+ * @generated
+ */
+ AggregatedParameterSubstitution createAggregatedParameterSubstitution();
+
/**
* Returns the package supported by this factory.
*
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 ddfb75a2..f5347e31 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
@@ -2750,6 +2750,15 @@ public interface LogiclanguagePackage extends EPackage {
*/
int AGGREGATE_EXPRESSION__RELATION = TERM_FEATURE_COUNT + 0;
+ /**
+ * The feature id for the 'Parameter Substitution' containment reference list.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION = TERM_FEATURE_COUNT + 1;
+
/**
* The number of structural features of the 'Aggregate Expression' class.
*
@@ -2757,7 +2766,7 @@ public interface LogiclanguagePackage extends EPackage {
* @generated
* @ordered
*/
- int AGGREGATE_EXPRESSION_FEATURE_COUNT = TERM_FEATURE_COUNT + 1;
+ int AGGREGATE_EXPRESSION_FEATURE_COUNT = TERM_FEATURE_COUNT + 2;
/**
* The number of operations of the 'Aggregate Expression' class.
@@ -2787,6 +2796,15 @@ public interface LogiclanguagePackage extends EPackage {
*/
int PROJECTED_AGGREGATE_EXPRESSION__RELATION = AGGREGATE_EXPRESSION__RELATION;
+ /**
+ * The feature id for the 'Parameter Substitution' containment reference list.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION = AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
+
/**
* The feature id for the 'Projection Index' attribute.
*
@@ -2833,6 +2851,15 @@ public interface LogiclanguagePackage extends EPackage {
*/
int SUM__RELATION = PROJECTED_AGGREGATE_EXPRESSION__RELATION;
+ /**
+ * The feature id for the 'Parameter Substitution' containment reference list.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int SUM__PARAMETER_SUBSTITUTION = PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
+
/**
* The feature id for the 'Projection Index' attribute.
*
@@ -2879,6 +2906,15 @@ public interface LogiclanguagePackage extends EPackage {
*/
int COUNT__RELATION = AGGREGATE_EXPRESSION__RELATION;
+ /**
+ * The feature id for the 'Parameter Substitution' containment reference list.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int COUNT__PARAMETER_SUBSTITUTION = AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
+
/**
* The number of structural features of the 'Count' class.
*
@@ -2916,6 +2952,15 @@ public interface LogiclanguagePackage extends EPackage {
*/
int MIN__RELATION = PROJECTED_AGGREGATE_EXPRESSION__RELATION;
+ /**
+ * The feature id for the 'Parameter Substitution' containment reference list.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int MIN__PARAMETER_SUBSTITUTION = PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
+
/**
* The feature id for the 'Projection Index' attribute.
*
@@ -2962,6 +3007,15 @@ public interface LogiclanguagePackage extends EPackage {
*/
int MAX__RELATION = PROJECTED_AGGREGATE_EXPRESSION__RELATION;
+ /**
+ * The feature id for the 'Parameter Substitution' containment reference list.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int MAX__PARAMETER_SUBSTITUTION = PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
+
/**
* The feature id for the 'Projection Index' attribute.
*
@@ -2990,6 +3044,44 @@ public interface LogiclanguagePackage extends EPackage {
int MAX_OPERATION_COUNT = PROJECTED_AGGREGATE_EXPRESSION_OPERATION_COUNT + 0;
+ /**
+ * The meta object id for the '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregatedParameterSubstitutionImpl Aggregated Parameter Substitution}' class.
+ *
+ *
+ * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregatedParameterSubstitutionImpl
+ * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.LogiclanguagePackageImpl#getAggregatedParameterSubstitution()
+ * @generated
+ */
+ int AGGREGATED_PARAMETER_SUBSTITUTION = 65;
+
+ /**
+ * The feature id for the 'Variable' reference.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int AGGREGATED_PARAMETER_SUBSTITUTION__VARIABLE = 0;
+
+ /**
+ * The number of structural features of the 'Aggregated Parameter Substitution' class.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int AGGREGATED_PARAMETER_SUBSTITUTION_FEATURE_COUNT = 1;
+
+ /**
+ * The number of operations of the 'Aggregated Parameter Substitution' class.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int AGGREGATED_PARAMETER_SUBSTITUTION_OPERATION_COUNT = 0;
+
+
/**
* Returns the meta object for class '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type Type}'.
*
@@ -4305,6 +4397,17 @@ public interface LogiclanguagePackage extends EPackage {
*/
EReference getAggregateExpression_Relation();
+ /**
+ * Returns the meta object for the containment reference list '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getParameterSubstitution Parameter Substitution}'.
+ *
+ *
+ * @return the meta object for the containment reference list 'Parameter Substitution'.
+ * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getParameterSubstitution()
+ * @see #getAggregateExpression()
+ * @generated
+ */
+ EReference getAggregateExpression_ParameterSubstitution();
+
/**
* Returns the meta object for class '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Sum Sum}'.
*
@@ -4366,6 +4469,27 @@ public interface LogiclanguagePackage extends EPackage {
*/
EAttribute getProjectedAggregateExpression_ProjectionIndex();
+ /**
+ * Returns the meta object for class '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregatedParameterSubstitution Aggregated Parameter Substitution}'.
+ *
+ *
+ * @return the meta object for class 'Aggregated Parameter Substitution'.
+ * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregatedParameterSubstitution
+ * @generated
+ */
+ EClass getAggregatedParameterSubstitution();
+
+ /**
+ * Returns the meta object for the reference '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregatedParameterSubstitution#getVariable Variable}'.
+ *
+ *
+ * @return the meta object for the reference 'Variable'.
+ * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregatedParameterSubstitution#getVariable()
+ * @see #getAggregatedParameterSubstitution()
+ * @generated
+ */
+ EReference getAggregatedParameterSubstitution_Variable();
+
/**
* Returns the factory that creates the instances of the model.
*
@@ -5509,6 +5633,14 @@ public interface LogiclanguagePackage extends EPackage {
*/
EReference AGGREGATE_EXPRESSION__RELATION = eINSTANCE.getAggregateExpression_Relation();
+ /**
+ * The meta object literal for the 'Parameter Substitution' containment reference list feature.
+ *
+ *
+ * @generated
+ */
+ EReference AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION = eINSTANCE.getAggregateExpression_ParameterSubstitution();
+
/**
* The meta object literal for the '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.SumImpl Sum}' class.
*
@@ -5567,6 +5699,24 @@ public interface LogiclanguagePackage extends EPackage {
*/
EAttribute PROJECTED_AGGREGATE_EXPRESSION__PROJECTION_INDEX = eINSTANCE.getProjectedAggregateExpression_ProjectionIndex();
+ /**
+ * The meta object literal for the '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregatedParameterSubstitutionImpl Aggregated Parameter Substitution}' class.
+ *
+ *
+ * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregatedParameterSubstitutionImpl
+ * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.LogiclanguagePackageImpl#getAggregatedParameterSubstitution()
+ * @generated
+ */
+ EClass AGGREGATED_PARAMETER_SUBSTITUTION = eINSTANCE.getAggregatedParameterSubstitution();
+
+ /**
+ * The meta object literal for the 'Variable' reference feature.
+ *
+ *
+ * @generated
+ */
+ EReference AGGREGATED_PARAMETER_SUBSTITUTION__VARIABLE = eINSTANCE.getAggregatedParameterSubstitution_Variable();
+
}
} //LogiclanguagePackage
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 fc1420b0..0459af42 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
@@ -3,15 +3,21 @@
package hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl;
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression;
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregatedParameterSubstitution;
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage;
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation;
+import java.util.Collection;
import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.NotificationChain;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
+import org.eclipse.emf.ecore.util.EObjectContainmentEList;
+import org.eclipse.emf.ecore.util.InternalEList;
/**
*
@@ -22,6 +28,7 @@ import org.eclipse.emf.ecore.impl.ENotificationImpl;
*
*
* - {@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregateExpressionImpl#getRelation Relation}
+ * - {@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregateExpressionImpl#getParameterSubstitution Parameter Substitution}
*
*
* @generated
@@ -37,6 +44,16 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
*/
protected Relation relation;
+ /**
+ * The cached value of the '{@link #getParameterSubstitution() Parameter Substitution}' containment reference list.
+ *
+ *
+ * @see #getParameterSubstitution()
+ * @generated
+ * @ordered
+ */
+ protected EList parameterSubstitution;
+
/**
*
*
@@ -96,6 +113,33 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
eNotify(new ENotificationImpl(this, Notification.SET, LogiclanguagePackage.AGGREGATE_EXPRESSION__RELATION, oldRelation, relation));
}
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public EList getParameterSubstitution() {
+ if (parameterSubstitution == null) {
+ parameterSubstitution = new EObjectContainmentEList(AggregatedParameterSubstitution.class, this, LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION);
+ }
+ return parameterSubstitution;
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
+ switch (featureID) {
+ case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION:
+ return ((InternalEList>)getParameterSubstitution()).basicRemove(otherEnd, msgs);
+ }
+ return super.eInverseRemove(otherEnd, featureID, msgs);
+ }
+
/**
*
*
@@ -107,6 +151,8 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
case LogiclanguagePackage.AGGREGATE_EXPRESSION__RELATION:
if (resolve) return getRelation();
return basicGetRelation();
+ case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION:
+ return getParameterSubstitution();
}
return super.eGet(featureID, resolve, coreType);
}
@@ -116,12 +162,17 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
*
* @generated
*/
+ @SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case LogiclanguagePackage.AGGREGATE_EXPRESSION__RELATION:
setRelation((Relation)newValue);
return;
+ case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION:
+ getParameterSubstitution().clear();
+ getParameterSubstitution().addAll((Collection extends AggregatedParameterSubstitution>)newValue);
+ return;
}
super.eSet(featureID, newValue);
}
@@ -137,6 +188,9 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
case LogiclanguagePackage.AGGREGATE_EXPRESSION__RELATION:
setRelation((Relation)null);
return;
+ case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION:
+ getParameterSubstitution().clear();
+ return;
}
super.eUnset(featureID);
}
@@ -151,6 +205,8 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
switch (featureID) {
case LogiclanguagePackage.AGGREGATE_EXPRESSION__RELATION:
return relation != null;
+ case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION:
+ return parameterSubstitution != null && !parameterSubstitution.isEmpty();
}
return super.eIsSet(featureID);
}
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/AggregatedParameterSubstitutionImpl.java b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/AggregatedParameterSubstitutionImpl.java
new file mode 100644
index 00000000..15af0f21
--- /dev/null
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/AggregatedParameterSubstitutionImpl.java
@@ -0,0 +1,159 @@
+/**
+ */
+package hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl;
+
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregatedParameterSubstitution;
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage;
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable;
+
+import org.eclipse.emf.common.notify.Notification;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.InternalEObject;
+
+import org.eclipse.emf.ecore.impl.ENotificationImpl;
+import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;
+
+/**
+ *
+ * An implementation of the model object 'Aggregated Parameter Substitution'.
+ *
+ *
+ * The following features are implemented:
+ *
+ *
+ * - {@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregatedParameterSubstitutionImpl#getVariable Variable}
+ *
+ *
+ * @generated
+ */
+public class AggregatedParameterSubstitutionImpl extends MinimalEObjectImpl.Container implements AggregatedParameterSubstitution {
+ /**
+ * The cached value of the '{@link #getVariable() Variable}' reference.
+ *
+ *
+ * @see #getVariable()
+ * @generated
+ * @ordered
+ */
+ protected Variable variable;
+
+ /**
+ *
+ *
+ * @generated
+ */
+ protected AggregatedParameterSubstitutionImpl() {
+ super();
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ protected EClass eStaticClass() {
+ return LogiclanguagePackage.Literals.AGGREGATED_PARAMETER_SUBSTITUTION;
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public Variable getVariable() {
+ if (variable != null && variable.eIsProxy()) {
+ InternalEObject oldVariable = (InternalEObject)variable;
+ variable = (Variable)eResolveProxy(oldVariable);
+ if (variable != oldVariable) {
+ if (eNotificationRequired())
+ eNotify(new ENotificationImpl(this, Notification.RESOLVE, LogiclanguagePackage.AGGREGATED_PARAMETER_SUBSTITUTION__VARIABLE, oldVariable, variable));
+ }
+ }
+ return variable;
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ public Variable basicGetVariable() {
+ return variable;
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public void setVariable(Variable newVariable) {
+ Variable oldVariable = variable;
+ variable = newVariable;
+ if (eNotificationRequired())
+ eNotify(new ENotificationImpl(this, Notification.SET, LogiclanguagePackage.AGGREGATED_PARAMETER_SUBSTITUTION__VARIABLE, oldVariable, variable));
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public Object eGet(int featureID, boolean resolve, boolean coreType) {
+ switch (featureID) {
+ case LogiclanguagePackage.AGGREGATED_PARAMETER_SUBSTITUTION__VARIABLE:
+ if (resolve) return getVariable();
+ return basicGetVariable();
+ }
+ return super.eGet(featureID, resolve, coreType);
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public void eSet(int featureID, Object newValue) {
+ switch (featureID) {
+ case LogiclanguagePackage.AGGREGATED_PARAMETER_SUBSTITUTION__VARIABLE:
+ setVariable((Variable)newValue);
+ return;
+ }
+ super.eSet(featureID, newValue);
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public void eUnset(int featureID) {
+ switch (featureID) {
+ case LogiclanguagePackage.AGGREGATED_PARAMETER_SUBSTITUTION__VARIABLE:
+ setVariable((Variable)null);
+ return;
+ }
+ super.eUnset(featureID);
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public boolean eIsSet(int featureID) {
+ switch (featureID) {
+ case LogiclanguagePackage.AGGREGATED_PARAMETER_SUBSTITUTION__VARIABLE:
+ return variable != null;
+ }
+ return super.eIsSet(featureID);
+ }
+
+} //AggregatedParameterSubstitutionImpl
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/LogiclanguageFactoryImpl.java b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/LogiclanguageFactoryImpl.java
index b890b6e0..b8d87d99 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/LogiclanguageFactoryImpl.java
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/impl/LogiclanguageFactoryImpl.java
@@ -104,6 +104,7 @@ public class LogiclanguageFactoryImpl extends EFactoryImpl implements Logiclangu
case LogiclanguagePackage.COUNT: return createCount();
case LogiclanguagePackage.MIN: return createMin();
case LogiclanguagePackage.MAX: return createMax();
+ case LogiclanguagePackage.AGGREGATED_PARAMETER_SUBSTITUTION: return createAggregatedParameterSubstitution();
default:
throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier");
}
@@ -637,6 +638,17 @@ public class LogiclanguageFactoryImpl extends EFactoryImpl implements Logiclangu
return max;
}
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public AggregatedParameterSubstitution createAggregatedParameterSubstitution() {
+ AggregatedParameterSubstitutionImpl aggregatedParameterSubstitution = new AggregatedParameterSubstitutionImpl();
+ return aggregatedParameterSubstitution;
+ }
+
/**
*
*
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 6d370c0f..64ebdde1 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
@@ -3,6 +3,7 @@
package hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl;
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression;
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregatedParameterSubstitution;
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.And;
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Assertion;
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AtomicTerm;
@@ -547,6 +548,13 @@ public class LogiclanguagePackageImpl extends EPackageImpl implements Logiclangu
*/
private EClass projectedAggregateExpressionEClass = null;
+ /**
+ *
+ *
+ * @generated
+ */
+ private EClass aggregatedParameterSubstitutionEClass = null;
+
/**
* Creates an instance of the model Package, registered with
* {@link org.eclipse.emf.ecore.EPackage.Registry EPackage.Registry} by the package
@@ -1868,6 +1876,16 @@ public class LogiclanguagePackageImpl extends EPackageImpl implements Logiclangu
return (EReference)aggregateExpressionEClass.getEStructuralFeatures().get(0);
}
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public EReference getAggregateExpression_ParameterSubstitution() {
+ return (EReference)aggregateExpressionEClass.getEStructuralFeatures().get(1);
+ }
+
/**
*
*
@@ -1928,6 +1946,26 @@ public class LogiclanguagePackageImpl extends EPackageImpl implements Logiclangu
return (EAttribute)projectedAggregateExpressionEClass.getEStructuralFeatures().get(0);
}
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public EClass getAggregatedParameterSubstitution() {
+ return aggregatedParameterSubstitutionEClass;
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public EReference getAggregatedParameterSubstitution_Variable() {
+ return (EReference)aggregatedParameterSubstitutionEClass.getEStructuralFeatures().get(0);
+ }
+
/**
*
*
@@ -2141,6 +2179,7 @@ public class LogiclanguagePackageImpl extends EPackageImpl implements Logiclangu
aggregateExpressionEClass = createEClass(AGGREGATE_EXPRESSION);
createEReference(aggregateExpressionEClass, AGGREGATE_EXPRESSION__RELATION);
+ createEReference(aggregateExpressionEClass, AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION);
sumEClass = createEClass(SUM);
@@ -2152,6 +2191,9 @@ public class LogiclanguagePackageImpl extends EPackageImpl implements Logiclangu
projectedAggregateExpressionEClass = createEClass(PROJECTED_AGGREGATE_EXPRESSION);
createEAttribute(projectedAggregateExpressionEClass, PROJECTED_AGGREGATE_EXPRESSION__PROJECTION_INDEX);
+
+ aggregatedParameterSubstitutionEClass = createEClass(AGGREGATED_PARAMETER_SUBSTITUTION);
+ createEReference(aggregatedParameterSubstitutionEClass, AGGREGATED_PARAMETER_SUBSTITUTION__VARIABLE);
}
/**
@@ -2433,6 +2475,7 @@ public class LogiclanguagePackageImpl extends EPackageImpl implements Logiclangu
initEClass(aggregateExpressionEClass, AggregateExpression.class, "AggregateExpression", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
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);
+ 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);
initEClass(sumEClass, Sum.class, "Sum", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
@@ -2445,6 +2488,9 @@ public class LogiclanguagePackageImpl extends EPackageImpl implements Logiclangu
initEClass(projectedAggregateExpressionEClass, ProjectedAggregateExpression.class, "ProjectedAggregateExpression", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEAttribute(getProjectedAggregateExpression_ProjectionIndex(), ecorePackage.getEInt(), "projectionIndex", "-1", 1, 1, ProjectedAggregateExpression.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
+ initEClass(aggregatedParameterSubstitutionEClass, AggregatedParameterSubstitution.class, "AggregatedParameterSubstitution", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
+ initEReference(getAggregatedParameterSubstitution_Variable(), this.getVariable(), null, "variable", null, 0, 1, AggregatedParameterSubstitution.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
+
// Create resource
createResource(eNS_URI);
}
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/util/LogiclanguageAdapterFactory.java b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/util/LogiclanguageAdapterFactory.java
index 25edee70..3fc7c298 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/util/LogiclanguageAdapterFactory.java
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/util/LogiclanguageAdapterFactory.java
@@ -328,6 +328,10 @@ public class LogiclanguageAdapterFactory extends AdapterFactoryImpl {
return createProjectedAggregateExpressionAdapter();
}
@Override
+ public Adapter caseAggregatedParameterSubstitution(AggregatedParameterSubstitution object) {
+ return createAggregatedParameterSubstitutionAdapter();
+ }
+ @Override
public Adapter defaultCase(EObject object) {
return createEObjectAdapter();
}
@@ -1257,6 +1261,20 @@ public class LogiclanguageAdapterFactory extends AdapterFactoryImpl {
return null;
}
+ /**
+ * Creates a new adapter for an object of class '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregatedParameterSubstitution Aggregated Parameter Substitution}'.
+ *
+ * This default implementation returns null so that we can easily ignore cases;
+ * it's useful to ignore a case when inheritance will catch all the cases anyway.
+ *
+ * @return the new adapter.
+ * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregatedParameterSubstitution
+ * @generated
+ */
+ public Adapter createAggregatedParameterSubstitutionAdapter() {
+ return null;
+ }
+
/**
* Creates a new adapter for the default case.
*
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/util/LogiclanguageSwitch.java b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/util/LogiclanguageSwitch.java
index fc443484..ac821567 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/util/LogiclanguageSwitch.java
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner/logic/model/logiclanguage/util/LogiclanguageSwitch.java
@@ -617,6 +617,12 @@ public class LogiclanguageSwitch extends Switch {
if (result == null) result = defaultCase(theEObject);
return result;
}
+ case LogiclanguagePackage.AGGREGATED_PARAMETER_SUBSTITUTION: {
+ AggregatedParameterSubstitution aggregatedParameterSubstitution = (AggregatedParameterSubstitution)theEObject;
+ T result = caseAggregatedParameterSubstitution(aggregatedParameterSubstitution);
+ if (result == null) result = defaultCase(theEObject);
+ return result;
+ }
default: return defaultCase(theEObject);
}
}
@@ -1596,6 +1602,21 @@ public class LogiclanguageSwitch extends Switch {
return null;
}
+ /**
+ * Returns the result of interpreting the object as an instance of 'Aggregated Parameter Substitution'.
+ *
+ * This implementation returns null;
+ * returning a non-null result will terminate the switch.
+ *
+ * @param object the target of the switch.
+ * @return the result of interpreting the object as an instance of 'Aggregated Parameter Substitution'.
+ * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject)
+ * @generated
+ */
+ public T caseAggregatedParameterSubstitution(AggregatedParameterSubstitution object) {
+ return null;
+ }
+
/**
* Returns the result of interpreting the object as an instance of 'EObject'.
*
--
cgit v1.2.3-70-g09d2
From 539618ccaedfe05d5d62971c8fd0578f5ff3d040 Mon Sep 17 00:00:00 2001
From: Oszkar Semerath
Date: Mon, 15 Jul 2019 17:31:00 +0200
Subject: parsing count, min, max, check and eval v1
---
.../model/logiclanguage/AggregateExpression.java | 23 ++
.../model/logiclanguage/LogiclanguagePackage.java | 75 +++-
.../impl/AggregateExpressionImpl.java | 63 ++++
.../impl/LogiclanguagePackageImpl.java | 12 +
.../model/logiclanguage.aird | 34 +-
.../model/logiclanguage.ecore | 1 +
.../model/logiclanguage.genmodel | 1 +
.../logic/model/builder/LogicProblemBuilder.xtend | 40 ++-
.../META-INF/MANIFEST.MF | 3 +-
.../viatra2logic/Constraint2Logic.xtend | 69 ++++
.../viatra2logic/ExpressionEvaluation2Logic.xtend | 132 +++++++
.../dslreasoner/viatra2logic/Viatra2Logic.xtend | 328 ++++-------------
.../viatra2logic/Viatra2LogicTypeInferer.xtend | 392 +++++++++++++++++++++
.../viatra2logic/Viatra2LogicTypeResult.xtend | 47 +++
.../viatra2logic/XExpressionExtractor.xtend | 24 ++
15 files changed, 961 insertions(+), 283 deletions(-)
create mode 100644 Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/ExpressionEvaluation2Logic.xtend
create mode 100644 Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2LogicTypeInferer.xtend
create mode 100644 Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Viatra2LogicTypeResult.xtend
create mode 100644 Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/XExpressionExtractor.xtend
(limited to 'Framework/hu.bme.mit.inf.dslreasoner.logic.model/ecore-gen/hu/bme/mit/inf/dslreasoner')
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;
*
* - {@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getRelation Relation}
* - {@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getParameterSubstitution Parameter Substitution}
+ * - {@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getResultVariable Result Variable}
*
*
* @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage#getAggregateExpression()
@@ -61,4 +62,26 @@ public interface AggregateExpression extends Term {
*/
EList getParameterSubstitution();
+ /**
+ * Returns the value of the 'Result Variable' reference.
+ *
+ *
+ * @return the value of the 'Result Variable' reference.
+ * @see #setResultVariable(Variable)
+ * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage#getAggregateExpression_ResultVariable()
+ * @model
+ * @generated
+ */
+ Variable getResultVariable();
+
+ /**
+ * Sets the value of the '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getResultVariable Result Variable}' reference.
+ *
+ *
+ * @param value the new value of the 'Result Variable' reference.
+ * @see #getResultVariable()
+ * @generated
+ */
+ void setResultVariable(Variable value);
+
} // 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
@@ -2759,6 +2759,15 @@ public interface LogiclanguagePackage extends EPackage {
*/
int AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION = TERM_FEATURE_COUNT + 1;
+ /**
+ * The feature id for the 'Result Variable' reference.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int AGGREGATE_EXPRESSION__RESULT_VARIABLE = TERM_FEATURE_COUNT + 2;
+
/**
* The number of structural features of the 'Aggregate Expression' class.
*
@@ -2766,7 +2775,7 @@ public interface LogiclanguagePackage extends EPackage {
* @generated
* @ordered
*/
- int AGGREGATE_EXPRESSION_FEATURE_COUNT = TERM_FEATURE_COUNT + 2;
+ int AGGREGATE_EXPRESSION_FEATURE_COUNT = TERM_FEATURE_COUNT + 3;
/**
* The number of operations of the 'Aggregate Expression' class.
@@ -2805,6 +2814,15 @@ public interface LogiclanguagePackage extends EPackage {
*/
int PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION = AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
+ /**
+ * The feature id for the 'Result Variable' reference.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int PROJECTED_AGGREGATE_EXPRESSION__RESULT_VARIABLE = AGGREGATE_EXPRESSION__RESULT_VARIABLE;
+
/**
* The feature id for the 'Projection Index' attribute.
*
@@ -2860,6 +2878,15 @@ public interface LogiclanguagePackage extends EPackage {
*/
int SUM__PARAMETER_SUBSTITUTION = PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
+ /**
+ * The feature id for the 'Result Variable' reference.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int SUM__RESULT_VARIABLE = PROJECTED_AGGREGATE_EXPRESSION__RESULT_VARIABLE;
+
/**
* The feature id for the 'Projection Index' attribute.
*
@@ -2915,6 +2942,15 @@ public interface LogiclanguagePackage extends EPackage {
*/
int COUNT__PARAMETER_SUBSTITUTION = AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
+ /**
+ * The feature id for the 'Result Variable' reference.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int COUNT__RESULT_VARIABLE = AGGREGATE_EXPRESSION__RESULT_VARIABLE;
+
/**
* The number of structural features of the 'Count' class.
*
@@ -2961,6 +2997,15 @@ public interface LogiclanguagePackage extends EPackage {
*/
int MIN__PARAMETER_SUBSTITUTION = PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
+ /**
+ * The feature id for the 'Result Variable' reference.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int MIN__RESULT_VARIABLE = PROJECTED_AGGREGATE_EXPRESSION__RESULT_VARIABLE;
+
/**
* The feature id for the 'Projection Index' attribute.
*
@@ -3016,6 +3061,15 @@ public interface LogiclanguagePackage extends EPackage {
*/
int MAX__PARAMETER_SUBSTITUTION = PROJECTED_AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION;
+ /**
+ * The feature id for the 'Result Variable' reference.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int MAX__RESULT_VARIABLE = PROJECTED_AGGREGATE_EXPRESSION__RESULT_VARIABLE;
+
/**
* The feature id for the 'Projection Index' attribute.
*
@@ -4408,6 +4462,17 @@ public interface LogiclanguagePackage extends EPackage {
*/
EReference getAggregateExpression_ParameterSubstitution();
+ /**
+ * Returns the meta object for the reference '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getResultVariable Result Variable}'.
+ *
+ *
+ * @return the meta object for the reference 'Result Variable'.
+ * @see hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression#getResultVariable()
+ * @see #getAggregateExpression()
+ * @generated
+ */
+ EReference getAggregateExpression_ResultVariable();
+
/**
* Returns the meta object for class '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Sum Sum}'.
*
@@ -5641,6 +5706,14 @@ public interface LogiclanguagePackage extends EPackage {
*/
EReference AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION = eINSTANCE.getAggregateExpression_ParameterSubstitution();
+ /**
+ * The meta object literal for the 'Result Variable' reference feature.
+ *
+ *
+ * @generated
+ */
+ EReference AGGREGATE_EXPRESSION__RESULT_VARIABLE = eINSTANCE.getAggregateExpression_ResultVariable();
+
/**
* The meta object literal for the '{@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.SumImpl Sum}' class.
*
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
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage;
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation;
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable;
import java.util.Collection;
import org.eclipse.emf.common.notify.Notification;
@@ -29,6 +30,7 @@ import org.eclipse.emf.ecore.util.InternalEList;
*
* - {@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregateExpressionImpl#getRelation Relation}
* - {@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregateExpressionImpl#getParameterSubstitution Parameter Substitution}
+ * - {@link hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.AggregateExpressionImpl#getResultVariable Result Variable}
*
*
* @generated
@@ -54,6 +56,16 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
*/
protected EList parameterSubstitution;
+ /**
+ * The cached value of the '{@link #getResultVariable() Result Variable}' reference.
+ *
+ *
+ * @see #getResultVariable()
+ * @generated
+ * @ordered
+ */
+ protected Variable resultVariable;
+
/**
*
*
@@ -126,6 +138,46 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
return parameterSubstitution;
}
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public Variable getResultVariable() {
+ if (resultVariable != null && resultVariable.eIsProxy()) {
+ InternalEObject oldResultVariable = (InternalEObject)resultVariable;
+ resultVariable = (Variable)eResolveProxy(oldResultVariable);
+ if (resultVariable != oldResultVariable) {
+ if (eNotificationRequired())
+ eNotify(new ENotificationImpl(this, Notification.RESOLVE, LogiclanguagePackage.AGGREGATE_EXPRESSION__RESULT_VARIABLE, oldResultVariable, resultVariable));
+ }
+ }
+ return resultVariable;
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ public Variable basicGetResultVariable() {
+ return resultVariable;
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public void setResultVariable(Variable newResultVariable) {
+ Variable oldResultVariable = resultVariable;
+ resultVariable = newResultVariable;
+ if (eNotificationRequired())
+ eNotify(new ENotificationImpl(this, Notification.SET, LogiclanguagePackage.AGGREGATE_EXPRESSION__RESULT_VARIABLE, oldResultVariable, resultVariable));
+ }
+
/**
*
*
@@ -153,6 +205,9 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
return basicGetRelation();
case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION:
return getParameterSubstitution();
+ case LogiclanguagePackage.AGGREGATE_EXPRESSION__RESULT_VARIABLE:
+ if (resolve) return getResultVariable();
+ return basicGetResultVariable();
}
return super.eGet(featureID, resolve, coreType);
}
@@ -173,6 +228,9 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
getParameterSubstitution().clear();
getParameterSubstitution().addAll((Collection extends AggregatedParameterSubstitution>)newValue);
return;
+ case LogiclanguagePackage.AGGREGATE_EXPRESSION__RESULT_VARIABLE:
+ setResultVariable((Variable)newValue);
+ return;
}
super.eSet(featureID, newValue);
}
@@ -191,6 +249,9 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION:
getParameterSubstitution().clear();
return;
+ case LogiclanguagePackage.AGGREGATE_EXPRESSION__RESULT_VARIABLE:
+ setResultVariable((Variable)null);
+ return;
}
super.eUnset(featureID);
}
@@ -207,6 +268,8 @@ public abstract class AggregateExpressionImpl extends TermImpl implements Aggreg
return relation != null;
case LogiclanguagePackage.AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION:
return parameterSubstitution != null && !parameterSubstitution.isEmpty();
+ case LogiclanguagePackage.AGGREGATE_EXPRESSION__RESULT_VARIABLE:
+ return resultVariable != null;
}
return super.eIsSet(featureID);
}
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
@@ -1886,6 +1886,16 @@ public class LogiclanguagePackageImpl extends EPackageImpl implements Logiclangu
return (EReference)aggregateExpressionEClass.getEStructuralFeatures().get(1);
}
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public EReference getAggregateExpression_ResultVariable() {
+ return (EReference)aggregateExpressionEClass.getEStructuralFeatures().get(2);
+ }
+
/**
*
*
@@ -2180,6 +2190,7 @@ public class LogiclanguagePackageImpl extends EPackageImpl implements Logiclangu
aggregateExpressionEClass = createEClass(AGGREGATE_EXPRESSION);
createEReference(aggregateExpressionEClass, AGGREGATE_EXPRESSION__RELATION);
createEReference(aggregateExpressionEClass, AGGREGATE_EXPRESSION__PARAMETER_SUBSTITUTION);
+ createEReference(aggregateExpressionEClass, AGGREGATE_EXPRESSION__RESULT_VARIABLE);
sumEClass = createEClass(SUM);
@@ -2476,6 +2487,7 @@ public class LogiclanguagePackageImpl extends EPackageImpl implements Logiclangu
initEClass(aggregateExpressionEClass, AggregateExpression.class, "AggregateExpression", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
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);
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);
+ 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);
initEClass(sumEClass, Sum.class, "Sum", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -9240,7 +9256,7 @@
-
+
KEEP_LOCATION
@@ -10514,7 +10530,7 @@
-
+
KEEP_LOCATION
@@ -10714,6 +10730,20 @@
+
+
+
+
+
+
+ labelSize
+
+
+ labelSize
+
+
+
+
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 @@
+
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 @@
+
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{
def %(TermDescription left, TermDescription right) { Modulo(left,right) }
def Modulo(TermDescription left, TermDescription right) { createMod => [leftOperand = left.toTerm rightOperand = right.toTerm]}
+ def Pow(TermDescription left, TermDescription right) {createPow => [leftOperand = left.toTerm rightOperand = right.toTerm]}
def asTerm(boolean value) { createBoolLiteral => [x|x.value = value] }
def asTerm(int value) { createIntLiteral => [x|x.value = value] }
def asTerm(double value) { BigDecimal.valueOf(value).asTerm }
@@ -530,27 +531,28 @@ class LogicProblemBuilder{
// AggregatedExpression
- private def configureAggregateExpression(T expression, Relation referred, List terms) {
+ private def configureAggregateExpression(T expression, Relation referred, List terms, Variable target) {
if(terms.size != referred.parameters.size) {
throw new LogicProblemBuilderException(
'''The function called has «referred.parameters.size» parameters but it is called with «terms.size»!''')
} else {
expression.relation = referred
+ expression.resultVariable = target
for(var i=0; i [it.variable = target]
+ val targetRelation = terms.get(i)
+ val substitution = createAggregatedParameterSubstitution => [it.variable = targetRelation]
expression.parameterSubstitution += substitution
}
return expression
}
}
- private def configureProjectedAggregateExpression(T expression, Relation referred, List terms, int projection) {
+ private def configureProjectedAggregateExpression(T expression, Relation referred, List terms, Variable target, int projection) {
if(projection < 0 || projection >= referred.parameters.size) {
throw new LogicProblemBuilderException(
'''The function called has «referred.parameters.size» parameters but it is called with «terms.size»!''')
} else {
- val res = expression.configureAggregateExpression(referred, terms)
- if(res.parameterSubstitution.get(projection) !== null) {
+ val res = expression.configureAggregateExpression(referred, terms,target)
+ if(res.parameterSubstitution.get(projection).variable !== null) {
throw new LogicProblemBuilderException(
'''Projection over set variable!''')
}
@@ -564,10 +566,18 @@ class LogicProblemBuilder{
}
}
- def Count(Relation referred, List terms) { createCount.configureAggregateExpression(referred,terms) }
- def Sum(Relation referred, List terms, int projection) { createSum.configureProjectedAggregateExpression(referred,terms,projection) }
- def Min(Relation referred, List terms, int projection) { createMin.configureProjectedAggregateExpression(referred,terms,projection) }
- def Max(Relation referred, List terms, int projection) { createMax.configureProjectedAggregateExpression(referred,terms,projection) }
+ def Count(Relation referred, List terms, Variable result) {
+ createCount.configureAggregateExpression(referred,terms,result)
+ }
+ def Sum(Relation referred, List terms, int projection, Variable result) {
+ createSum.configureProjectedAggregateExpression(referred,terms,result,projection)
+ }
+ def Min(Relation referred, List terms, int projection, Variable result) {
+ createMin.configureProjectedAggregateExpression(referred,terms,result,projection)
+ }
+ def Max(Relation referred, List terms, int projection, Variable result) {
+ createMax.configureProjectedAggregateExpression(referred,terms,result,projection)
+ }
// Function calls
def call(Function function, TermDescription... substitutions) {
@@ -592,17 +602,19 @@ class LogicProblemBuilder{
def call(Relation relation, TermDescription... substitution) { relation.call(substitution as Iterable extends TermDescription>)}
def call(Relation relation, Iterable extends TermDescription> substitution) {
val relationReference = createSymbolicValue
+ if(relation === null) {
+ throw new LogicProblemBuilderException('''Call is referring to null!''')
+ }
relationReference.symbolicReference = relation
- //println('''«relation.name»(«substitution.size»->«relation.parameters»)''')
for(value : substitution)
relationReference.parameterSubstitutions += value.toTerm
relationReference.checkRelationCall(relation)
return relationReference
}
def private checkRelationCall(SymbolicValue value, Relation referredRelation) {
-// if(value === null || referredRelation === null) {
-// println("gebasz")
-// }
+ if(value === null || referredRelation === null) {
+ throw new LogicProblemBuilderException('''Call is referring to null!''')
+ }
if(value.parameterSubstitutions.size != referredRelation.parameters.size) {
throw new LogicProblemBuilderException(
'''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,
hu.bme.mit.inf.dslreasoner.logic.model;bundle-version="1.0.0";visibility:=reexport,
org.eclipse.viatra.query.runtime.base.itc;bundle-version="1.5.0",
org.eclipse.viatra.query.patternlanguage.emf;bundle-version="2.0.0",
- org.eclipse.xtext
+ org.eclipse.xtext,
+ org.eclipse.xtext.xbase;bundle-version="2.18.0"
Bundle-ActivationPolicy: lazy
Export-Package: hu.bme.mit.inf.dslreasoner.viatra2logic,
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
import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint
+import org.eclipse.viatra.query.runtime.matchers.aggregators.DoubleSumOperator
+import org.eclipse.viatra.query.runtime.matchers.aggregators.IntegerSumOperator
+import org.eclipse.viatra.query.runtime.matchers.aggregators.LongSumOperator
+import org.eclipse.viatra.query.runtime.matchers.aggregators.ExtremumOperator
+import org.eclipse.viatra.query.runtime.matchers.aggregators.ExtremumOperator.Extreme
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation
class Constraint2Logic {
val extension LogicProblemBuilder builder = new LogicProblemBuilder
val Ecore2Logic ecore2Logic
+ val ExpressionEvaluation2Logic expressionEvaliation2Logic = new ExpressionEvaluation2Logic
+ val expressionExtractor = new XExpressionExtractor
new(Ecore2Logic ecore2Logic) {
this.ecore2Logic = ecore2Logic
@@ -269,6 +279,65 @@ class Constraint2Logic {
} else throw new IllegalArgumentException('''unknown tuple: «tuple»''')
}
+ def dispatch Term transformConstraint(AggregatorConstraint constraint,
+ TracedOutput ecore2LogicTrace,
+ Viatra2LogicTrace viatra2LogicTrace,
+ Map variable2Variable,
+ Viatra2LogicConfiguration config)
+ {
+ val logicReferred = constraint.referredQuery.lookup(viatra2LogicTrace.query2Relation)
+ val parameterSubstitution = new LinkedList
+ for(index : 0.. ecore2LogicTrace,
+ Viatra2LogicTrace viatra2LogicTrace,
+ Map variable2Variable,
+ Viatra2LogicConfiguration config)
+ {
+ val logicReferred = constraint.referredQuery.lookup(viatra2LogicTrace.query2Relation)
+ val parameterSubstitution = new LinkedList
+ for(index : 0.. ecore2LogicTrace,
+ Viatra2LogicTrace viatra2LogicTrace,
+ Map variable2Variable,
+ Viatra2LogicConfiguration config)
+ {
+ val outputVariable = constraint.outputVariable
+ val expression = expressionExtractor.extractExpression(constraint.evaluator)
+ return expressionEvaliation2Logic.transformEval(outputVariable,expression,variable2Variable)
+ }
+
def dispatch Term transformConstraint(PConstraint constraint,
TracedOutput ecore2LogicTrace,
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 @@
+package hu.bme.mit.inf.dslreasoner.viatra2logic
+
+import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Term
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable
+import java.util.Map
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable
+import org.eclipse.xtext.xbase.XBinaryOperation
+import org.eclipse.xtext.xbase.XExpression
+import org.eclipse.xtext.xbase.XFeatureCall
+import org.eclipse.xtext.xbase.XMemberFeatureCall
+import org.eclipse.xtext.xbase.XNumberLiteral
+import org.eclipse.xtext.xbase.XUnaryOperation
+
+import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
+
+class ExpressionEvaluation2Logic {
+ val extension LogicProblemBuilder builder = new LogicProblemBuilder
+
+ def Term transformCheck(XExpression expression, Map variable2Variable) {
+ return expression.transform(variable2Variable)
+ }
+ def Term transformEval(PVariable target, XExpression expression, Map variable2Variable) {
+ return target.lookup(variable2Variable) == expression.transform(variable2Variable)
+ }
+
+ static val N_Base = "org.eclipse.xtext.xbase.lib."
+
+ static val N_PLUS1 = "operator_plus"
+ static val N_MINUS1 = "operator_minus"
+
+ static val N_MINUS2 = "operator_minus"
+ static val N_PLUS2 = "operator_plus"
+ static val N_POWER = "operator_power"
+ static val N_MULTIPLY = "operator_multiply"
+ static val N_DIVIDE = "operator_divide"
+ static val N_MODULO = "operator_modulo"
+ static val N_LESSTHAN = "operator_lessThan"
+ static val N_LESSEQUALSTHAN = "operator_lessEqualsThan"
+ static val N_GREATERTHAN = "operator_greaterThan"
+ static val N_GREATEREQUALTHAN = "operator_greaterEqualsThan"
+ static val N_EQUALS = "operator_equals"
+ static val N_NOTEQUALS = "operator_notEquals"
+ static val N_EQUALS3 = "operator_tripleEquals"
+ static val N_NOTEQUALS3 = "operator_tripleNotEquals"
+
+
+
+ protected def isN(String name, String s) {
+ val res = name.startsWith(N_Base) && name.endsWith(s)
+ //println('''[«res»] «name» ?= «N_Base»*«s»''')
+ return res
+ }
+
+ static val N_POWER2 = "java.lang.Math.pow"
+
+ def protected dispatch Term transform(XBinaryOperation e, Map variable2Variable) {
+ val left = e.leftOperand.transform(variable2Variable)
+ val right = e.rightOperand.transform(variable2Variable)
+ val feature = e.feature.qualifiedName
+ if(feature.isN(N_MINUS2)) { return Minus(left,right) }
+ else if(feature.isN(N_PLUS2)) { return Plus(left,right) }
+ else if(feature.isN(N_POWER)) { return Pow(left,right) }
+ else if(feature.isN(N_MULTIPLY)) { return Multiply(left,right) }
+ else if(feature.isN(N_DIVIDE)) { return Divide(left,right) }
+ else if(feature.isN(N_MODULO)) { return Modulo(left,right) }
+ else if(feature.isN(N_LESSTHAN)) { return LessThan(left,right) }
+ else if(feature.isN(N_LESSEQUALSTHAN)) { return LessOrEqual(left,right) }
+ else if(feature.isN(N_GREATERTHAN)) { return MoreThan(left,right) }
+ else if(feature.isN(N_GREATEREQUALTHAN)) { return MoreOrEqual(left,right) }
+ else if(feature.isN(N_EQUALS)) { return Equals(left,right) }
+ else if(feature.isN(N_NOTEQUALS)) { return Distinct(left,right) }
+ else if(feature.isN(N_EQUALS3)) { return Equals(left,right) }
+ else if(feature.isN(N_NOTEQUALS3)) { return Distinct(left,right) }
+ else {
+ println("-> " + e.feature+","+e.class)
+ println("-> " + e.leftOperand)
+ println("-> " + e.rightOperand)
+ println("-> " + e.feature.qualifiedName)
+ throw new UnsupportedOperationException('''Unsupported binary operator feature: "«e.feature.class.simpleName»" - «e»''')
+ }
+ }
+
+ def protected dispatch Term transform(XUnaryOperation e, Map variable2Variable) {
+ val operand = e.operand.transform(variable2Variable)
+ val feature = e.feature.qualifiedName
+ if(feature.isN(N_MINUS1)) { return Minus(0.asTerm,operand)}
+ else if(feature.isN(N_PLUS1)) { return operand}
+ else{
+ println("-> " + e.feature+","+e.class)
+ println("-> " + e.operand)
+ println("-> " + e.feature.qualifiedName)
+ throw new UnsupportedOperationException('''Unsupported unary operator feature: "«e.feature.class.simpleName»" - «e»''')
+ }
+ }
+
+ def protected dispatch Term transform(XMemberFeatureCall e, Map variable2Variable) {
+ val transformedArguments = e.actualArguments.map[transform(variable2Variable)]
+ val feature = e.feature.qualifiedName
+ if(feature == N_POWER2) {
+ return Pow(transformedArguments.get(0),transformedArguments.get(1))
+ }else {
+ println(e.feature+","+e.class)
+ println(e.actualArguments.join(", "))
+ println(e.feature.qualifiedName)
+ throw new UnsupportedOperationException('''Unsupported feature call: "«e.feature.qualifiedName»" - «e»''')
+ }
+ }
+
+ def protected dispatch Term transform(XFeatureCall e, Map variable2Variable) {
+ val featureName = e.feature.qualifiedName
+ val entryWithName = variable2Variable.entrySet.filter[it.key.name == featureName].head
+ if(entryWithName !== null) {
+ return entryWithName.value.toTerm
+ } else {
+ throw new IllegalArgumentException('''Feature call reference to unavailable variable "«featureName»"''')
+ }
+ }
+
+ def protected dispatch Term transform(XNumberLiteral l, Map variable2Variable) {
+ val s = l.value
+ try{ return Integer.parseInt(s).asTerm } catch(NumberFormatException e){}
+ try{ return Short.parseShort(s).asTerm } catch(NumberFormatException e){}
+ try{ return Double.parseDouble(s).asTerm } catch(NumberFormatException e){}
+ try{ return Float.parseFloat(s).asTerm } catch(NumberFormatException e){}
+ throw new UnsupportedOperationException('''Unsupported numeric type: "«s»"''')
+ }
+
+ def protected dispatch Term transform(XExpression e, Map variable2Variable) {
+ throw new UnsupportedOperationException('''Unsupported expression: "«e.class.simpleName»" - «e»''')
+ }
+}
\ 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
import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace
import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder
import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput
-import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ComplexTypeReference
-import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.PrimitiveTypeReference
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDefinition
-import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type
-import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeReference
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable
import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.TransfomedViatraQuery
import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.Viatra2LogicAnnotationsFactory
import java.util.ArrayList
import java.util.HashMap
-import java.util.HashSet
import java.util.LinkedList
import java.util.List
import java.util.Map
import java.util.Set
import org.eclipse.emf.ecore.EAttribute
-import org.eclipse.emf.ecore.EClassifier
-import org.eclipse.emf.ecore.EEnum
import org.eclipse.emf.ecore.EReference
import org.eclipse.emf.ecore.EStructuralFeature
-import org.eclipse.emf.ecore.EcorePackage
+import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.viatra.query.runtime.api.IQuerySpecification
import org.eclipse.viatra.query.runtime.emf.EMFQueryMetaContext
-import org.eclipse.viatra.query.runtime.emf.types.BaseEMFTypeKey
-import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey
-import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey
-import org.eclipse.viatra.query.runtime.matchers.context.IInputKey
-import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey
-import org.eclipse.viatra.query.runtime.matchers.planning.helpers.TypeHelper
import org.eclipse.viatra.query.runtime.matchers.psystem.PBody
+import org.eclipse.viatra.query.runtime.matchers.psystem.PConstraint
import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint
import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PDisjunction
import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter
import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery
import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PBodyNormalizer
import org.eclipse.xtend.lib.annotations.Data
import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
-import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PDisjunction
-import org.eclipse.emf.ecore.util.EcoreUtil
-import org.eclipse.viatra.query.runtime.emf.types.EClassUnscopedTransitiveInstancesKey
@Data class ViatraQuerySetDescriptor {
val List extends IQuerySpecification>> patterns
@@ -57,24 +45,24 @@ class Viatra2LogicTrace {
public val Map query2Relation = new HashMap
public val Map query2Annotation = new HashMap
public val Map, Variable> parameter2Variable = new HashMap
- //public val Map variable2Variable = new HashMap
}
class Viatra2LogicConfiguration {
public var normalize = true
- public var transitiveClosureDepth = 3
}
class Viatra2Logic {
val extension LogicProblemBuilder builder = new LogicProblemBuilder
val extension Viatra2LogicAnnotationsFactory factory = Viatra2LogicAnnotationsFactory.eINSTANCE
val normalizer = new PBodyNormalizer(EMFQueryMetaContext.DEFAULT)
+ val Viatra2LogicTypeInferer typeInferer
val Ecore2Logic ecore2Logic
Constraint2Logic constraint2Logic
new(Ecore2Logic ecore2Logic) {
this.ecore2Logic = ecore2Logic
- constraint2Logic = new Constraint2Logic(ecore2Logic)
+ this.typeInferer = new Viatra2LogicTypeInferer(ecore2Logic)
+ this.constraint2Logic = new Constraint2Logic(ecore2Logic)
}
def TracedOutput transformQueries(
@@ -82,65 +70,55 @@ class Viatra2Logic {
TracedOutput ecore2LogicTrace,
Viatra2LogicConfiguration config)
{
+ // Create trace
val viatra2LogicTrace = new Viatra2LogicTrace
- val typeAlanysis = new HashMap
+
+ // Translation works on PQueries. QuerySpecification -> PQuery.
val pQueries = queries.patterns.map[it.internalQueryRepresentation]
- for(query: pQueries) {
- val disjunction = normalizer.rewrite(query)
+ // If requested, the queries are normalized
+ for(query: pQueries) {
+ val disjunction = normalizer.rewrite(query)
viatra2LogicTrace.query2Disjunction.put(query,disjunction)
}
- for(query: pQueries) {
- val types = query.lookup(viatra2LogicTrace.query2Disjunction).bodies.toInvertedMap[
- TypeHelper::inferUnaryTypesFor(it.uniqueVariables,it.constraints,EMFQueryMetaContext.DEFAULT)
- ]
-// for(m : types.values) {
-// for(n: m.entrySet) {
-// val variable = n.key
-// println(''' - «variable.name»''')
-// for(type : n.value) {
-// println('''«variable.name» - «type»''')
-// }
-// }
-//
-// }
-
- typeAlanysis.put(query,types)
- }
+ // The types are calculated
+ val types = typeInferer.inferTypes(pQueries,ecore2LogicTrace,viatra2LogicTrace)
+ // First, the signature of the queries are translated, ...
for(query: pQueries) {
try {
- this.transformQueryHeader(query,query.lookup(typeAlanysis),ecore2LogicTrace,viatra2LogicTrace,config)
+ this.transformQueryHeader(query,types,ecore2LogicTrace,viatra2LogicTrace,config)
} catch(IllegalArgumentException e) {
throw new IllegalArgumentException('''
Unable to translate query "«query.fullyQualifiedName»".
Reason: «e.class.simpleName», «e.message»''',e)
}
}
+
+ // ...then the bodies, ...
for(query: pQueries) {
try {
- this.transformQuerySpecification(query,query.lookup(typeAlanysis),ecore2LogicTrace,viatra2LogicTrace,config)
+ this.transformQuerySpecification(query,types,ecore2LogicTrace,viatra2LogicTrace,config)
} catch (IllegalArgumentException e){
throw new IllegalArgumentException('''
Unable to translate query "«query.fullyQualifiedName»".
Reason: «e.class.simpleName», «e.message»''',e)
}
}
- /*for(d : viatra2LogicTrace.query2Relation.values) {
- checkDefinition(d)
- }*/
+ // ... and finally, the annotations.
transformQueryConstraints(
queries.validationPatterns.map[internalQueryRepresentation],
queries.derivedFeatures,
ecore2LogicTrace,viatra2LogicTrace)
+
return new TracedOutput(ecore2LogicTrace.output,viatra2LogicTrace)
}
def protected transformQueryHeader(
PQuery pquery,
- Map>> types,
+ Viatra2LogicTypeResult types,
TracedOutput ecore2LogicTrace,
Viatra2LogicTrace viatra2LogicTrace,
Viatra2LogicConfiguration config)
@@ -149,7 +127,7 @@ class Viatra2Logic {
val parameters = new ArrayList(pquery.parameters.size)
for(vParam: pquery.parameters) {
val parameterName = '''parameter «vParam.name»'''
- val parameterType = getType(vParam,types,ecore2LogicTrace)
+ val parameterType = types.getType(pquery,vParam)
if(parameterType === null) {
throw new AssertionError('''null type for parameter «vParam.name» in pattern «pquery.fullyQualifiedName»''')
}
@@ -175,7 +153,7 @@ class Viatra2Logic {
def protected transformQuerySpecification(
PQuery pquery,
- Map>> types,
+ Viatra2LogicTypeResult types,
TracedOutput ecore2LogicTrace,
Viatra2LogicTrace viatra2LogicTrace,
Viatra2LogicConfiguration config)
@@ -233,7 +211,7 @@ class Viatra2Logic {
}
def transformBody(PBody body,
- Map>> types,
+ Viatra2LogicTypeResult types,
TracedOutput ecore2LogicTrace,
Viatra2LogicTrace viatra2LogicTrace,
Viatra2LogicConfiguration config)
@@ -248,19 +226,29 @@ class Viatra2Logic {
// Inner Variables
val innerPositiveVariables = new LinkedList
val innerNegativeVariables = new LinkedList
+ val innerAggreatedVariables = new LinkedList
+ //println(body.uniqueVariables)
for(innerVariable : body.uniqueVariables) {
if(!variable2Variable.containsKey(innerVariable)) {
- val name = '''variable «innerVariable.name.normalizeName»'''
- //println(body.pattern.fullyQualifiedName + "-")
- val logicType = getType(innerVariable,types,ecore2LogicTrace)
- val logicVariable = createVar(name,logicType)
- if(innerVariable.isPositiveVariable) {
- innerPositiveVariables += logicVariable
+ if(innerVariable.aggregateOnly) {
+ // do not create variable
+ innerAggreatedVariables.add(innerVariable)
+ variable2Variable.put(innerVariable,null)
} else {
- innerNegativeVariables += logicVariable
+ val name = '''variable «innerVariable.name.normalizeName»'''
+ val logicType = types.getType(body,innerVariable)
+ if(logicType === null) {
+ throw new IllegalArgumentException('''Variable «innerVariable.name.normalizeName» has no type!''')
+ }
+ val logicVariable = createVar(name,logicType)
+ if(innerVariable.negativeOnly) {
+ innerNegativeVariables += logicVariable
+ } else {
+ innerPositiveVariables += logicVariable
+ }
+ variable2Variable.put(innerVariable,logicVariable)
}
- variable2Variable.put(innerVariable,logicVariable)
}
}
@@ -282,226 +270,36 @@ class Viatra2Logic {
return allVariablesAreExisting
}
-// def toTypeJudgement(PVariable v, IInputKey key) {
-// new TypeJudgement(key,new Tuple1)
-// }
def private normalizeName(String variableName) {
return variableName.replaceAll("[\\W]|_", "")
}
-
- /**
- * Translates the type of a parameter variable in a pattern
- */
- def TypeReference getType(PParameter v, Map>> types, TracedOutput ecore2LogicTrace) {
- // If parameter type is specified then the specified type is used
- if(v.declaredUnaryType !== null) {
- val res = transformTypeReference(v.declaredUnaryType,ecore2LogicTrace)
- if(res === null) {
- throw new AssertionError('''
- Unable to translate declared type «v.declaredUnaryType».
- ''')
- } else {
- return res
- }
- }
- // Otherwise, calculate the type based on the type of the variable in the bodies
- else {
- val bodies = types.keySet
- val typesFromBodies = new ArrayList(bodies.size)
- for(body : bodies) {
- // collect the variable in the body
- val exported = body.symbolicParameters.filter[it.patternParameter === v]
- if(exported.size !== 1) {
- throw new AssertionError('''Parameter «v.name» has no reference in body!''')
- }
- val variable = exported.head.parameterVariable
- typesFromBodies+=variable.getType(types,ecore2LogicTrace)
- }
- return typesFromBodies.calculateCommonSupertype
- }
- }
-
- /**
- * Translates the type of a variable in a pattern body
- */
- def TypeReference getType(PVariable v, Map>> types ,TracedOutput ecore2LogicTrace) {
- if (v.isPositiveVariable) {
- val keys = getTypesFromCollection(v,types)
- val logicTypes = keys.map[transformTypeReference(it,ecore2LogicTrace)].filterNull
- return logicTypes.calculateCommonSubtype
- } else {
- val onlyConstraint = v.referringConstraints.head as NegativePatternCall
- val indexOfVariable = v.lookup(onlyConstraint.actualParametersTuple.invertIndex)
- val parameter = onlyConstraint.referredQuery.parameters.get(indexOfVariable)
- val declaredUnaryType = parameter.declaredUnaryType as BaseEMFTypeKey extends EClassifier>
- if (declaredUnaryType === null) {
- throw new UnsupportedOperationException(
- '''parameter «parameter.name» in pattern «onlyConstraint.referredQuery.fullyQualifiedName» does not have type!''')
- } else
- return declaredUnaryType.transformTypeReference(ecore2LogicTrace)
- }
- }
-
- def getTypesFromCollection(PVariable v, Map>> types) {
- for(entry : types.entrySet) {
- if(entry.key.uniqueVariables.contains(v)) {
- return v.lookup(entry.value)
- }
- }
- throw new IllegalArgumentException('''Variable «v.name» is not present in neither of the bodies!''')
- }
-
- def TypeReference calculateCommonSubtype(Iterable types) {
- val primitiveTypeReferences = types.filter(PrimitiveTypeReference)
- val complexTypeReferences = types.filter(ComplexTypeReference)
- if(complexTypeReferences.isEmpty) {
- val head = primitiveTypeReferences.head
- if(primitiveTypeReferences.exists[it.eClass !== head.eClass]) {
- throw new IllegalArgumentException('''Inconsistent types: «primitiveTypeReferences.map[eClass.name].toSet.toList»''')
- }
- return head
- } else if(primitiveTypeReferences.isEmpty) {
- val complexTypes = complexTypeReferences.map[it.referred].toSet
- if(complexTypes.size === 1) {
- return builder.toTypeReference(complexTypes.head)
- }
- // Collect possible subtypes
- val subtypeSets = complexTypes.map[it.transitiveClosureStar[it.subtypes].toSet]
- val commonTypeSet = new HashSet(subtypeSets.head)
- val otherSets = subtypeSets.tail
- for(otherSet : otherSets) {
- commonTypeSet.retainAll(otherSet)
- }
- if(commonTypeSet.empty) {
- throw new IllegalArgumentException('''Inconsistent types: «complexTypes.map[name].toList»''')
- }
-
- return calculateCommonComplexSupertype(commonTypeSet)
-
- } else {
- throw new IllegalArgumentException('''
- Inconsistent types, mixing primitive and complex types:
- «primitiveTypeReferences.map[eClass.name].toSet.toList»
- and
- «complexTypeReferences.map[it.referred].toSet.map[name].toList»''')
-
- }
- }
- def TypeReference calculateCommonSupertype(Iterable types) {
- val primitiveTypeReferences = types.filter(PrimitiveTypeReference)
- val complexTypeReferences = types.filter(ComplexTypeReference)
- if(complexTypeReferences.isEmpty) {
- val head = primitiveTypeReferences.head
- if(primitiveTypeReferences.exists[it.eClass !== head.eClass]) {
- throw new IllegalArgumentException('''Inconsistent types: «primitiveTypeReferences.map[eClass.name].toSet.toList»''')
- }
- return head
- } else if(primitiveTypeReferences.isEmpty) {
- val complexTypes = complexTypeReferences.map[it.referred].toSet
- return calculateCommonComplexSupertype(complexTypes)
-
- } else {
- throw new IllegalArgumentException('''
- Inconsistent types, mixing primitive and complex types:
- «primitiveTypeReferences.map[eClass.name].toSet.toList»
- and
- «complexTypeReferences.map[it.referred].toSet.map[name].toList»''')
-
- }
- }
- def TypeReference calculateCommonComplexSupertype(Set complexTypes) {
- if(complexTypes.size === 1) {
- return builder.toTypeReference(complexTypes.head)
- }
- // Collect possible supertypes
- val supertypeSets = complexTypes.map[it.transitiveClosureStar[it.supertypes].toSet]
- val commonTypeSet = new HashSet(supertypeSets.head)
- val otherSets = supertypeSets.tail
- for(otherSet : otherSets) {
- commonTypeSet.retainAll(otherSet)
- }
- if(commonTypeSet.empty) {
- throw new IllegalArgumentException('''Inconsistent types: «complexTypes.map[name].toList»''')
- }
- // Remove type that already have covered
- val coveredTypes = commonTypeSet.map[it.supertypes].flatten
- commonTypeSet.removeAll(coveredTypes)
- return builder.toTypeReference(commonTypeSet.head)
- }
-
- /**
- * Transforms a Viatra type reference to a logic type.
- */
- def dispatch TypeReference transformTypeReference(EDataTypeInSlotsKey k,TracedOutput ecore2LogicTrace) {
- val w = k.wrappedKey
- if(w == EcorePackage.Literals.EINT || w == EcorePackage.Literals.ESHORT || w == EcorePackage.Literals.ELONG) {
- return builder.LogicInt
- } else if(w == EcorePackage.Literals.EDOUBLE || w == EcorePackage.Literals.EFLOAT) {
- return builder.LogicReal
- } else if(w == EcorePackage.Literals.EBOOLEAN) {
- return builder.LogicBool
- } else if(w == EcorePackage.Literals.ESTRING) {
- return builder.LogicString
- } else if(w instanceof EEnum) {
- val c = this.ecore2Logic.TypeofEEnum(ecore2LogicTrace.trace,w)
- return builder.toTypeReference(c);
- } else throw new UnsupportedOperationException('''Unknown reference type «w.class.name»''')
- }
- def dispatch TypeReference transformTypeReference(JavaTransitiveInstancesKey k,TracedOutput ecore2LogicTrace) {
- val c = k.wrapperInstanceClass
- if(c == Integer || c == Long || c == Short) {
- return LogicInt
- } else if(c == Float || c == Double) {
- return LogicReal
- } else if(c == Boolean) {
- return LogicBool
- } else if(c == String) {
- return LogicString
- } else if(c.superclass == java.lang.Enum){
- val enums = ecore2Logic.allEnumsInScope(ecore2LogicTrace.trace)
- for(enum : enums) {
- if(c == enum.instanceClass) {
- return builder.toTypeReference(ecore2Logic.TypeofEEnum(ecore2LogicTrace.trace,enum))
- }
+ def isNegativeOnly(PVariable variable) {
+ if(variable.referringConstraints.size == 1) {
+ val PConstraint onlyConstraint = variable.referringConstraints.head
+ if(onlyConstraint instanceof NegativePatternCall) {
+ return true
+ } else {
+ return false
}
- throw new IllegalArgumentException('''Enum type «c.simpleName» is not mapped to logic!''')
- }
- return null
- }
- def dispatch TypeReference transformTypeReference(EClassTransitiveInstancesKey k,TracedOutput ecore2LogicTrace) {
- val c = k.wrappedKey
-
- if(this.ecore2Logic.allClassesInScope(ecore2LogicTrace.trace).toList.contains(c)) {
- return builder.toTypeReference(this.ecore2Logic.TypeofEClass(ecore2LogicTrace.trace,k.wrappedKey))
} else {
- return null
+ return false
}
}
- def dispatch TypeReference transformTypeReference(EClassUnscopedTransitiveInstancesKey k, TracedOutput ecore2LogicTrace) {
- val c = k.wrappedKey
-
- if(this.ecore2Logic.allClassesInScope(ecore2LogicTrace.trace).toList.contains(c)) {
- return builder.toTypeReference(this.ecore2Logic.TypeofEClass(ecore2LogicTrace.trace,k.wrappedKey))
- } else {
- return null
- }
- }
-
- def dispatch TypeReference transformTypeReference(IInputKey k,TracedOutput ecore2LogicTrace) {
- //println(k)
- throw new IllegalArgumentException('''Unsupported type: «k.class.simpleName»''')
- }
- def boolean isPositiveVariable(PVariable v) {
- val constraints = v.referringConstraints
- if(constraints.size == 1) {
- val onlyConstraint = constraints.head
- if(onlyConstraint instanceof NegativePatternCall) {
+ def isAggregateOnly(PVariable variable) {
+ if(variable.referringConstraints.size == 1) {
+ val PConstraint onlyConstraint = variable.referringConstraints.head
+ if(onlyConstraint instanceof AggregatorConstraint) {
+ return true
+ } else if(onlyConstraint instanceof PatternMatchCounter) {
+ return true
+ } else {
return false
}
+ } else {
+ return false
}
- return true
}
}
\ 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 @@
+package hu.bme.mit.inf.dslreasoner.viatra2logic
+
+import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic
+import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace
+import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder
+import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ComplexTypeReference
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntTypeReference
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.PrimitiveTypeReference
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealTypeReference
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeReference
+import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
+import java.util.HashMap
+import java.util.HashSet
+import java.util.List
+import java.util.Set
+import org.eclipse.emf.ecore.EEnum
+import org.eclipse.emf.ecore.EcorePackage
+import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup
+import org.eclipse.viatra.query.patternlanguage.emf.specification.XBaseEvaluator
+import org.eclipse.viatra.query.runtime.emf.EMFQueryMetaContext
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey
+import org.eclipse.viatra.query.runtime.emf.types.EClassUnscopedTransitiveInstancesKey
+import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey
+import org.eclipse.viatra.query.runtime.matchers.context.IInputKey
+import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey
+import org.eclipse.viatra.query.runtime.matchers.planning.helpers.TypeHelper
+import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternCallBasedDeferred
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery
+import org.eclipse.xtext.xbase.XExpression
+import org.eclipse.xtext.xbase.typesystem.IBatchTypeResolver
+import org.eclipse.xtext.xbase.typesystem.references.UnknownTypeReference
+
+import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
+import org.eclipse.xtext.xbase.typesystem.references.InnerTypeReference
+
+class Viatra2LogicTypeInferer{
+ val Ecore2Logic ecore2Logic
+ val extension LogicProblemBuilder builder = new LogicProblemBuilder
+ /**Typeresolver uses the same resolver as EMFPatternLanguageStandaloneSetup.*/
+ val IBatchTypeResolver typeResolver =
+ (new EMFPatternLanguageStandaloneSetup).createInjector.getInstance(IBatchTypeResolver)
+ val expressionExtractor = new XExpressionExtractor
+
+ new(Ecore2Logic ecore2Logic) {
+ this.ecore2Logic = ecore2Logic
+ }
+
+ def Viatra2LogicTypeResult inferTypes(List pQueries, TracedOutput ecore2LogicTrace, Viatra2LogicTrace viatra2LogicTrace) {
+ val Viatra2LogicTypeResult result = new Viatra2LogicTypeResult(new HashMap,new HashMap);
+ for(query : pQueries) {
+ for(body: query.lookup(viatra2LogicTrace.query2Disjunction).bodies) {
+ for(variable : body.uniqueVariables) {
+ getOrMakeTypeDecision(result,variable,body,ecore2LogicTrace,viatra2LogicTrace,emptySet)
+ }
+ }
+ for(parameter: query.parameters) {
+ getOrMakeTypeDecision(result,query,parameter,ecore2LogicTrace,viatra2LogicTrace,emptySet)
+ }
+ }
+ return result
+ }
+
+ private def TypeReference getOrMakeTypeDecision(
+ Viatra2LogicTypeResult result,
+ PVariable variable, PBody body,
+ TracedOutput ecore2LogicTrace,
+ Viatra2LogicTrace viatra2LogicTrace,
+ Set extends PParameter> checkedInDecisionMaking)
+ {
+ if(result.containsSolution(body,variable)) {
+ return result.getType(body,variable)
+ } else {
+ val inferredTypesByViatra = TypeHelper::inferUnaryTypesFor(body.uniqueVariables, body.constraints, EMFQueryMetaContext.DEFAULT)
+ val constraintsForVariable = variable.lookup(inferredTypesByViatra)
+
+ val typeConstraintsDerivedByTypeHelper = constraintsForVariable.map[transformTypeReference(ecore2LogicTrace)]
+ val typesFromEval = variable.getTypesFromEval(typeResolver)
+ val typesFromAggregatorResult = variable.getTypeFromPassivePatternCallConstraintResult(
+ result,
+ ecore2LogicTrace,
+ viatra2LogicTrace,
+ checkedInDecisionMaking)
+
+ val typesFromPositiveReasoning = (typeConstraintsDerivedByTypeHelper + typesFromEval + typesFromAggregatorResult).filterNull
+
+ val types = if(!typesFromPositiveReasoning.empty) {
+ typesFromPositiveReasoning
+ } else {
+ variable.getTypeFromPassivePatternCallConstraints(
+ result,
+ ecore2LogicTrace,
+ viatra2LogicTrace,
+ checkedInDecisionMaking)
+ }
+
+ val commonSubtype = this.calculateCommonSubtype(types)
+
+ result.addType(body,variable,commonSubtype)
+ return commonSubtype
+ }
+ }
+
+ private def TypeReference getOrMakeTypeDecision(
+ Viatra2LogicTypeResult result,
+ PQuery query,
+ PParameter parameter,
+ TracedOutput ecore2LogicTrace,
+ Viatra2LogicTrace viatra2LogicTrace,
+ Set extends PParameter> checkedInDecisionMaking)
+ {
+ if(checkedInDecisionMaking.contains(parameter)) {
+ return null
+ }
+ if(result.containsSolution(parameter)) {
+ return result.getType(query, parameter)
+ }
+
+ var TypeReference typeReference;
+
+ if(parameter.declaredUnaryType !== null) {
+ val key = parameter.declaredUnaryType
+ typeReference = key.transformTypeReference(ecore2LogicTrace)
+ } else {
+ val bodies = query.lookup(viatra2LogicTrace.query2Disjunction).bodies
+ val newChecked = new HashSet(checkedInDecisionMaking) => [add(parameter)]
+ val Iterable variableTypes = bodies.map[body|
+ val symbolicParameter = body.symbolicParameters.filter[patternParameter === parameter].head
+ val variable = symbolicParameter.parameterVariable
+ getOrMakeTypeDecision(result,variable,body,ecore2LogicTrace,viatra2LogicTrace,newChecked)
+ ]
+ typeReference = calculateCommonSupertype(variableTypes)
+ }
+ result.addType(query,parameter,typeReference)
+ return typeReference
+ }
+
+ private def Iterable extends TypeReference> getTypesFromEval(PVariable v, IBatchTypeResolver typeResolver) {
+ val constraints = v.getReferringConstraintsOfType(
+ typeof(ExpressionEvaluation)
+ ).filter[
+ it.outputVariable === v
+ ]
+ val res = constraints.map[getTypeFromEval]
+ return res
+ }
+
+ def TypeReference getTypeFromEval(ExpressionEvaluation evaluation) {
+ val XExpression expression = expressionExtractor.extractExpression(evaluation.evaluator)
+ val returnType = typeResolver.resolveTypes(expression).getReturnType(expression);
+ if(returnType === null || returnType instanceof UnknownTypeReference) {
+ return null
+ } else {
+ val javaIdentifier = returnType.wrapperTypeIfPrimitive.javaIdentifier
+ if(javaIdentifier == Boolean.name) {
+ return LogicBool
+ } else if(javaIdentifier == Integer.name || javaIdentifier == Short.name) {
+ return LogicInt
+ } else if(javaIdentifier == Double.name || javaIdentifier == Float.name){
+ return LogicReal
+ } else if(javaIdentifier == String.name) {
+ return LogicString
+ } else {
+ throw new UnsupportedOperationException('''Unsupported eval type: "«javaIdentifier»"!''')
+ }
+ }
+ }
+
+ private def getTypeFromPassivePatternCallConstraintResult(
+ PVariable v,
+ Viatra2LogicTypeResult result,
+ TracedOutput ecore2LogicTrace,
+ Viatra2LogicTrace viatra2LogicTrace,
+ Set extends PParameter> checkedInDecisionMaking
+ ) {
+ val referringConstraints = v.referringConstraints
+
+ val referringCountMatcherTargeting = referringConstraints
+ .filter(PatternMatchCounter)
+ .filter[it.resultVariable === v]
+ .map[builder.LogicInt]
+ val referringAggregatorConstraintsTargeting = referringConstraints
+ .filter(AggregatorConstraint)
+ .filter[it.resultVariable === v]
+ .map[ // get the type of the referred column
+ getOrMakeTypeDecision(
+ result,
+ it.referredQuery,
+ it.referredQuery.parameters.get(aggregatedColumn),
+ ecore2LogicTrace,
+ viatra2LogicTrace,
+ checkedInDecisionMaking)]
+
+ return referringCountMatcherTargeting + referringAggregatorConstraintsTargeting
+ }
+
+ private def getTypeFromPassivePatternCallConstraints(
+ PVariable v,
+ Viatra2LogicTypeResult result,
+ TracedOutput ecore2LogicTrace,
+ Viatra2LogicTrace viatra2LogicTrace,
+ Set extends PParameter> checkedInDecisionMaking
+ ) {
+ val referringConstraints = v.referringConstraints
+ if(referringConstraints.size === 1) {
+ val onlyConstraint = referringConstraints.head
+
+ if(onlyConstraint instanceof PatternCallBasedDeferred) {
+ val indexOfVariable = v.lookup(onlyConstraint.actualParametersTuple.invertIndex)
+ val parameter = onlyConstraint.referredQuery.parameters.get(indexOfVariable)
+ val res = getOrMakeTypeDecision(result, onlyConstraint.referredQuery, parameter, ecore2LogicTrace,viatra2LogicTrace,checkedInDecisionMaking)
+ return #[res]
+ } else {
+ throw new IllegalArgumentException('''A non-PatternCallBasedDeferred type constraint is referring to the variable "«v.name»"!''')
+ }
+ } else {
+ throw new IllegalArgumentException('''Multiple («referringConstraints.size», «FOR c:referringConstraints SEPARATOR ", "»«c»«ENDFOR») constraints are referring to variable "«v.name»", but no type is inferred!''')
+ }
+ }
+
+ def TypeReference calculateCommonSubtype(Iterable types) {
+ val primitiveTypeReferences = types.filter(PrimitiveTypeReference)
+ val complexTypeReferences = types.filter(ComplexTypeReference)
+ if(complexTypeReferences.isEmpty) {
+ // If there is an int type, ...
+ if(primitiveTypeReferences.exists[it instanceof IntTypeReference]) {
+ // ... and all types are either real or int, then return int!
+ if(primitiveTypeReferences.forall[it instanceof RealTypeReference || it instanceof IntTypeReference]) {
+ return primitiveTypeReferences.filter(IntTypeReference).head
+ }
+ // Otherwise, the types are inconsistent, because they mixing numeric and non-numeric types.
+ else throw new IllegalArgumentException('''Inconsistent types: «primitiveTypeReferences.map[eClass.name].toSet.toList»''')
+ }
+ // If there is no Real, then the types should be homogenious
+ val head = primitiveTypeReferences.head
+ if(primitiveTypeReferences.exists[it.eClass !== head.eClass]) {
+ throw new IllegalArgumentException('''Inconsistent types: «primitiveTypeReferences.map[eClass.name].toSet.toList»''')
+ }
+ return head
+ } else if(primitiveTypeReferences.isEmpty) {
+ val complexTypes = complexTypeReferences.map[it.referred].toSet
+ if(complexTypes.size === 1) {
+ return builder.toTypeReference(complexTypes.head)
+ }
+ // Collect possible subtypes
+ val subtypeSets = complexTypes.map[it.transitiveClosureStar[it.subtypes].toSet]
+ val commonTypeSet = new HashSet(subtypeSets.head)
+ val otherSets = subtypeSets.tail
+ for(otherSet : otherSets) {
+ commonTypeSet.retainAll(otherSet)
+ }
+ if(commonTypeSet.empty) {
+ throw new IllegalArgumentException('''Inconsistent types: «complexTypes.map[name].toList»''')
+ }
+
+
+ return calculateCommonComplexSupertype(commonTypeSet)
+
+ } else {
+ throw new IllegalArgumentException('''
+ Inconsistent types, mixing primitive and complex types:
+ «primitiveTypeReferences.map[eClass.name].toSet.toList»
+ and
+ «complexTypeReferences.map[it.referred].toSet.map[name].toList»''')
+
+ }
+ }
+
+
+ def TypeReference calculateCommonSupertype(Iterable types) {
+ val primitiveTypeReferences = types.filter(PrimitiveTypeReference)
+ val complexTypeReferences = types.filter(ComplexTypeReference)
+ if(complexTypeReferences.isEmpty) {
+ // If there is a real type, ...
+ if(primitiveTypeReferences.exists[it instanceof RealTypeReference]) {
+ // ... and all types are either real or int, then return real!
+ if(primitiveTypeReferences.forall[it instanceof RealTypeReference || it instanceof IntTypeReference]) {
+ return primitiveTypeReferences.filter(RealTypeReference).head
+ }
+ // Otherwise, the types are inconsistent, because they mixing numeric and non-numeric types.
+ else throw new IllegalArgumentException('''Inconsistent types: «primitiveTypeReferences.map[eClass.name].toSet.toList»''')
+ }
+ // If there is no Real, then the types should be homogenious
+ val head = primitiveTypeReferences.head
+ if(primitiveTypeReferences.exists[it.eClass !== head.eClass]) {
+ throw new IllegalArgumentException('''Inconsistent types: «primitiveTypeReferences.map[eClass.name].toSet.toList»''')
+ }
+ return head
+ } else if(primitiveTypeReferences.isEmpty) {
+ val complexTypes = complexTypeReferences.map[it.referred].toSet
+ return calculateCommonComplexSupertype(complexTypes)
+
+ } else {
+ throw new IllegalArgumentException('''
+ Inconsistent types, mixing primitive and complex types:
+ «primitiveTypeReferences.map[eClass.name].toSet.toList»
+ and
+ «complexTypeReferences.map[it.referred].toSet.map[name].toList»''')
+
+ }
+ }
+ def TypeReference calculateCommonComplexSupertype(Set complexTypes) {
+ if(complexTypes.size === 1) {
+ return builder.toTypeReference(complexTypes.head)
+ }
+ // Collect possible supertypes
+ val supertypeSets = complexTypes.map[it.transitiveClosureStar[it.supertypes].toSet]
+ val commonTypeSet = new HashSet(supertypeSets.head)
+ val otherSets = supertypeSets.tail
+ for(otherSet : otherSets) {
+ commonTypeSet.retainAll(otherSet)
+ }
+ if(commonTypeSet.empty) {
+ throw new IllegalArgumentException('''Inconsistent types: «complexTypes.map[name].toList»''')
+ }
+ // Remove type that already have covered
+ val coveredTypes = commonTypeSet.map[it.supertypes].flatten
+ commonTypeSet.removeAll(coveredTypes)
+ return builder.toTypeReference(commonTypeSet.head)
+ }
+
+ /**
+ * Transforms a Viatra type reference to a logic type.
+ */
+ def dispatch TypeReference transformTypeReference(EDataTypeInSlotsKey k,TracedOutput ecore2LogicTrace) {
+ val w = k.wrappedKey
+ if(w == EcorePackage.Literals.EINT || w == EcorePackage.Literals.ESHORT || w == EcorePackage.Literals.ELONG) {
+ return builder.LogicInt
+ } else if(w == EcorePackage.Literals.EDOUBLE || w == EcorePackage.Literals.EFLOAT) {
+ return builder.LogicReal
+ } else if(w == EcorePackage.Literals.EBOOLEAN) {
+ return builder.LogicBool
+ } else if(w == EcorePackage.Literals.ESTRING) {
+ return builder.LogicString
+ } else if(w instanceof EEnum) {
+ val c = this.ecore2Logic.TypeofEEnum(ecore2LogicTrace.trace,w)
+ return builder.toTypeReference(c);
+ } else throw new UnsupportedOperationException('''Unknown reference type «w.class.name»''')
+ }
+ def dispatch TypeReference transformTypeReference(JavaTransitiveInstancesKey k,TracedOutput ecore2LogicTrace) {
+ val c = k.wrapperInstanceClass
+ if(c == Integer || c == Long || c == Short) {
+ return LogicInt
+ } else if(c == Float || c == Double) {
+ return LogicReal
+ } else if(c == Boolean) {
+ return LogicBool
+ } else if(c == String) {
+ return LogicString
+ } else if(c.superclass == Enum){
+ val enums = ecore2Logic.allEnumsInScope(ecore2LogicTrace.trace)
+ for(enum : enums) {
+ if(c == enum.instanceClass) {
+ return builder.toTypeReference(ecore2Logic.TypeofEEnum(ecore2LogicTrace.trace,enum))
+ }
+ }
+ throw new IllegalArgumentException('''Enum type «c.simpleName» is not mapped to logic!''')
+ } else {
+ return null
+ }
+ }
+ def dispatch TypeReference transformTypeReference(EClassTransitiveInstancesKey k,TracedOutput ecore2LogicTrace) {
+ val c = k.wrappedKey
+
+ if(this.ecore2Logic.allClassesInScope(ecore2LogicTrace.trace).toList.contains(c)) {
+ return builder.toTypeReference(this.ecore2Logic.TypeofEClass(ecore2LogicTrace.trace,k.wrappedKey))
+ } else {
+ return null
+ }
+ }
+ def dispatch TypeReference transformTypeReference(EClassUnscopedTransitiveInstancesKey k, TracedOutput ecore2LogicTrace) {
+ val c = k.wrappedKey
+
+ if(this.ecore2Logic.allClassesInScope(ecore2LogicTrace.trace).toList.contains(c)) {
+ return builder.toTypeReference(this.ecore2Logic.TypeofEClass(ecore2LogicTrace.trace,k.wrappedKey))
+ } else {
+ return null
+ }
+ }
+
+ def dispatch TypeReference transformTypeReference(IInputKey k,TracedOutput ecore2LogicTrace) {
+ throw new IllegalArgumentException('''Unsupported type: «k.class.simpleName»''')
+ }
+}
\ 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 @@
+package hu.bme.mit.inf.dslreasoner.viatra2logic
+
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeReference
+import java.util.Map
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery
+import org.eclipse.xtend.lib.annotations.Data
+import org.eclipse.xtext.xbase.lib.Functions.Function0
+import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ComplexTypeReference
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory
+import org.eclipse.emf.ecore.util.EcoreUtil
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.PrimitiveTypeReference
+
+@Data class Viatra2LogicTypeResult{
+ Map,Function0> typesInParameters
+ Map,Function0> typesInBodies;
+
+ def addType(PBody body, PVariable variable, TypeReference typeConstructor) {
+ typesInBodies.put(body->variable,typeConstructor.createTypeConstructor)
+ }
+ def addType(PQuery query, PParameter variable, TypeReference typeConstructor) {
+ typesInParameters.put(query->variable,typeConstructor.createTypeConstructor)
+ }
+ def getType(PBody body, PVariable variable) {
+ return (body->variable).lookup(typesInBodies).apply
+ }
+ def getType(PQuery query, PParameter variable) {
+ return (query->variable).lookup(typesInParameters).apply
+ }
+
+ def containsSolution(PBody body, PVariable variable) {
+ return typesInBodies.containsKey(body->variable)
+ }
+ def containsSolution(PParameter variable) {
+ return typesInParameters.containsKey(variable)
+ }
+
+ def dispatch Function0 createTypeConstructor(ComplexTypeReference ref) {
+ return [LogiclanguageFactory.eINSTANCE.createComplexTypeReference=>[it.referred = ref.referred]]
+ }
+ def dispatch Function0 createTypeConstructor(PrimitiveTypeReference ref) {
+ return [EcoreUtil.copy(ref)]
+ }
+}
\ 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 @@
+package hu.bme.mit.inf.dslreasoner.viatra2logic
+
+import org.eclipse.viatra.query.patternlanguage.emf.specification.XBaseEvaluator
+import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator
+import org.eclipse.xtext.xbase.XExpression
+
+class XExpressionExtractor {
+ def dispatch XExpression extractExpression(XBaseEvaluator evaluator) { evaluator.expression }
+ def dispatch XExpression extractExpression(IExpressionEvaluator evaluator) {
+ val clazz = evaluator.class
+ if(clazz.name == "org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.VariableMappingExpressionEvaluatorWrapper") {
+ val field = clazz.declaredFields.filter[it.name == "wrapped"].head
+ if(field === null) {
+ throw new IllegalArgumentException('''Class «clazz.simpleName» has no field "wrapped"!''')
+ } else {
+ field.setAccessible(true);
+ val wrappedEvaluator = field.get(evaluator) as XBaseEvaluator
+ return wrappedEvaluator.extractExpression
+ }
+ } else {
+ throw new IllegalArgumentException('''Unsupported expression evaluation form: «clazz.simpleName»!''')
+ }
+ }
+}
\ No newline at end of file
--
cgit v1.2.3-70-g09d2