diff options
author | 2020-05-20 02:07:37 +0200 | |
---|---|---|
committer | 2020-05-20 02:07:37 +0200 | |
commit | eb081453e93e6e30c0b6bb92400275529ed3273b (patch) | |
tree | aba071677812e49eb101a429f01f28aa4f58a226 /Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner | |
parent | FIx Boolean export to gml (diff) | |
download | VIATRA-Generator-eb081453e93e6e30c0b6bb92400275529ed3273b.tar.gz VIATRA-Generator-eb081453e93e6e30c0b6bb92400275529ed3273b.tar.zst VIATRA-Generator-eb081453e93e6e30c0b6bb92400275529ed3273b.zip |
Fix attribute export to xmi
Diffstat (limited to 'Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner')
-rw-r--r-- | Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend | 49 |
1 files changed, 17 insertions, 32 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 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 | |||
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 | import org.eclipse.emf.ecore.EAttribute | ||
24 | import java.math.BigDecimal | ||
25 | 24 | ||
26 | class Logic2Ecore { | 25 | class Logic2Ecore { |
27 | val extension LogicStructureBuilder structureBuilder = new LogicStructureBuilder | 26 | val extension LogicStructureBuilder structureBuilder = new LogicStructureBuilder |
@@ -86,15 +85,15 @@ class Logic2Ecore { | |||
86 | if(attributeType.EContainingClass.isSuperTypeOf(sourceObject.eClass)) { | 85 | if(attributeType.EContainingClass.isSuperTypeOf(sourceObject.eClass)) { |
87 | val allElementsOfTargetDatatype = getAllElementsOfDatatype(attributeType.EAttributeType,forwardTrace,interpretation) | 86 | val allElementsOfTargetDatatype = getAllElementsOfDatatype(attributeType.EAttributeType,forwardTrace,interpretation) |
88 | for(l : allElementsOfTargetDatatype.entrySet) { | 87 | for(l : allElementsOfTargetDatatype.entrySet) { |
89 | val expression = ecore2Logic.IsAttributeValue(forwardTrace,sourceElement,l.value,attributeType) | 88 | val expression = ecore2Logic.IsAttributeValue(forwardTrace,sourceElement,l.key,attributeType) |
90 | val linkExist = interpretation.evalAsBool(expression) | 89 | val linkExist = interpretation.evalAsBool(expression) |
91 | if(linkExist) { | 90 | if(linkExist) { |
92 | if(attributeType.isMany) { | 91 | if(attributeType.isMany) { |
93 | val list = sourceObject.eGet(attributeType) as List<? super Object> | 92 | val list = sourceObject.eGet(attributeType) as List<? super Object> |
94 | list += l.key | 93 | list += l.value |
95 | } else { | 94 | } else { |
96 | try { | 95 | try { |
97 | sourceObject.eSet(attributeType,translateType(attributeType.EAttributeType,l.key)) | 96 | sourceObject.eSet(attributeType,translateType(attributeType.EAttributeType,l.value)) |
98 | } catch(Exception e) { | 97 | } catch(Exception e) { |
99 | e.printStackTrace | 98 | e.printStackTrace |
100 | } | 99 | } |
@@ -119,34 +118,20 @@ class Logic2Ecore { | |||
119 | } else return value | 118 | } else return value |
120 | } | 119 | } |
121 | 120 | ||
122 | 121 | protected dispatch def Map<? extends TermDescription, ? extends Object> getAllElementsOfDatatype(EEnum type, Ecore2Logic_Trace forwardTrace, LogicModelInterpretation interpretation) { | |
123 | // if(attributeType.EAttributeType.isSuperTypeOf(targetObject.eClass)) { | 122 | ecore2Logic.allLiteralsInScope(forwardTrace).toMap[ecore2Logic.Literal(forwardTrace,it)] |
124 | // val expression = ecore2Logic.IsAttributeValue(forwardTrace,sourceElement,targetElement,attributeType) | ||
125 | // val linkExist = interpretation.evalAsBool(expression) | ||
126 | // if(linkExist) { | ||
127 | // if(attributeType.isMany) { | ||
128 | // val list = sourceObject.eGet(attributeType) as List<? super EObject> | ||
129 | // list+= targetObject | ||
130 | // } else { | ||
131 | // sourceObject.eSet(referenceType,targetObject) | ||
132 | // } | ||
133 | // } | ||
134 | // } | ||
135 | |||
136 | protected dispatch def Map<? extends Object, ? extends TermDescription> getAllElementsOfDatatype(EEnum type, Ecore2Logic_Trace forwardTrace, LogicModelInterpretation interpretation) { | ||
137 | ecore2Logic.allLiteralsInScope(forwardTrace).toInvertedMap[ecore2Logic.Literal(forwardTrace,it)] | ||
138 | } | 123 | } |
139 | 124 | ||
140 | 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) { |
141 | val extension LogicProblemBuilder b = new LogicProblemBuilder | 126 | val extension LogicProblemBuilder b = new LogicProblemBuilder |
142 | 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) { |
143 | interpretation.allIntegersInStructure.toInvertedMap[it.asTerm] | 128 | interpretation.allIntegersWithInterpretation |
144 | } else if(primitive === EcorePackage.eINSTANCE.EDouble || primitive === EcorePackage.eINSTANCE.EFloat) { | 129 | } else if(primitive === EcorePackage.eINSTANCE.EDouble || primitive === EcorePackage.eINSTANCE.EFloat) { |
145 | interpretation.allRealsInStructure.toInvertedMap[it.asTerm] | 130 | interpretation.allRealsWithInterpretation |
146 | } else if(primitive === EcorePackage.eINSTANCE.EString) { | 131 | } else if(primitive === EcorePackage.eINSTANCE.EString) { |
147 | interpretation.allStringsInStructure.toInvertedMap[it.asTerm] | 132 | interpretation.allStringsWithInterpretation |
148 | } else if(primitive === EcorePackage.eINSTANCE.EBoolean) { | 133 | } else if(primitive === EcorePackage.eINSTANCE.EBoolean) { |
149 | return #[false,true].toInvertedMap[it.asTerm] | 134 | interpretation.allBooleansWithInterpretation |
150 | } | 135 | } |
151 | } | 136 | } |
152 | 137 | ||