{@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#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
From 933ce1872359918ff71602479640f4153063a737 Mon Sep 17 00:00:00 2001
From: Oszkar Semerath
Date: Fri, 30 Aug 2019 14:26:55 +0200
Subject: Bug fixed in transitive closure expression builder
---
.../mit/inf/dslreasoner/logic/model/builder/LogicProblemBuilder.xtend | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic')
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 a231af3c..fa97cbef 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
@@ -494,8 +494,8 @@ class LogicProblemBuilder{
def transitiveClosure(Relation relation, TermDescription source, TermDescription target) {
createTransitiveClosure => [
it.relation = relation
- it.leftOperand = leftOperand
- it.rightOperand = rightOperand
+ it.leftOperand = source.toTerm
+ it.rightOperand = target.toTerm
]
}
--
cgit v1.2.3-54-g00ecf
From 28b8a136335733343360d2e6ff0bbdb959334386 Mon Sep 17 00:00:00 2001
From: Oszkar Semerath
Date: Thu, 14 May 2020 23:06:40 +0200
Subject: separtor ; -> \t
---
.../inf/dslreasoner/logic/model/statistics/StatisticSections2CSV.xtend | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic')
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2CSV.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2CSV.xtend
index d673cb17..d6dc1c5e 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2CSV.xtend
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2CSV.xtend
@@ -17,7 +17,7 @@ class StatisticsData {
}
class StatisticSections2CSV {
- static val separator = ';'
+ static val separator = '\t'
static val empty = ""
private def getValue(Map map,String key) {
--
cgit v1.2.3-54-g00ecf
From 73738a94151363ae96557d749ff4ab93d941f983 Mon Sep 17 00:00:00 2001
From: Oszkar Semerath
Date: Sun, 17 May 2020 01:34:05 +0200
Subject: Setting delimier in every printing mode to ','
---
.../inf/dslreasoner/logic/model/statistics/StatisticSections2CSV.xtend | 2 +-
.../dslreasoner/logic/model/statistics/StatisticSections2Print.xtend | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic')
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2CSV.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2CSV.xtend
index d6dc1c5e..a78ceb19 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2CSV.xtend
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2CSV.xtend
@@ -17,7 +17,7 @@ class StatisticsData {
}
class StatisticSections2CSV {
- static val separator = '\t'
+ static val separator = ','
static val empty = ""
private def getValue(Map map,String key) {
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2Print.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2Print.xtend
index 39370d75..c5e81f94 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2Print.xtend
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/statistics/StatisticSections2Print.xtend
@@ -12,7 +12,7 @@ class StatisticSections2Print {
{
var result = "";
for(statistic : statistics) {
- result+= '''«statistic.readValue»;'''
+ result+= '''«statistic.readValue»,'''
}
return result
}
--
cgit v1.2.3-54-g00ecf
From eb081453e93e6e30c0b6bb92400275529ed3273b Mon Sep 17 00:00:00 2001
From: Kristóf Marussy
Date: Wed, 20 May 2020 02:07:37 +0200
Subject: Fix attribute export to xmi
---
.../inf/dslreasoner/ecore2logic/Ecore2Logic.xtend | 10 +--
.../model/builder/LogicModelInterpretation.xtend | 76 ++++++++++++++++------
.../inf/dslreasoner/logic2ecore/Logic2Ecore.xtend | 49 +++++---------
.../dse/PartialModelAsLogicInterpretation.xtend | 63 +++++++++++++++++-
4 files changed, 139 insertions(+), 59 deletions(-)
(limited to 'Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic')
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.ecore2logic/src/hu/bme/mit/inf/dslreasoner/ecore2logic/Ecore2Logic.xtend b/Framework/hu.bme.mit.inf.dslreasoner.ecore2logic/src/hu/bme/mit/inf/dslreasoner/ecore2logic/Ecore2Logic.xtend
index cae489e3..85b488eb 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.ecore2logic/src/hu/bme/mit/inf/dslreasoner/ecore2logic/Ecore2Logic.xtend
+++ b/Framework/hu.bme.mit.inf.dslreasoner.ecore2logic/src/hu/bme/mit/inf/dslreasoner/ecore2logic/Ecore2Logic.xtend
@@ -1,7 +1,13 @@
package hu.bme.mit.inf.dslreasoner.ecore2logic
+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.Term
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TermDescription
+import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.ContainmentHierarchy
import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
import java.util.List
+import java.util.Set
import org.eclipse.emf.ecore.EAttribute
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EEnum
@@ -9,10 +15,6 @@ import org.eclipse.emf.ecore.EEnumLiteral
import org.eclipse.emf.ecore.EReference
import org.eclipse.xtend.lib.annotations.Data
import org.eclipse.xtend.lib.annotations.Delegate
-import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput
-import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder
-import java.util.Set
-import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.ContainmentHierarchy
@Data class EcoreMetamodelDescriptor {
val List classes;
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicModelInterpretation.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicModelInterpretation.xtend
index 905859eb..cdcbb48a 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicModelInterpretation.xtend
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicModelInterpretation.xtend
@@ -3,22 +3,27 @@ package hu.bme.mit.inf.dslreasoner.logic.model.builder
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ConstantDeclaration
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.FunctionDeclaration
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TermDescription
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDeclaration
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition
+import java.math.BigDecimal
import java.util.List
+import java.util.Map
+import java.util.SortedSet
+import java.util.TreeSet
import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
-import java.util.SortedSet
-import java.math.BigDecimal
-interface LogicModelInterpretation{
-
+interface LogicModelInterpretation {
+
/**
* Returns the elements of a type.
- */
+ */
def List getElements(Type type)
+
/**
* Returns the interpretation of a function. The parameters and the return values are encoded to primitive java objects defined by the following table:
*
@@ -34,6 +39,7 @@ interface LogicModelInterpretation{
* @return The result of the function call encoded as defined in the table.
*/
def Object getInterpretation(FunctionDeclaration function, Object[] parameterSubstitution)
+
/**
* Returns the interpretation of a relation. The parameters are encoded to primitive java objects defined by the following table:
*
@@ -49,6 +55,7 @@ interface LogicModelInterpretation{
* @return If the parameter tuple is in the relation.
*/
def boolean getInterpretation(RelationDeclaration relation, Object[] parameterSubstitution)
+
/**
* Returns the interpretation of a constant. The value is encoded to primitive java objects defined by the following table:
*
@@ -63,60 +70,89 @@ interface LogicModelInterpretation{
* @return The value of the constant encoded as specified in the table.
*/
def Object getInterpretation(ConstantDeclaration constant)
-
+
/**
* Returns all integers relevant to the logic structure. Not all integer is necessarily used.
*/
def SortedSet getAllIntegersInStructure()
+
+ def Map getAllIntegersWithInterpretation() {
+ allIntegersInStructure.toMap [ integer |
+ (LogiclanguageFactory.eINSTANCE.createIntLiteral => [value = integer]) as TermDescription
+ ]
+ }
+
/**
* Returns all real numbers relevant to the logic structure. Not all integer is necessarily used.
*/
- def SortedSet getAllRealsInStructure()
- /**
+ def SortedSet getAllRealsInStructure()
+
+ def Map getAllRealsWithInterpretation() {
+ allRealsInStructure.toMap [ real |
+ (LogiclanguageFactory.eINSTANCE.createRealLiteral => [value = real]) as TermDescription
+ ]
+ }
+
+ /**
* Returns all string values relevant to the logic structure. Not all integer is necessarily used.
*/
- def SortedSet getAllStringsInStructure()
+ def SortedSet getAllStringsInStructure()
+
+ def Map getAllStringsWithInterpretation() {
+ allStringsInStructure.toMap [ string |
+ (LogiclanguageFactory.eINSTANCE.createStringLiteral => [value = string]) as TermDescription
+ ]
+ }
+
+ def SortedSet getAllBooleansInStructure() {
+ new TreeSet(#{true, false})
+ }
+
+ def Map getAllBooleansWithInterpretation() {
+ allBooleansInStructure.toMap [ bool |
+ (LogiclanguageFactory.eINSTANCE.createBoolLiteral => [value = bool]) as TermDescription
+ ]
+ }
}
class Uninterpreted implements LogicModelInterpretation {
/*private val static unknownBecauseUninterpreted = LogiclanguageFactory.eINSTANCE.createUnknownBecauseUninterpreted
- public def static getUnknownBecauseUninterpreted() {return Uninterpreted.unknownBecauseUninterpreted}*/
-
+ public def static getUnknownBecauseUninterpreted() {return Uninterpreted.unknownBecauseUninterpreted}*/
override getElements(Type type) {
throw new UnsupportedOperationException("The interpteration is unknown.")
}
-
+
def getKnownElements(Type type) {
val allSubtypes = type.transitiveClosureStar[it.subtypes]
return allSubtypes.filter(TypeDefinition).map[elements].flatten.toList
}
-
+
def allElementsAreInterpreted(Type type) {
val allSubtypes = type.transitiveClosureStar[it.subtypes]
return allSubtypes.exists[it instanceof TypeDeclaration]
}
-
+
override getInterpretation(FunctionDeclaration function, Object[] parameterSubstitution) {
throw new UnsupportedOperationException("The interpteration is unknown.")
}
-
+
override getInterpretation(RelationDeclaration relation, Object[] parameterSubstitution) {
throw new UnsupportedOperationException("The interpteration is unknown.")
}
-
+
override getInterpretation(ConstantDeclaration constant) {
throw new UnsupportedOperationException("The interpteration is unknown.")
}
-
+
override getAllIntegersInStructure() {
throw new UnsupportedOperationException("The interpteration is unknown.")
}
-
+
override getAllRealsInStructure() {
throw new UnsupportedOperationException("The interpteration is unknown.")
}
-
+
override getAllStringsInStructure() {
throw new UnsupportedOperationException("The interpteration is unknown.")
}
-}
\ No newline at end of file
+}
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend
index 08c6b7b7..8d6b565a 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend
@@ -3,25 +3,24 @@ package hu.bme.mit.inf.dslreasoner.logic2ecore
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.LogicModelInterpretation
+import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder
import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicStructureBuilder
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TermDescription
+import java.math.BigDecimal
import java.util.Collection
import java.util.HashMap
import java.util.HashSet
import java.util.List
+import java.util.Map
import java.util.Set
import org.eclipse.emf.ecore.EClass
+import org.eclipse.emf.ecore.EDataType
+import org.eclipse.emf.ecore.EEnum
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.EStructuralFeature
+import org.eclipse.emf.ecore.EcorePackage
import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
-import org.eclipse.emf.ecore.EEnum
-import org.eclipse.emf.ecore.EDataType
-import org.eclipse.emf.ecore.EcorePackage
-import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TermDescription
-import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder
-import java.util.Map
-import org.eclipse.emf.ecore.EAttribute
-import java.math.BigDecimal
class Logic2Ecore {
val extension LogicStructureBuilder structureBuilder = new LogicStructureBuilder
@@ -86,15 +85,15 @@ class Logic2Ecore {
if(attributeType.EContainingClass.isSuperTypeOf(sourceObject.eClass)) {
val allElementsOfTargetDatatype = getAllElementsOfDatatype(attributeType.EAttributeType,forwardTrace,interpretation)
for(l : allElementsOfTargetDatatype.entrySet) {
- val expression = ecore2Logic.IsAttributeValue(forwardTrace,sourceElement,l.value,attributeType)
+ val expression = ecore2Logic.IsAttributeValue(forwardTrace,sourceElement,l.key,attributeType)
val linkExist = interpretation.evalAsBool(expression)
if(linkExist) {
if(attributeType.isMany) {
val list = sourceObject.eGet(attributeType) as List super Object>
- list += l.key
+ list += l.value
} else {
try {
- sourceObject.eSet(attributeType,translateType(attributeType.EAttributeType,l.key))
+ sourceObject.eSet(attributeType,translateType(attributeType.EAttributeType,l.value))
} catch(Exception e) {
e.printStackTrace
}
@@ -119,34 +118,20 @@ class Logic2Ecore {
} else return value
}
-
-// if(attributeType.EAttributeType.isSuperTypeOf(targetObject.eClass)) {
-// val expression = ecore2Logic.IsAttributeValue(forwardTrace,sourceElement,targetElement,attributeType)
-// val linkExist = interpretation.evalAsBool(expression)
-// if(linkExist) {
-// if(attributeType.isMany) {
-// val list = sourceObject.eGet(attributeType) as List super EObject>
-// list+= targetObject
-// } else {
-// sourceObject.eSet(referenceType,targetObject)
-// }
-// }
-// }
-
- protected dispatch def Map extends Object, ? extends TermDescription> getAllElementsOfDatatype(EEnum type, Ecore2Logic_Trace forwardTrace, LogicModelInterpretation interpretation) {
- ecore2Logic.allLiteralsInScope(forwardTrace).toInvertedMap[ecore2Logic.Literal(forwardTrace,it)]
+ protected dispatch def Map extends TermDescription, ? extends Object> getAllElementsOfDatatype(EEnum type, Ecore2Logic_Trace forwardTrace, LogicModelInterpretation interpretation) {
+ ecore2Logic.allLiteralsInScope(forwardTrace).toMap[ecore2Logic.Literal(forwardTrace,it)]
}
- protected dispatch def Map extends Object, ? extends TermDescription> getAllElementsOfDatatype(EDataType primitive, Ecore2Logic_Trace forwardTrace, LogicModelInterpretation interpretation) {
+ protected dispatch def Map extends TermDescription, ? extends Object> getAllElementsOfDatatype(EDataType primitive, Ecore2Logic_Trace forwardTrace, LogicModelInterpretation interpretation) {
val extension LogicProblemBuilder b = new LogicProblemBuilder
if(primitive === EcorePackage.eINSTANCE.EInt || primitive === EcorePackage.eINSTANCE.EShort || primitive === EcorePackage.eINSTANCE.ELong) {
- interpretation.allIntegersInStructure.toInvertedMap[it.asTerm]
+ interpretation.allIntegersWithInterpretation
} else if(primitive === EcorePackage.eINSTANCE.EDouble || primitive === EcorePackage.eINSTANCE.EFloat) {
- interpretation.allRealsInStructure.toInvertedMap[it.asTerm]
+ interpretation.allRealsWithInterpretation
} else if(primitive === EcorePackage.eINSTANCE.EString) {
- interpretation.allStringsInStructure.toInvertedMap[it.asTerm]
+ interpretation.allStringsWithInterpretation
} else if(primitive === EcorePackage.eINSTANCE.EBoolean) {
- return #[false,true].toInvertedMap[it.asTerm]
+ interpretation.allBooleansWithInterpretation
}
}
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/PartialModelAsLogicInterpretation.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/PartialModelAsLogicInterpretation.xtend
index f61c7333..48922f5d 100644
--- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/PartialModelAsLogicInterpretation.xtend
+++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/PartialModelAsLogicInterpretation.xtend
@@ -1,5 +1,6 @@
package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse
+import com.google.common.collect.ImmutableMap
import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicModelInterpretation
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ConstantDeclaration
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement
@@ -153,14 +154,70 @@ class PartialModelAsLogicInterpretation implements LogicModelInterpretation{
}
override getAllIntegersInStructure() {
- new TreeSet(this.integerForwardTrace.keySet)
+ new TreeSet(allIntegersWithInterpretation.values)
+ }
+
+ override getAllIntegersWithInterpretation() {
+ val builder = new HashMap
+ for (entry : integerForwardTrace.entrySet) {
+ builder.put(entry.value, entry.key)
+ }
+ for (element : partialInterpretation.newElements) {
+ if (element instanceof IntegerElement) {
+ builder.put(element, element.value)
+ }
+ }
+ builder
}
override getAllRealsInStructure() {
- new TreeSet(this.realForwardTrace.keySet)
+ new TreeSet(allRealsWithInterpretation.values)
+ }
+
+ override getAllRealsWithInterpretation() {
+ val builder = new HashMap
+ for (entry : realForwardTrace.entrySet) {
+ builder.put(entry.value, entry.key)
+ }
+ for (element : partialInterpretation.newElements) {
+ if (element instanceof RealElement) {
+ builder.put(element, element.value)
+ }
+ }
+ builder
}
override getAllStringsInStructure() {
- new TreeSet(this.stringForwardTrace.keySet)
+ new TreeSet(allStringsWithInterpretation.values)
+ }
+
+ override getAllStringsWithInterpretation() {
+ val builder = new HashMap
+ for (entry : stringForwardTrace.entrySet) {
+ builder.put(entry.value, entry.key)
+ }
+ for (element : partialInterpretation.newElements) {
+ if (element instanceof StringElement) {
+ builder.put(element, element.value)
+ }
+ }
+ builder
+ }
+
+ override getAllBooleansInStructure() {
+ new TreeSet(allBooleansWithInterpretation.values)
+ }
+
+ override getAllBooleansWithInterpretation() {
+ val builder = new HashMap
+ for (entry : booleanForwardTrace.entrySet) {
+ builder.put(entry.value, entry.key)
+ }
+ for (element : partialInterpretation.newElements) {
+ if (element instanceof BooleanElement) {
+ builder.put(element, element.value)
+ }
+ }
+ builder
}
}
\ No newline at end of file
--
cgit v1.2.3-54-g00ecf