aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend
diff options
context:
space:
mode:
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend')
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend81
1 files changed, 75 insertions, 6 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend
index f4fc1fce..bd0f4ca4 100644
--- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend
+++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend
@@ -20,6 +20,10 @@ import org.eclipse.emf.ecore.EObject
20import org.eclipse.emf.ecore.resource.Resource 20import org.eclipse.emf.ecore.resource.Resource
21 21
22import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* 22import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.*
23import java.util.HashSet
24import java.util.Set
25import java.math.BigDecimal
26import org.eclipse.emf.ecore.EAttribute
23 27
24class InstanceModel2PartialInterpretation { 28class InstanceModel2PartialInterpretation {
25 val extension LogiclanguageFactory factory = LogiclanguageFactory.eINSTANCE 29 val extension LogiclanguageFactory factory = LogiclanguageFactory.eINSTANCE
@@ -43,7 +47,12 @@ class InstanceModel2PartialInterpretation {
43 { 47 {
44 val problem = metamodelTranslationResult.output 48 val problem = metamodelTranslationResult.output
45 val ecore2LogicTrace = metamodelTranslationResult.trace 49 val ecore2LogicTrace = metamodelTranslationResult.trace
46 val tracedOutput = partialInterpretationInitialiser.initialisePartialInterpretation(problem, new TypeScopes) 50
51 val referencesUsed = ecore2Logic.allReferencesInScope(ecore2LogicTrace).toSet
52 val attributesUsed = ecore2Logic.allAttributesInScope(ecore2LogicTrace).toSet
53
54 val typeScope = createTypeScopesFromKnownAttributeValues(objects,attributesUsed)
55 val tracedOutput = partialInterpretationInitialiser.initialisePartialInterpretation(problem, typeScope)
47 val partialInterpretation = tracedOutput.output 56 val partialInterpretation = tracedOutput.output
48 val partialInterpretationTrace = tracedOutput.trace 57 val partialInterpretationTrace = tracedOutput.trace
49 58
@@ -54,7 +63,7 @@ class InstanceModel2PartialInterpretation {
54 val object = objects.get(objectIndex) 63 val object = objects.get(objectIndex)
55 val element = createDefinedElement => [ 64 val element = createDefinedElement => [
56 it.name = if(withID) 65 it.name = if(withID)
57 { '''o «objectIndex»''' } else 66 { '''o «objectIndex+1»''' } else
58 { null } 67 { null }
59 ] 68 ]
60 69
@@ -71,8 +80,6 @@ class InstanceModel2PartialInterpretation {
71 object2DefinedElement.put(object, element) 80 object2DefinedElement.put(object, element)
72 } 81 }
73 82
74 val referencesUsed = ecore2Logic.allReferencesInScope(ecore2LogicTrace).toSet
75 val attributesUsed = ecore2Logic.allAttributesInScope(ecore2LogicTrace).toSet
76 for(source : objects) { 83 for(source : objects) {
77 // Translating the references 84 // Translating the references
78 for(reference : source.eClass.EAllReferences.filter[ 85 for(reference : source.eClass.EAllReferences.filter[
@@ -126,6 +133,52 @@ class InstanceModel2PartialInterpretation {
126 return partialInterpretation 133 return partialInterpretation
127 } 134 }
128 135
136 private def createTypeScopesFromKnownAttributeValues(List<EObject> objects, Set<EAttribute> attributesUsed) {
137 val Set<Integer> integers = new HashSet
138 val Set<BigDecimal> reals = new HashSet
139 val Set<String> strings = new HashSet
140 for(object: objects) {
141 for(attribute : object.eClass.EAllAttributes.filter[attributesUsed.contains(it)]) {
142 val value = object.eGet(attribute)
143 if(value !== null) {
144 if(value instanceof List<?>) {
145 for(v : value) {
146 shortValue(v,integers,reals,strings)
147 }
148 } else {
149 shortValue(value,integers,reals,strings)
150 }
151 }
152 }
153 }
154 return new TypeScopes => [
155 it.knownIntegers += integers
156 it.knownReals += reals
157 it.knownStrings += strings
158 ]
159 }
160 private def dispatch shortValue(Boolean value, Set<Integer> integers, Set<BigDecimal> reals, Set<String> strings) {
161 // Do nothing
162 }
163 private def dispatch shortValue(Integer value, Set<Integer> integers, Set<BigDecimal> reals, Set<String> strings) {
164 integers += value
165 }
166 private def dispatch shortValue(Float value, Set<Integer> integers, Set<BigDecimal> reals, Set<String> strings) {
167 reals += BigDecimal.valueOf(value)
168 }
169 private def dispatch shortValue(Double value, Set<Integer> integers, Set<BigDecimal> reals, Set<String> strings) {
170 reals += BigDecimal.valueOf(value)
171 }
172 private def dispatch shortValue(String value, Set<Integer> integers, Set<BigDecimal> reals, Set<String> strings) {
173 strings += value
174 }
175 private def dispatch shortValue(Void value, Set<Integer> integers, Set<BigDecimal> reals, Set<String> strings) {
176 // Do nothing
177 }
178 private def dispatch shortValue(Object value, Set<Integer> integers, Set<BigDecimal> reals, Set<String> strings) {
179 // Do nothing
180 }
181
129 protected def translateLink(PartialRelationInterpretation interpretation, DefinedElement source, DefinedElement target) { 182 protected def translateLink(PartialRelationInterpretation interpretation, DefinedElement source, DefinedElement target) {
130 interpretation.relationlinks += createBinaryElementRelationLink => [it.param1 = source it.param2 = target] 183 interpretation.relationlinks += createBinaryElementRelationLink => [it.param1 = source it.param2 = target]
131 } 184 }
@@ -138,7 +191,23 @@ class InstanceModel2PartialInterpretation {
138 else throw new AssertionError('''term should be a defined element?''') 191 else throw new AssertionError('''term should be a defined element?''')
139 } 192 }
140 193
141 dispatch protected def translateValue(Object value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) { 194 dispatch protected def translateValue(Boolean value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) {
142 //throw new UnsupportedOperationException('''Mapping of «value.class.simpleName» in partial models is currently not supported!''') 195 value.lookup(partialInterpretationTrace.primitiveValues.booleanMap)
196 }
197
198 dispatch protected def translateValue(Integer value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) {
199 value.lookup(partialInterpretationTrace.primitiveValues.integerMap)
200 }
201
202 dispatch protected def translateValue(Double value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) {
203 BigDecimal.valueOf(value).lookup(partialInterpretationTrace.primitiveValues.realMap)
204 }
205
206 dispatch protected def translateValue(Float value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) {
207 BigDecimal.valueOf(value).lookup(partialInterpretationTrace.primitiveValues.realMap)
208 }
209
210 dispatch protected def translateValue(String value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) {
211 value.lookup(partialInterpretationTrace.primitiveValues.stringMap)
143 } 212 }
144} \ No newline at end of file 213} \ No newline at end of file