diff options
author | 2020-11-04 01:33:58 -0500 | |
---|---|---|
committer | 2020-11-04 01:33:58 -0500 | |
commit | a20af4d0dbf5eab84ee271d426528aabb5a8ac3b (patch) | |
tree | a9ab772ee313125aaf3a941d66e131b408d949ba /Framework/hu.bme.mit.inf.dslreasoner.logic2ecore | |
parent | changes in settings of measurements (diff) | |
parent | merge with current master, comment numerical solver related logging (diff) | |
download | VIATRA-Generator-a20af4d0dbf5eab84ee271d426528aabb5a8ac3b.tar.gz VIATRA-Generator-a20af4d0dbf5eab84ee271d426528aabb5a8ac3b.tar.zst VIATRA-Generator-a20af4d0dbf5eab84ee271d426528aabb5a8ac3b.zip |
fix merging issue
Diffstat (limited to 'Framework/hu.bme.mit.inf.dslreasoner.logic2ecore')
-rw-r--r-- | Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend | 55 |
1 files changed, 26 insertions, 29 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 92deeae6..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,23 +3,24 @@ package hu.bme.mit.inf.dslreasoner.logic2ecore | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | 3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic |
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | 4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace |
5 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicModelInterpretation | 5 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicModelInterpretation |
6 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicStructureBuilder | 7 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicStructureBuilder |
8 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TermDescription | ||
9 | import java.math.BigDecimal | ||
7 | import java.util.Collection | 10 | import java.util.Collection |
8 | import java.util.HashMap | 11 | import java.util.HashMap |
9 | import java.util.HashSet | 12 | import java.util.HashSet |
10 | import java.util.List | 13 | import java.util.List |
14 | import java.util.Map | ||
11 | import java.util.Set | 15 | import java.util.Set |
12 | import org.eclipse.emf.ecore.EClass | 16 | import org.eclipse.emf.ecore.EClass |
17 | import org.eclipse.emf.ecore.EDataType | ||
18 | import org.eclipse.emf.ecore.EEnum | ||
13 | import org.eclipse.emf.ecore.EObject | 19 | import org.eclipse.emf.ecore.EObject |
14 | import org.eclipse.emf.ecore.EStructuralFeature | 20 | import org.eclipse.emf.ecore.EStructuralFeature |
21 | import org.eclipse.emf.ecore.EcorePackage | ||
15 | 22 | ||
16 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 23 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
17 | import org.eclipse.emf.ecore.EEnum | ||
18 | import org.eclipse.emf.ecore.EDataType | ||
19 | import org.eclipse.emf.ecore.EcorePackage | ||
20 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TermDescription | ||
21 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder | ||
22 | import java.util.Map | ||
23 | 24 | ||
24 | class Logic2Ecore { | 25 | class Logic2Ecore { |
25 | val extension LogicStructureBuilder structureBuilder = new LogicStructureBuilder | 26 | val extension LogicStructureBuilder structureBuilder = new LogicStructureBuilder |
@@ -84,15 +85,15 @@ class Logic2Ecore { | |||
84 | if(attributeType.EContainingClass.isSuperTypeOf(sourceObject.eClass)) { | 85 | if(attributeType.EContainingClass.isSuperTypeOf(sourceObject.eClass)) { |
85 | val allElementsOfTargetDatatype = getAllElementsOfDatatype(attributeType.EAttributeType,forwardTrace,interpretation) | 86 | val allElementsOfTargetDatatype = getAllElementsOfDatatype(attributeType.EAttributeType,forwardTrace,interpretation) |
86 | for(l : allElementsOfTargetDatatype.entrySet) { | 87 | for(l : allElementsOfTargetDatatype.entrySet) { |
87 | val expression = ecore2Logic.IsAttributeValue(forwardTrace,sourceElement,l.value,attributeType) | 88 | val expression = ecore2Logic.IsAttributeValue(forwardTrace,sourceElement,l.key,attributeType) |
88 | val linkExist = interpretation.evalAsBool(expression) | 89 | val linkExist = interpretation.evalAsBool(expression) |
89 | if(linkExist) { | 90 | if(linkExist) { |
90 | if(attributeType.isMany) { | 91 | if(attributeType.isMany) { |
91 | val list = sourceObject.eGet(attributeType) as List<? super Object> | 92 | val list = sourceObject.eGet(attributeType) as List<? super Object> |
92 | list += l.key | 93 | list += l.value |
93 | } else { | 94 | } else { |
94 | try { | 95 | try { |
95 | sourceObject.eSet(attributeType,l.key) | 96 | sourceObject.eSet(attributeType,translateType(attributeType.EAttributeType,l.value)) |
96 | } catch(Exception e) { | 97 | } catch(Exception e) { |
97 | e.printStackTrace | 98 | e.printStackTrace |
98 | } | 99 | } |
@@ -107,34 +108,30 @@ class Logic2Ecore { | |||
107 | return element2Object.values.root | 108 | return element2Object.values.root |
108 | } | 109 | } |
109 | 110 | ||
111 | def translateType(EDataType type, Object value) { | ||
112 | if(type == EcorePackage.eINSTANCE.EFloat) { | ||
113 | val bd = value as BigDecimal | ||
114 | return bd.floatValue | ||
115 | } else if( type == EcorePackage.eINSTANCE.EDouble ) { | ||
116 | val bd = value as BigDecimal | ||
117 | return bd.doubleValue | ||
118 | } else return value | ||
119 | } | ||
110 | 120 | ||
111 | // if(attributeType.EAttributeType.isSuperTypeOf(targetObject.eClass)) { | 121 | protected dispatch def Map<? extends TermDescription, ? extends Object> getAllElementsOfDatatype(EEnum type, Ecore2Logic_Trace forwardTrace, LogicModelInterpretation interpretation) { |
112 | // val expression = ecore2Logic.IsAttributeValue(forwardTrace,sourceElement,targetElement,attributeType) | 122 | ecore2Logic.allLiteralsInScope(forwardTrace).toMap[ecore2Logic.Literal(forwardTrace,it)] |
113 | // val linkExist = interpretation.evalAsBool(expression) | ||
114 | // if(linkExist) { | ||
115 | // if(attributeType.isMany) { | ||
116 | // val list = sourceObject.eGet(attributeType) as List<? super EObject> | ||
117 | // list+= targetObject | ||
118 | // } else { | ||
119 | // sourceObject.eSet(referenceType,targetObject) | ||
120 | // } | ||
121 | // } | ||
122 | // } | ||
123 | |||
124 | protected dispatch def Map<? extends Object, ? extends TermDescription> getAllElementsOfDatatype(EEnum type, Ecore2Logic_Trace forwardTrace, LogicModelInterpretation interpretation) { | ||
125 | ecore2Logic.allLiteralsInScope(forwardTrace).toInvertedMap[ecore2Logic.Literal(forwardTrace,it)] | ||
126 | } | 123 | } |
127 | 124 | ||
128 | protected dispatch def Map<? extends Object, ? extends TermDescription> getAllElementsOfDatatype(EDataType primitive, Ecore2Logic_Trace forwardTrace, LogicModelInterpretation interpretation) { | 125 | protected dispatch def Map<? extends TermDescription, ? extends Object> getAllElementsOfDatatype(EDataType primitive, Ecore2Logic_Trace forwardTrace, LogicModelInterpretation interpretation) { |
129 | val extension LogicProblemBuilder b = new LogicProblemBuilder | 126 | val extension LogicProblemBuilder b = new LogicProblemBuilder |
130 | if(primitive === EcorePackage.eINSTANCE.EInt || primitive === EcorePackage.eINSTANCE.EShort || primitive === EcorePackage.eINSTANCE.ELong) { | 127 | if(primitive === EcorePackage.eINSTANCE.EInt || primitive === EcorePackage.eINSTANCE.EShort || primitive === EcorePackage.eINSTANCE.ELong) { |
131 | interpretation.allIntegersInStructure.toInvertedMap[it.asTerm] | 128 | interpretation.allIntegersWithInterpretation |
132 | } else if(primitive === EcorePackage.eINSTANCE.EDouble || primitive === EcorePackage.eINSTANCE.EFloat) { | 129 | } else if(primitive === EcorePackage.eINSTANCE.EDouble || primitive === EcorePackage.eINSTANCE.EFloat) { |
133 | interpretation.allRealsInStructure.toInvertedMap[it.asTerm] | 130 | interpretation.allRealsWithInterpretation |
134 | } else if(primitive === EcorePackage.eINSTANCE.EString) { | 131 | } else if(primitive === EcorePackage.eINSTANCE.EString) { |
135 | interpretation.allStringsInStructure.toInvertedMap[it.asTerm] | 132 | interpretation.allStringsWithInterpretation |
136 | } else if(primitive === EcorePackage.eINSTANCE.EBoolean) { | 133 | } else if(primitive === EcorePackage.eINSTANCE.EBoolean) { |
137 | return #[false,true].toInvertedMap[it.asTerm] | 134 | interpretation.allBooleansWithInterpretation |
138 | } | 135 | } |
139 | } | 136 | } |
140 | 137 | ||