diff options
author | 2017-06-21 21:19:27 +0200 | |
---|---|---|
committer | 2017-06-21 21:19:27 +0200 | |
commit | bd9d6001d6d288b98f20ba2b4886a147088a6f99 (patch) | |
tree | b0b93dd8de27642afe86cdc9e849c49e7ec7202b /Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src | |
parent | Model translator and sanitiser from original yakindu files to simplified (diff) | |
download | VIATRA-Generator-bd9d6001d6d288b98f20ba2b4886a147088a6f99.tar.gz VIATRA-Generator-bd9d6001d6d288b98f20ba2b4886a147088a6f99.tar.zst VIATRA-Generator-bd9d6001d6d288b98f20ba2b4886a147088a6f99.zip |
Logic interpretation -> standard EMF instance model
Diffstat (limited to 'Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src')
-rw-r--r-- | Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend | 91 |
1 files changed, 91 insertions, 0 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 new file mode 100644 index 00000000..2ab7091e --- /dev/null +++ b/Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend | |||
@@ -0,0 +1,91 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.logic2ecore | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicStructureBuilder | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder | ||
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicModelInterpretation | ||
9 | import java.util.HashSet | ||
10 | import java.util.HashMap | ||
11 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | ||
12 | import org.eclipse.emf.ecore.EClass | ||
13 | import java.util.Set | ||
14 | import org.eclipse.emf.ecore.EObject | ||
15 | import java.util.List | ||
16 | import java.util.Collection | ||
17 | |||
18 | class Logic2Ecore { | ||
19 | private val extension LogicProblemBuilder problemBuilder = new LogicProblemBuilder | ||
20 | private val extension LogicStructureBuilder structureBuilder = new LogicStructureBuilder | ||
21 | val Ecore2Logic ecore2Logic; | ||
22 | |||
23 | new (Ecore2Logic ecore2Logic) { | ||
24 | this.ecore2Logic = ecore2Logic | ||
25 | } | ||
26 | |||
27 | def transformInterpretation(LogicModelInterpretation interpretation, Ecore2Logic_Trace forwardTrace) { | ||
28 | val allClasses = ecore2Logic.allClassesInScope(forwardTrace) | ||
29 | val elements = new HashSet | ||
30 | val element2Classes = new HashMap | ||
31 | |||
32 | |||
33 | for(clazz: allClasses) { | ||
34 | val type = ecore2Logic.TypeofEClass(forwardTrace,clazz); | ||
35 | val elementsOfClass = getElements(interpretation,type) | ||
36 | for(element : elementsOfClass) { | ||
37 | elements += element | ||
38 | element2Classes.putOrAddToSet(element,clazz) | ||
39 | } | ||
40 | } | ||
41 | |||
42 | val element2Object = new HashMap | ||
43 | for(element: elements) { | ||
44 | val clazz = element.lookup(element2Classes).mostConcreteType | ||
45 | val eobject = clazz.EPackage.EFactoryInstance.create(clazz) | ||
46 | element2Object.put(element,eobject) | ||
47 | } | ||
48 | |||
49 | val allReferences = ecore2Logic.allReferencesInScope(forwardTrace) | ||
50 | for(referenceType : allReferences) { | ||
51 | for(sourceElement : elements) { | ||
52 | val sourceObject = sourceElement.lookup(element2Object) | ||
53 | if(sourceObject.eClass.isSuperTypeOf(referenceType.EContainingClass)) { | ||
54 | for(targetElement: elements) { | ||
55 | val targetObject = targetElement.lookup(element2Object) | ||
56 | if(targetObject.eClass.isSuperTypeOf(referenceType.EReferenceType)) { | ||
57 | val expression = ecore2Logic.IsInReference(forwardTrace,sourceElement,targetElement,referenceType) | ||
58 | val linkExist = interpretation.evalAsBool(expression) | ||
59 | if(linkExist) { | ||
60 | if(referenceType.isMany) { | ||
61 | val list = sourceObject.eGet(referenceType) as List<? super EObject> | ||
62 | list+= targetObject | ||
63 | } else { | ||
64 | sourceObject.eSet(referenceType,targetObject) | ||
65 | } | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | |||
73 | /// Attributes | ||
74 | |||
75 | return element2Object.values.root | ||
76 | } | ||
77 | |||
78 | def mostConcreteType(Set<EClass> classes) { | ||
79 | for(candidate : classes) { | ||
80 | val subtypeOfAll = classes.forall[it.isSuperTypeOf(candidate)] | ||
81 | if(subtypeOfAll) { | ||
82 | return candidate | ||
83 | } | ||
84 | } | ||
85 | throw new AssertionError("Object has no unique concrete type!") | ||
86 | } | ||
87 | |||
88 | def getRoot(Collection<EObject> objects) { | ||
89 | objects.filter[eContainer === null].head | ||
90 | } | ||
91 | } \ No newline at end of file | ||