aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar OszkarSemerath <oszkar.semerath@gmail.com>2018-10-11 19:22:18 +0200
committerLibravatar OszkarSemerath <oszkar.semerath@gmail.com>2018-10-11 19:22:18 +0200
commitfd3f01f4240ff13f7877784b2f5417031f7e7da6 (patch)
treec091b41ac37cf142ed2fdf4905bc841011ca6f76
parentUpdate error message for untranslated types in Viatra (diff)
downloadVIATRA-Generator-fd3f01f4240ff13f7877784b2f5417031f7e7da6.tar.gz
VIATRA-Generator-fd3f01f4240ff13f7877784b2f5417031f7e7da6.tar.zst
VIATRA-Generator-fd3f01f4240ff13f7877784b2f5417031f7e7da6.zip
Attributes are filled in instance models
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend64
1 files changed, 62 insertions, 2 deletions
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 00239935..c7e14362 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
@@ -14,9 +14,15 @@ import org.eclipse.emf.ecore.EObject
14import org.eclipse.emf.ecore.EStructuralFeature 14import org.eclipse.emf.ecore.EStructuralFeature
15 15
16import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* 16import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
17import org.eclipse.emf.ecore.EEnum
18import org.eclipse.emf.ecore.EDataType
19import org.eclipse.emf.ecore.EcorePackage
20import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TermDescription
21import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder
22import java.util.Map
17 23
18class Logic2Ecore { 24class Logic2Ecore {
19 private val extension LogicStructureBuilder structureBuilder = new LogicStructureBuilder 25 val extension LogicStructureBuilder structureBuilder = new LogicStructureBuilder
20 val Ecore2Logic ecore2Logic; 26 val Ecore2Logic ecore2Logic;
21 27
22 new (Ecore2Logic ecore2Logic) { 28 new (Ecore2Logic ecore2Logic) {
@@ -70,11 +76,65 @@ class Logic2Ecore {
70 } 76 }
71 } 77 }
72 78
73 /// + Attributes 79 val allAttributes = ecore2Logic.allAttributesInScope(forwardTrace)
80 for(attributeType : allAttributes) {
81 if(attributeType.canSetFeature) {
82 for(sourceElement : elements) {
83 val sourceObject = sourceElement.lookup(element2Object)
84 if(attributeType.EContainingClass.isSuperTypeOf(sourceObject.eClass)) {
85 val allElementsOfTargetDatatype = getAllElementsOfDatatype(attributeType.EAttributeType,forwardTrace,interpretation)
86 for(l : allElementsOfTargetDatatype.entrySet) {
87 val expression = ecore2Logic.IsAttributeValue(forwardTrace,sourceElement,l.value,attributeType)
88 val linkExist = interpretation.evalAsBool(expression)
89 if(linkExist) {
90 if(attributeType.isMany) {
91 val list = sourceObject.eGet(attributeType) as List<? super Object>
92 list += l.key
93 } else {
94 sourceObject.eSet(attributeType,l)
95 }
96 }
97 }
98 }
99 }
100 }
101 }
74 102
75 return element2Object.values.root 103 return element2Object.values.root
76 } 104 }
77 105
106
107// if(attributeType.EAttributeType.isSuperTypeOf(targetObject.eClass)) {
108// val expression = ecore2Logic.IsAttributeValue(forwardTrace,sourceElement,targetElement,attributeType)
109// val linkExist = interpretation.evalAsBool(expression)
110// if(linkExist) {
111// if(attributeType.isMany) {
112// val list = sourceObject.eGet(attributeType) as List<? super EObject>
113// list+= targetObject
114// } else {
115// sourceObject.eSet(referenceType,targetObject)
116// }
117// }
118// }
119
120 protected dispatch def Map<? extends Object, ? extends TermDescription> getAllElementsOfDatatype(EEnum type, Ecore2Logic_Trace forwardTrace, LogicModelInterpretation interpretation) {
121 ecore2Logic.allLiteralsInScope(forwardTrace).toInvertedMap[ecore2Logic.Literal(forwardTrace,it)]
122 }
123
124 protected dispatch def Map<? extends Object, ? extends TermDescription> getAllElementsOfDatatype(EDataType primitive, Ecore2Logic_Trace forwardTrace, LogicModelInterpretation interpretation) {
125 val extension LogicProblemBuilder b = new LogicProblemBuilder
126 if(primitive === EcorePackage.eINSTANCE.EInt || primitive === EcorePackage.eINSTANCE.EShort || primitive === EcorePackage.eINSTANCE.ELong) {
127 interpretation.allIntegersInStructure.toInvertedMap[it.asTerm]
128 } else if(primitive === EcorePackage.eINSTANCE.EDouble || primitive === EcorePackage.eINSTANCE.EFloat) {
129 interpretation.allRealsInStructure.toInvertedMap[it.asTerm]
130 } else if(primitive === EcorePackage.eINSTANCE.EString) {
131 interpretation.allStringsInStructure.toInvertedMap[it.asTerm]
132 } else if(primitive === EcorePackage.eINSTANCE.EBoolean) {
133 return #[false,true].toInvertedMap[it.asTerm]
134 }
135 }
136
137
78 private def canSetFeature(EStructuralFeature feature) { 138 private def canSetFeature(EStructuralFeature feature) {
79 feature.changeable && !feature.derived 139 feature.changeable && !feature.derived
80 } 140 }