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 ++
.../model/logiclanguage.aird | 103 +++++++-
.../model/logiclanguage.ecore | 5 +
.../model/logiclanguage.genmodel | 4 +
.../logic/model/builder/LogicProblemBuilder.xtend | 261 ++++++++++++---------
14 files changed, 784 insertions(+), 123 deletions(-)
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')
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'.
*
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 5673d66a..0a49e388 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
@@ -7805,7 +7805,7 @@
-
+
@@ -7814,7 +7814,7 @@
-
+
@@ -7823,7 +7823,7 @@
-
+
@@ -7832,7 +7832,7 @@
-
+
@@ -7841,7 +7841,7 @@
-
+
@@ -7854,7 +7854,16 @@
-
+
+
+
+
+
+
+
+
+
+
@@ -9011,17 +9020,17 @@
-
+
-
+
-
+
-
+
@@ -9105,6 +9114,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -9199,7 +9240,7 @@
-
+
KEEP_LOCATION
@@ -10473,7 +10514,7 @@
-
+
KEEP_LOCATION
@@ -10635,6 +10676,44 @@
+
+
+
+ KEEP_LOCATION
+ KEEP_SIZE
+ KEEP_RATIO
+
+
+
+
+
+
+
+
+
+
+ labelSize
+
+
+ labelSize
+
+
+
+
+
+
+
+
+
+
+ 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 fdbc1c27..fb94b598 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
@@ -215,6 +215,8 @@
+
@@ -225,4 +227,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 303080e7..cb14ae5b 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
@@ -168,6 +168,7 @@
+
@@ -176,6 +177,9 @@
+
+
+
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 f6bd9541..09bfbb39 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
@@ -1,5 +1,6 @@
package hu.bme.mit.inf.dslreasoner.logic.model.builder
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.AggregateExpression
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Assertion
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.BoolTypeReference
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ComplexTypeReference
@@ -8,6 +9,7 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Function
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntTypeReference
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ProjectedAggregateExpression
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.QuantifiedExpression
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealTypeReference
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation
@@ -46,16 +48,16 @@ class LogicProblemBuilderException extends Exception {
}
}
-public class LogicProblemBuilder{
+class LogicProblemBuilder{
val protected extension LogiclanguageFactory logicFactiory = LogiclanguageFactory.eINSTANCE
val protected extension LogicproblemFactory problemFactory = LogicproblemFactory.eINSTANCE
val protected advancedConstructs = new LogicProblemBuilder_AdvancedConstructs(this)
- def public createProblem(){ createLogicProblem }
+ def createProblem(){ createLogicProblem }
// Names
def protected String canonize(CharSequence name) {
- if(name == null) return ""
+ if(name === null) return ""
val result = name.toString.split("\\s+");
if(result.size == 1) {
val element = result.get(0);
@@ -82,23 +84,23 @@ public class LogicProblemBuilder{
}
// Type builders
- def public Element(CharSequence elementName) { return createDefinedElement => [x|x.name = elementName.canonize] }
- def public Element() { return createDefinedElement }
- def public TypeDeclaration(CharSequence name, boolean isAbstract) { TypeDeclaration => [x | x.name = name.canonize x.isAbstract = isAbstract] }
- def public TypeDeclaration() { createTypeDeclaration }
- def public TypeDefinition(CharSequence name, boolean isAbstract, DefinedElement... elements) { TypeDefinition(name, isAbstract, elements as Iterable) }
- def public TypeDefinition(CharSequence name, boolean isAbstract, Iterable elements) { createTypeDefinition => [x | x.name = name.canonize x.isAbstract = isAbstract x.elements += elements ] }
-
- def public Supertype(Type subtype, Type supertype) {
+ def Element(CharSequence elementName) { return createDefinedElement => [x|x.name = elementName.canonize] }
+ def Element() { return createDefinedElement }
+ def TypeDeclaration(CharSequence name, boolean isAbstract) { TypeDeclaration => [x | x.name = name.canonize x.isAbstract = isAbstract] }
+ def TypeDeclaration() { createTypeDeclaration }
+ def TypeDefinition(CharSequence name, boolean isAbstract, DefinedElement... elements) { TypeDefinition(name, isAbstract, elements as Iterable) }
+ def TypeDefinition(CharSequence name, boolean isAbstract, Iterable elements) { createTypeDefinition => [x | x.name = name.canonize x.isAbstract = isAbstract x.elements += elements ] }
+
+ def Supertype(Type subtype, Type supertype) {
subtype.supertypes+=supertype
}
- def public SetSupertype(Type subtype, Type supertype, boolean value) {
+ def SetSupertype(Type subtype, Type supertype, boolean value) {
if(value) subtype.supertypes+=supertype
else subtype.subtypes-=supertype
}
// Type add
- def public add(LogicProblem problem, Type type) {
+ def add(LogicProblem problem, Type type) {
problem.nameIfAnonymType(type)
problem.types+=type
if(type instanceof TypeDefinition) {
@@ -118,10 +120,10 @@ public class LogicProblemBuilder{
element.name = typeDefinition.elements.map[it.name].generateUniqueName[i | '''type «i.toString»''']
}
- def public LogicBool() { createBoolTypeReference }
- def public LogicInt() { createIntTypeReference }
- def public LogicReal() { createRealTypeReference }
- def public LogicString() { createStringTypeReference }
+ def LogicBool() { createBoolTypeReference }
+ def LogicInt() { createIntTypeReference }
+ def LogicReal() { createRealTypeReference }
+ def LogicString() { createStringTypeReference }
def toTypeReference(TypeDescriptor descriptor) {
if(descriptor instanceof TypeReference) { return EcoreUtil.copy(descriptor); }
else if(descriptor instanceof Type) { return createComplexTypeReference => [referred = descriptor]}
@@ -129,31 +131,31 @@ public class LogicProblemBuilder{
}
// Variables
- def public createVar(CharSequence name, TypeDescriptor range) {
+ def createVar(CharSequence name, TypeDescriptor range) {
return createVariable => [it.name = name.canonize it.range = range.toTypeReference]
}
// Functions
- def public FunctionDescription ->(TypeDescriptor parameter, TypeDescriptor range) { return #[parameter] -> range }
- def public FunctionDescription ->(Iterable extends TypeDescriptor> parameters, TypeDescriptor range) { return new FunctionDescription(parameters.map[toTypeReference], range.toTypeReference); }
- def public FunctionDeclaration(CharSequence name, FunctionDescription functionDescription) { FunctionDeclaration(name,functionDescription.range, functionDescription.parameters) }
- def public FunctionDeclaration(FunctionDescription functionDescription) { FunctionDeclaration(functionDescription.range, functionDescription.parameters) }
- def public FunctionDeclaration(CharSequence name, TypeDescriptor range, TypeDescriptor... parameters) { FunctionDeclaration(name, range, parameters as Iterable extends TypeReference>) }
- def public FunctionDeclaration(TypeDescriptor range, TypeDescriptor... parameters) { FunctionDeclaration(range, parameters as Iterable extends TypeReference>) }
- def public FunctionDeclaration(CharSequence name, TypeDescriptor range, Iterable extends TypeDescriptor> parameters) { return FunctionDeclaration(range,parameters) => [x|x.name = name.canonize] }
- def public FunctionDeclaration(TypeDescriptor range, Iterable extends TypeDescriptor> parameters) {
+ def FunctionDescription ->(TypeDescriptor parameter, TypeDescriptor range) { return #[parameter] -> range }
+ def FunctionDescription ->(Iterable extends TypeDescriptor> parameters, TypeDescriptor range) { return new FunctionDescription(parameters.map[toTypeReference], range.toTypeReference); }
+ def FunctionDeclaration(CharSequence name, FunctionDescription functionDescription) { FunctionDeclaration(name,functionDescription.range, functionDescription.parameters) }
+ def FunctionDeclaration(FunctionDescription functionDescription) { FunctionDeclaration(functionDescription.range, functionDescription.parameters) }
+ def FunctionDeclaration(CharSequence name, TypeDescriptor range, TypeDescriptor... parameters) { FunctionDeclaration(name, range, parameters as Iterable extends TypeReference>) }
+ def FunctionDeclaration(TypeDescriptor range, TypeDescriptor... parameters) { FunctionDeclaration(range, parameters as Iterable extends TypeReference>) }
+ def FunctionDeclaration(CharSequence name, TypeDescriptor range, Iterable extends TypeDescriptor> parameters) { return FunctionDeclaration(range,parameters) => [x|x.name = name.canonize] }
+ def FunctionDeclaration(TypeDescriptor range, Iterable extends TypeDescriptor> parameters) {
val function = createFunctionDeclaration
for(parameter : parameters) function.parameters+=parameter.toTypeReference
function.range = range.toTypeReference
return function
}
- def public FunctionDefinition(CharSequence name, TypeDescriptor range, Function1 expression) {
+ def FunctionDefinition(CharSequence name, TypeDescriptor range, Function1 expression) {
val context = new VariableContext(this,logicFactiory)
val definition = expression.apply(context)
return FunctionDefinition(name,range,context.variables,definition);
}
- def public FunctionDefinition(CharSequence name, TypeDescriptor range, Iterable variables, TermDescription definition) {
+ def FunctionDefinition(CharSequence name, TypeDescriptor range, Iterable variables, TermDescription definition) {
return createFunctionDefinition => [
it.name = name.canonize
it.parameters += variables.map[it.range.toTypeReference]
@@ -162,23 +164,23 @@ public class LogicProblemBuilder{
it.value = definition.toTerm
]
}
- def public FunctionDefinition(CharSequence name, TypeDescriptor range, Iterable parameters, Map,Term> parametersToValue) {
+ def FunctionDefinition(CharSequence name, TypeDescriptor range, Iterable parameters, Map,Term> parametersToValue) {
return FunctionDefinition(name,range,parameters,parametersToValue,null)
}
- def public FunctionDefinition(CharSequence name, TypeDescriptor range, Iterable parameters, Map,Term> parametersToValue, Term defaultValue) {
+ def FunctionDefinition(CharSequence name, TypeDescriptor range, Iterable parameters, Map,Term> parametersToValue, Term defaultValue) {
val parameterList = parameters.toList;
val variableList = (1..parameterList.size).map[index | '''param «index»'''.createVar(parameterList.get(index-1))].toList
return FunctionDefinition(name,range,variableList,advancedConstructs.FunctionDefinitionBody(variableList,parametersToValue,defaultValue))
}
// Add function to a problem
- def public add(LogicProblem input, Function function) {
+ def add(LogicProblem input, Function function) {
input.nameIfAnonymFunction(function)
input.checkFunction(function)
input.functions += function
return function
}
- def public add(LogicProblem input, FunctionDescription functionDescription) { input.add(FunctionDeclaration(functionDescription)) }
+ def add(LogicProblem input, FunctionDescription functionDescription) { input.add(FunctionDeclaration(functionDescription)) }
def protected nameIfAnonymFunction(LogicProblem problem, Function functionDeclaration) {
if(functionDeclaration.name.nullOrEmpty) {
functionDeclaration.name = problem.functions.map[it.name].generateUniqueName[i | "function"+i]
@@ -199,15 +201,15 @@ public class LogicProblemBuilder{
}
// Constants
- def public ConstantDeclaration(CharSequence name, TypeDescriptor type) { ConstantDeclaration(type) => [it.name = name.canonize] }
- def public ConstantDeclaration(TypeDescriptor type) { createConstantDeclaration => [it.type = type.toTypeReference] }
+ def ConstantDeclaration(CharSequence name, TypeDescriptor type) { ConstantDeclaration(type) => [it.name = name.canonize] }
+ def ConstantDeclaration(TypeDescriptor type) { createConstantDeclaration => [it.type = type.toTypeReference] }
- def public ConstantDefinition(CharSequence name, TypeDescriptor type, TermDescription value) {
+ def ConstantDefinition(CharSequence name, TypeDescriptor type, TermDescription value) {
createConstantDefinition => [it.name = name.canonize it.type = type.toTypeReference it.value = value.toTerm]
}
// Add constant to a problem
- def public add(LogicProblem problem, Constant constant) {
+ def add(LogicProblem problem, Constant constant) {
problem.nameIfAnonymConstant(constant);
problem.checkConstant(constant)
problem.constants += constant
@@ -226,10 +228,10 @@ public class LogicProblemBuilder{
}
// Relations
- def public RelationDeclaration(CharSequence name, TypeDescriptor... parameters) { return RelationDeclaration(name, parameters as Iterable extends TypeReference>) }
- def public RelationDeclaration(CharSequence name, Iterable extends TypeDescriptor> parameters) { return RelationDeclaration(parameters) => [x|x.name = name.canonize] }
- def public RelationDeclaration(TypeDescriptor... parameters) { RelationDeclaration( parameters as Iterable extends TypeReference>) }
- def public RelationDeclaration(Iterable extends TypeDescriptor> parameters) {
+ def RelationDeclaration(CharSequence name, TypeDescriptor... parameters) { return RelationDeclaration(name, parameters as Iterable extends TypeReference>) }
+ def RelationDeclaration(CharSequence name, Iterable extends TypeDescriptor> parameters) { return RelationDeclaration(parameters) => [x|x.name = name.canonize] }
+ def RelationDeclaration(TypeDescriptor... parameters) { RelationDeclaration( parameters as Iterable extends TypeReference>) }
+ def RelationDeclaration(Iterable extends TypeDescriptor> parameters) {
val relation = createRelationDeclaration
for(parameter : parameters) {
relation.parameters+=parameter.toTypeReference
@@ -237,12 +239,12 @@ public class LogicProblemBuilder{
return relation
}
- def public RelationDefinition(CharSequence name, Function1 expression) {
+ def RelationDefinition(CharSequence name, Function1 expression) {
val context = new VariableContext(this,logicFactiory);
val definition = expression.apply(context);
return RelationDefinition(name,context.variables,definition)
}
- def public RelationDefinition(CharSequence name, Iterable variables, TermDescription definition) {
+ def RelationDefinition(CharSequence name, Iterable variables, TermDescription definition) {
return createRelationDefinition => [
it.name = name.canonize
it.parameters += variables.map[it.range.toTypeReference]
@@ -250,7 +252,7 @@ public class LogicProblemBuilder{
it.value = definition?.toTerm
]
}
- def public RelationDefinition(CharSequence name, Iterable extends TypeDescriptor> parameters, Iterable extends List extends TermDescription>> possibleValues) {
+ def RelationDefinition(CharSequence name, Iterable extends TypeDescriptor> parameters, Iterable extends List extends TermDescription>> possibleValues) {
val res = createRelationDefinition => [it.name = name.canonize]
val variableMap = new ArrayList(parameters.size)
var index = 0
@@ -267,7 +269,7 @@ public class LogicProblemBuilder{
}
// Add Relation to a problem
- def public add(LogicProblem input, Relation relation) {
+ def add(LogicProblem input, Relation relation) {
input.nameIfAnonymRelation(relation)
input.checkRelation(relation)
input.relations+=relation
@@ -293,17 +295,17 @@ public class LogicProblemBuilder{
}
// Assertion
- def public Assertion(TermDescription term) {
+ def Assertion(TermDescription term) {
val result = term.toTerm
result.nameAnonymVariables(Collections.EMPTY_LIST)
createAssertion => [it.value = result]
}
- def public Assertion(CharSequence name, TermDescription term) {
+ def Assertion(CharSequence name, TermDescription term) {
val result = term.toTerm
result.nameAnonymVariables(Collections.EMPTY_LIST)
createAssertion => [it.value = result it.name=name.canonize]
}
- def public add(LogicProblem problem, Assertion assertion) {
+ def add(LogicProblem problem, Assertion assertion) {
if(assertion.name.nullOrEmpty) {
val name = problem.assertions.map[name].generateUniqueName["assertion"+it]
assertion.name=name
@@ -313,7 +315,7 @@ public class LogicProblemBuilder{
return assertion
}
- def public add(LogicProblem problem, TermDescription term) {
+ def add(LogicProblem problem, TermDescription term) {
problem.add(Assertion(term))
}
@@ -329,7 +331,7 @@ public class LogicProblemBuilder{
}
}
- def public checkDefinition(EObject definition) {
+ def checkDefinition(EObject definition) {
/*for(value : definition.eAllContents.filter(SymbolicValue).toIterable) {
var referred = value.symbolicReference
if(referred instanceof Variable) {
@@ -341,7 +343,7 @@ public class LogicProblemBuilder{
}
// Containment
- def public ContainmentHierarchy(
+ def ContainmentHierarchy(
Iterable extends Type> typesInHierarchy,
Iterable extends Function> containmentFunctions,
Iterable extends Relation> containmentRelations,
@@ -355,7 +357,7 @@ public class LogicProblemBuilder{
]
return result
}
- def public add(LogicProblem problem, ContainmentHierarchy hierarchy) {
+ def add(LogicProblem problem, ContainmentHierarchy hierarchy) {
problem.containmentHierarchies+=hierarchy
return hierarchy
}
@@ -413,7 +415,7 @@ public class LogicProblemBuilder{
return result;
}
- def public Term toTerm(TermDescription term) {
+ def Term toTerm(TermDescription term) {
if(term instanceof Term) return term
else if (term instanceof Variable) return createSymbolicValue => [symbolicReference = term]
else if (term instanceof Constant) return term.call()
@@ -421,74 +423,74 @@ public class LogicProblemBuilder{
else throw new UnsupportedOperationException("Can not create reference for symbolic declaration " + term.class.name)
}
- def public !(TermDescription term) { Not(term) }
- def public Not(TermDescription term) { createNot => [operand = term.toTerm] }
+ def !(TermDescription term) { Not(term) }
+ def Not(TermDescription term) { createNot => [operand = term.toTerm] }
- def public &&(TermDescription a, TermDescription b) { And(a,b) }
- def public And(TermDescription... terms) { return And(terms as Iterable extends TermDescription>) }
- def public And(Iterable extends TermDescription> terms) { createAnd => [operands += terms.map[toTerm]] }
+ def &&(TermDescription a, TermDescription b) { And(a,b) }
+ def And(TermDescription... terms) { return And(terms as Iterable extends TermDescription>) }
+ def And(Iterable extends TermDescription> terms) { createAnd => [operands += terms.map[toTerm]] }
- def public ||(TermDescription a, TermDescription b) { Or(a,b) }
- def public Or(TermDescription... terms) { Or(terms as Iterable extends TermDescription>) }
- def public Or(Iterable extends TermDescription> terms) { createOr => [operands += terms.map[toTerm]] }
+ def ||(TermDescription a, TermDescription b) { Or(a,b) }
+ def Or(TermDescription... terms) { Or(terms as Iterable extends TermDescription>) }
+ def Or(Iterable extends TermDescription> terms) { createOr => [operands += terms.map[toTerm]] }
- def public =>(TermDescription a, TermDescription b) { Impl(a,b) }
- def public Impl(TermDescription a, TermDescription b) { createImpl => [leftOperand = a.toTerm rightOperand = b.toTerm] }
+ def =>(TermDescription a, TermDescription b) { Impl(a,b) }
+ def Impl(TermDescription a, TermDescription b) { createImpl => [leftOperand = a.toTerm rightOperand = b.toTerm] }
- def public <=>(TermDescription a, TermDescription b) { Iff(a,b)}
- def public Iff(TermDescription a, TermDescription b) { createIff =>[leftOperand=a.toTerm rightOperand=b.toTerm] }
+ def <=>(TermDescription a, TermDescription b) { Iff(a,b)}
+ def Iff(TermDescription a, TermDescription b) { createIff =>[leftOperand=a.toTerm rightOperand=b.toTerm] }
- def public ITE(TermDescription condition, TermDescription ifTrue, TermDescription ifFalse) {
+ def ITE(TermDescription condition, TermDescription ifTrue, TermDescription ifFalse) {
createIfThenElse => [it.condition = condition.toTerm it.ifTrue = ifTrue.toTerm it.ifFalse = ifFalse.toTerm]
}
- def public >(TermDescription left, TermDescription right) { MoreThan(left,right)}
- def public MoreThan(TermDescription left, TermDescription right) { createMoreThan => [leftOperand=left.toTerm rightOperand=right.toTerm] }
+ def >(TermDescription left, TermDescription right) { MoreThan(left,right)}
+ def MoreThan(TermDescription left, TermDescription right) { createMoreThan => [leftOperand=left.toTerm rightOperand=right.toTerm] }
- def public <(TermDescription left, TermDescription right) { LessThan(left,right)}
- def public LessThan(TermDescription left, TermDescription right) { createLessThan => [leftOperand=left.toTerm rightOperand=right.toTerm] }
+ def <(TermDescription left, TermDescription right) { LessThan(left,right)}
+ def LessThan(TermDescription left, TermDescription right) { createLessThan => [leftOperand=left.toTerm rightOperand=right.toTerm] }
- def public <=(TermDescription left, TermDescription right) { LessOrEqual(left,right) }
- def public LessOrEqual(TermDescription left, TermDescription right) { createLessOrEqualThan => [leftOperand=left.toTerm rightOperand=right.toTerm] }
+ def <=(TermDescription left, TermDescription right) { LessOrEqual(left,right) }
+ def LessOrEqual(TermDescription left, TermDescription right) { createLessOrEqualThan => [leftOperand=left.toTerm rightOperand=right.toTerm] }
- def public >=(TermDescription left, TermDescription right) { MoreOrEqual(left,right) }
- def public MoreOrEqual(TermDescription left, TermDescription right) { createMoreOrEqualThan => [leftOperand=left.toTerm rightOperand=right.toTerm] }
+ def >=(TermDescription left, TermDescription right) { MoreOrEqual(left,right) }
+ def MoreOrEqual(TermDescription left, TermDescription right) { createMoreOrEqualThan => [leftOperand=left.toTerm rightOperand=right.toTerm] }
- def public ==(TermDescription left, TermDescription right) {Equals(left,right)}
- def public Equals(TermDescription left, TermDescription right) { createEquals => [leftOperand=left.toTerm rightOperand=right.toTerm] }
+ def ==(TermDescription left, TermDescription right) {Equals(left,right)}
+ def Equals(TermDescription left, TermDescription right) { createEquals => [leftOperand=left.toTerm rightOperand=right.toTerm] }
- def public !=(TermDescription left, TermDescription right) { Distinct(left,right) }
- def public Distinct(TermDescription... terms) { return Distinct(terms as Iterable extends TermDescription>) }
- def public Distinct(Iterable extends TermDescription> terms) { createDistinct => [operands += terms.map[toTerm]] }
+ def !=(TermDescription left, TermDescription right) { Distinct(left,right) }
+ def Distinct(TermDescription... terms) { return Distinct(terms as Iterable extends TermDescription>) }
+ def Distinct(Iterable extends TermDescription> terms) { createDistinct => [operands += terms.map[toTerm]] }
- def public +(TermDescription left, TermDescription right) { Plus(left,right) }
- def public Plus(TermDescription left, TermDescription right) { createPlus => [leftOperand=left.toTerm rightOperand=right.toTerm] }
+ def +(TermDescription left, TermDescription right) { Plus(left,right) }
+ def Plus(TermDescription left, TermDescription right) { createPlus => [leftOperand=left.toTerm rightOperand=right.toTerm] }
- def public -(TermDescription left, TermDescription right) { Minus(left,right) }
- def public Minus(TermDescription left, TermDescription right) { createMinus => [leftOperand=left.toTerm rightOperand=right.toTerm] }
+ def -(TermDescription left, TermDescription right) { Minus(left,right) }
+ def Minus(TermDescription left, TermDescription right) { createMinus => [leftOperand=left.toTerm rightOperand=right.toTerm] }
- def public *(TermDescription left, TermDescription right) { Multiply(left,right) }
- def public Multiply(TermDescription left, TermDescription right) { createMultiply => [leftOperand=left.toTerm rightOperand=right.toTerm] }
+ def *(TermDescription left, TermDescription right) { Multiply(left,right) }
+ def Multiply(TermDescription left, TermDescription right) { createMultiply => [leftOperand=left.toTerm rightOperand=right.toTerm] }
- def public /(TermDescription left, TermDescription right) { Divide(left,right) }
- def public Divide(TermDescription left, TermDescription right) { createDivison => [leftOperand = left.toTerm rightOperand = right.toTerm]}
+ def /(TermDescription left, TermDescription right) { Divide(left,right) }
+ def Divide(TermDescription left, TermDescription right) { createDivison => [leftOperand = left.toTerm rightOperand = right.toTerm]}
- def public %(TermDescription left, TermDescription right) { Modulo(left,right) }
- def public Modulo(TermDescription left, TermDescription right) { createMod => [leftOperand = left.toTerm rightOperand = right.toTerm]}
+ def %(TermDescription left, TermDescription right) { Modulo(left,right) }
+ def Modulo(TermDescription left, TermDescription right) { createMod => [leftOperand = left.toTerm rightOperand = right.toTerm]}
- def public asTerm(boolean value) { createBoolLiteral => [x|x.value = value] }
- def public asTerm(int value) { createIntLiteral => [x|x.value = value] }
- def public asTerm(double value) { BigDecimal.valueOf(value).asTerm }
- def public asTerm(float value) { BigDecimal.valueOf(value).asTerm }
- def public asTerm(BigDecimal value) { createRealLiteral => [x|x.value = value] }
- def public asTerm(String value) { createStringLiteral => [x|x.value = value]}
- def public InstanceOf(TermDescription term, TypeDescriptor type) {
+ 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 }
+ def asTerm(float value) { BigDecimal.valueOf(value).asTerm }
+ def asTerm(BigDecimal value) { createRealLiteral => [x|x.value = value] }
+ def asTerm(String value) { createStringLiteral => [x|x.value = value]}
+ def InstanceOf(TermDescription term, TypeDescriptor type) {
createInstanceOf => [
it.value = term.toTerm
it.range = type.toTypeReference
]
}
- def public transitiveClosure(Relation relation, TermDescription source, TermDescription target) {
+ def transitiveClosure(Relation relation, TermDescription source, TermDescription target) {
createTransitiveClosure => [
it.relation = relation
it.leftOperand = leftOperand
@@ -498,38 +500,79 @@ public class LogicProblemBuilder{
// QuantifiedExpressions
- def public Forall(Function1 expression) {
+ def Forall(Function1 expression) {
val context = new VariableContext(this,logicFactiory)
val term = expression.apply(context)
return createForall => [x| x.quantifiedVariables+=context.variables x.expression = term.toTerm]
}
- def public Forall(TermDescription expression, Variable... variables) {
+ def Forall(TermDescription expression, Variable... variables) {
Forall(variables,expression) }
- def public Forall(Iterable extends Variable> variables,TermDescription expression) {
+ def Forall(Iterable extends Variable> variables,TermDescription expression) {
val forallExpression = createForall
for(variable : variables) forallExpression.quantifiedVariables += variable
forallExpression.expression = expression.toTerm
return forallExpression
}
- def public Exists(Function1 expression) {
+ def Exists(Function1 expression) {
val context = new VariableContext(this,logicFactiory)
val term = expression.apply(context)
return createExists => [x| x.quantifiedVariables+=context.variables x.expression = term.toTerm]
}
- def public Exists(TermDescription expression, Variable... variables) {
+ def Exists(TermDescription expression, Variable... variables) {
Exists(variables,expression) }
- def public Exists(Iterable extends Variable> variables, TermDescription expression) {
+ def Exists(Iterable extends Variable> variables, TermDescription expression) {
val existsExpression = createExists
for(variable : variables) existsExpression.quantifiedVariables += variable
existsExpression.expression = expression.toTerm
return existsExpression
}
+ // AggregatedExpression
+
+ private def configureAggregateExpression(T expression, Relation referred, List terms) {
+ 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
+ for(var i=0; i [it.variable = target]
+ expression.parameterSubstitution += substitution
+ }
+ return expression
+ }
+ }
+ private def configureProjectedAggregateExpression(T expression, Relation referred, List terms, 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) {
+ throw new LogicProblemBuilderException(
+ '''Projection over set variable!''')
+ }
+ val projectionType = referred.parameters.get(projection)
+ if(!(projectionType instanceof IntTypeReference || projectionType instanceof RealTypeReference)) {
+ throw new LogicProblemBuilderException('''Projection over nunnumeric parameter!'''
+ )
+ }
+ res.projectionIndex = projection
+ return res
+ }
+
+ }
+ 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) }
+
// Function calls
- def public call(Function function, TermDescription... substitutions) {
+ def call(Function function, TermDescription... substitutions) {
call(function, substitutions as Iterable extends TermDescription>) }
- def public call(Function function, Iterable extends TermDescription> substitutions) {
+ def call(Function function, Iterable extends TermDescription> substitutions) {
val functionReference = createSymbolicValue
functionReference.symbolicReference=function
val List l= new LinkedList()
@@ -546,8 +589,8 @@ public class LogicProblemBuilder{
}
// Relation calls
- def public call(Relation relation, TermDescription... substitution) { relation.call(substitution as Iterable extends TermDescription>)}
- def public call(Relation relation, Iterable extends TermDescription> substitution) {
+ def call(Relation relation, TermDescription... substitution) { relation.call(substitution as Iterable extends TermDescription>)}
+ def call(Relation relation, Iterable extends TermDescription> substitution) {
val relationReference = createSymbolicValue
relationReference.symbolicReference = relation
//println('''«relation.name»(«substitution.size»->«relation.parameters»)''')
@@ -567,11 +610,9 @@ public class LogicProblemBuilder{
}
// constant evaluation
- def public call(Constant constant) {
+ def call(Constant constant) {
val constantReference = createSymbolicValue
constantReference.symbolicReference = constant
return constantReference
- }
-
-
+ }
}
--
cgit v1.2.3-54-g00ecf
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')
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-54-g00ecf