aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver
diff options
context:
space:
mode:
authorLibravatar OszkarSemerath <oszka@152.66.252.189>2017-06-10 19:05:05 +0200
committerLibravatar OszkarSemerath <oszka@152.66.252.189>2017-06-10 19:05:05 +0200
commit60f01f46ba232ed6416054f0a6115cb2a9b70b4e (patch)
tree5edf8aeb07abc51f3fec63bbd15c926e1de09552 /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver
parentInitial commit, migrating from SVN (diff)
downloadVIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.tar.gz
VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.tar.zst
VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.zip
Migrating Additional projects
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver')
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend21
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend130
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend146
3 files changed, 297 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend
new file mode 100644
index 00000000..2910a702
--- /dev/null
+++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend
@@ -0,0 +1,21 @@
1package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic
2
3import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace
4import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput
5import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
6import java.util.List
7import org.eclipse.emf.ecore.EObject
8
9class InstanceModel2Logic {
10 val InstanceModel2PartialInterpretation instanceModel2PartialInterpretation = new InstanceModel2PartialInterpretation
11 val PartialInterpretation2Logic partialInterpretation2Logic = new PartialInterpretation2Logic
12
13 public def transform(
14 TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult,
15 List<EObject> objects)
16 {
17 val res1 = this.instanceModel2PartialInterpretation.transform(metamodelTranslationResult,objects,true)
18 this.partialInterpretation2Logic.transformPartialIntepretation2Logic(metamodelTranslationResult.output,res1)
19 return metamodelTranslationResult//.output
20 }
21} \ No newline at end of file
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend
new file mode 100644
index 00000000..58c41a49
--- /dev/null
+++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend
@@ -0,0 +1,130 @@
1package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic
2
3import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic
4import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace
5import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement
6import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory
7import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDeclaration
8import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
9import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.PartialInterpretationInitialiser
10import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.Problem2PartialInterpretationTrace
11import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation
12import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationFactory
13import java.util.HashMap
14import java.util.List
15import java.util.Map
16import org.eclipse.emf.common.util.Enumerator
17import org.eclipse.emf.ecore.EObject
18
19import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
20import org.eclipse.emf.ecore.resource.Resource
21import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput
22
23class InstanceModel2PartialInterpretation {
24 val extension LogiclanguageFactory factory = LogiclanguageFactory.eINSTANCE
25 val extension PartialinterpretationFactory factory2 = PartialinterpretationFactory.eINSTANCE
26 val Ecore2Logic ecore2Logic = new Ecore2Logic
27 val partialInterpretationInitialiser = new PartialInterpretationInitialiser
28
29 public def transform(
30 TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult,
31 Resource resource,
32 boolean withID)
33 {
34 val objects = resource.allContents.toList
35 return transform(metamodelTranslationResult,objects,withID)
36 }
37
38 public def transform(
39 TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult,
40 List<EObject> objects,
41 boolean withID)
42 {
43 val problem = metamodelTranslationResult.output
44 val ecore2LogicTrace = metamodelTranslationResult.trace
45 val tracedOutput = partialInterpretationInitialiser.initialisePartialInterpretation(problem, -1, -1)
46 val partialInterpretation = tracedOutput.output
47 val partialInterpretationTrace = tracedOutput.trace
48
49 val Map<EObject,DefinedElement> object2DefinedElement = new HashMap
50
51 // EObject -> DefinedElement
52 for(objectIndex : 0..<objects.size) {
53 val object = objects.get(objectIndex)
54 val element = createDefinedElement => [
55 it.name = if(withID)
56 { '''PartialObject«objectIndex»''' } else
57 { null }
58 ]
59
60 // Add element to interpretation
61 partialInterpretation.newElements += element
62
63 // Define the types
64 val type = ecore2Logic.TypeofEClass(ecore2LogicTrace,object.eClass) as TypeDeclaration
65 val interpretation = type.lookup(partialInterpretationTrace.type2Interpretation)
66 interpretation.elements += element
67 interpretation.supertypeInterpretation.forEach[elements += element]
68
69 // Trace handling
70 object2DefinedElement.put(object, element)
71 }
72
73 for(source : objects) {
74 // Translating the references
75 for(reference : source.eClass.EAllReferences) {
76 val type = ecore2Logic.relationOfReference(ecore2LogicTrace,reference)
77 val interpretation = type.lookup(partialInterpretationTrace.relation2Interpretation)
78 val sourceElement = source.lookup(object2DefinedElement)
79 if(reference.isMany) {
80 val listOfTargets = source.eGet(reference) as List<? extends EObject>
81 for(target : listOfTargets) {
82 val targetElement = target.lookup(object2DefinedElement)
83 translateLink(interpretation,sourceElement,targetElement)
84 }
85 } else {
86 val target = source.eGet(reference) as EObject
87 val targetElement = target.lookup(object2DefinedElement)
88 if(target !== null) {
89 translateLink(interpretation,sourceElement,targetElement)
90 }
91 }
92 }
93 // Transforming the relations
94 for(attribute : source.eClass.EAllAttributes) {
95 val type = ecore2Logic.relationOfAttribute(ecore2LogicTrace,attribute)
96 val interpretation = type.lookup(partialInterpretationTrace.relation2Interpretation)
97 val sourceElement = source.lookup(object2DefinedElement)
98 if(attribute.isMany) {
99 val listOfTargets = source.eGet(attribute) as List<? extends EObject>
100 for(target : listOfTargets) {
101 translateLink(interpretation,sourceElement,translateValue(target,ecore2LogicTrace,partialInterpretationTrace))
102 }
103 } else {
104 val target = source.eGet(attribute)
105 if(target !== null) {
106 translateLink(interpretation,sourceElement,translateValue(target,ecore2LogicTrace,partialInterpretationTrace))
107 }
108 }
109 }
110 }
111
112 return partialInterpretation
113 }
114
115 protected def translateLink(PartialRelationInterpretation interpretation, DefinedElement source, DefinedElement target) {
116 interpretation.relationlinks += createBinaryElementRelationLink => [it.param1 = source it.param2 = target]
117 }
118
119 dispatch protected def translateValue(Enumerator value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) {
120 val term = this.ecore2Logic.Literal(ecore2LogicTrace,value)
121 if(term instanceof DefinedElement) {
122 return term
123 }
124 else throw new AssertionError('''term should be a defined element?''')
125 }
126
127 dispatch protected def translateValue(Object value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) {
128 throw new UnsupportedOperationException('''Mapping of «value.class.simpleName» in partial models is currently not supported!''')
129 }
130} \ No newline at end of file
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend
new file mode 100644
index 00000000..39d8a365
--- /dev/null
+++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend
@@ -0,0 +1,146 @@
1package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic
2
3import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder
4import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory
5import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.SymbolicDeclaration
6import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type
7import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDeclaration
8import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition
9import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
10import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink
11import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation
12import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation
13import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialTypeInterpratation
14import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RelationLink
15import java.util.ArrayList
16import java.util.HashMap
17import java.util.HashSet
18import java.util.Map
19import java.util.Set
20import org.eclipse.xtend.lib.annotations.Data
21
22import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
23
24@Data class PartialInterpretation2Logic_Trace {
25 Map<TypeDeclaration, TypeDefinition> definedPart = new HashMap
26 Map<TypeDeclaration, TypeDeclaration> undefinedPart = new HashMap
27 Set<Type> originalTypes = new HashSet
28 Set<TypeDeclaration> splittedTypes = new HashSet
29}
30
31class PartialInterpretation2Logic {
32 val extension LogiclanguageFactory factory = LogiclanguageFactory.eINSTANCE
33 val extension LogicProblemBuilder builder = new LogicProblemBuilder
34
35 def transformPartialIntepretation2Logic(LogicProblem p, PartialInterpretation i) {
36 val trace = new PartialInterpretation2Logic_Trace()
37 trace.originalTypes.addAll(p.types)
38 if(! i.newElements.empty) {
39
40 // Elements adding
41 addExistingElementToProblem(p,i)
42
43 // Types
44 for(partialTypeDeclaration : i.partialtypeinterpratation) {
45 splitTypeIntoTwo(p,partialTypeDeclaration,trace)
46 }
47 connectSplittings(p,trace)
48
49 // Relations
50 for(partialRelationInterpretation : i.partialrelationinterpretation) {
51 relationLinksToAssertion(p,partialRelationInterpretation,trace)
52 }
53 }
54 }
55
56 private def addExistingElementToProblem(LogicProblem p, PartialInterpretation i) {
57 val newElements = new ArrayList(i.newElements)
58 var newElementIndex = 1
59 for(newElement : newElements) {
60 newElement.name = '''DefinedElement «newElementIndex++»'''
61 p.elements += newElement
62 }
63 }
64
65 private def splitTypeIntoTwo(LogicProblem p, PartialTypeInterpratation partialTypeDeclaration,PartialInterpretation2Logic_Trace trace) {
66 if(!partialTypeDeclaration.elements.empty) {
67 val declaration = partialTypeDeclaration.interpretationOf
68
69 val definedPart = createTypeDefinition => [
70 it.name = '''DefinedPartOf «declaration.name»'''
71 it.elements += partialTypeDeclaration.elements
72 it.isAbstract = declaration.isIsAbstract
73 ]
74 val undefinedPart = createTypeDeclaration => [
75 it.name = '''UndefinedPartOf «declaration.name»'''
76 it.isAbstract = declaration.isIsAbstract
77 ]
78 declaration.isAbstract = true
79
80 trace.definedPart.put(declaration,definedPart)
81 trace.undefinedPart.put(declaration,undefinedPart)
82 trace.splittedTypes.add(declaration)
83 p.add(definedPart)
84 p.add(undefinedPart)
85 Supertype(definedPart,declaration)
86 Supertype(undefinedPart,declaration)
87 }
88 }
89
90 private def connectSplittings(LogicProblem p,PartialInterpretation2Logic_Trace trace) {
91 val originalTypes = p.types.filter[originalType(trace)].toList
92 for(type : originalTypes) {
93 val superTypes = new ArrayList(type.supertypes.filter[originalType(trace)].toList)
94 for(supertype : superTypes) {
95 if(type.isSplitted(trace)) {
96 if(supertype.isSplitted(trace)) {
97 Supertype((type as TypeDeclaration).lookup(trace.definedPart), (supertype as TypeDeclaration).lookup(trace.definedPart))
98 Supertype((type as TypeDeclaration).lookup(trace.undefinedPart), (supertype as TypeDeclaration).lookup(trace.undefinedPart))
99 } else {
100 // Do nothing
101 }
102 } else {
103 if(supertype.isSplitted(trace)) {
104 Supertype(type, (supertype as TypeDeclaration).lookup(trace.undefinedPart))
105 } else if(supertype instanceof TypeDefinition) {
106 // Do nothing
107 }
108 }
109 }
110 }
111 }
112
113 private def originalType(Type type,PartialInterpretation2Logic_Trace trace) {
114 return trace.originalTypes.contains(type)
115 }
116 private def isSplitted(Type t, PartialInterpretation2Logic_Trace trace) {
117 trace.splittedTypes.contains(t)
118 }
119
120 private def relationLinksToAssertion(LogicProblem p, PartialRelationInterpretation r,PartialInterpretation2Logic_Trace trace) {
121 val relation = r.interpretationOf
122 val links = r.relationlinks
123 if(links.size == 0) {
124 return
125 } else {
126 val term = if(links.size == 1) {
127 createLink(links.head,relation)
128 } else {
129 links.map[link|createLink(link,relation)].And
130 }
131 val assertion = Assertion('''PartialInterpretation «r.interpretationOf.name»''',term)
132 p.add(assertion)
133 }
134
135 }
136
137 def private createLink(RelationLink link, SymbolicDeclaration relationDeclaration) {
138 if(link instanceof BinaryElementRelationLink) {
139 return createSymbolicValue=>[
140 it.symbolicReference=relationDeclaration
141 it.parameterSubstitutions += createSymbolicValue => [link.param1]
142 it.parameterSubstitutions += createSymbolicValue => [link.param2]
143 ]
144 } else throw new UnsupportedOperationException
145 }
146} \ No newline at end of file