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.xtend108
1 files changed, 78 insertions, 30 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 94959025..f2f43aaa 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
@@ -3,6 +3,7 @@ package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic
3import com.google.common.collect.ImmutableList 3import com.google.common.collect.ImmutableList
4import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic 4import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic
5import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace 5import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace
6import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicSolverConfiguration
6import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput 7import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput
7import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes 8import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes
8import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement 9import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement
@@ -33,7 +34,8 @@ class InstanceModel2PartialInterpretation {
33 34
34 public def transform( 35 public def transform(
35 TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult, 36 TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult,
36 Resource resource, 37 Map<String, Map<String, String>> ignoredAttribs,
38 Resource resource,
37 boolean withID) 39 boolean withID)
38 { 40 {
39 val objectsBuilder = ImmutableList.builder 41 val objectsBuilder = ImmutableList.builder
@@ -49,11 +51,12 @@ class InstanceModel2PartialInterpretation {
49 } 51 }
50 } 52 }
51 val objects = objectsBuilder.build 53 val objects = objectsBuilder.build
52 return transform(metamodelTranslationResult,objects,withID) 54 return transform(metamodelTranslationResult, ignoredAttribs, objects, withID)
53 } 55 }
54 56
55 public def transform( 57 public def transform(
56 TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult, 58 TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult,
59 Map<String, Map<String, String>> ignoredAttribs,
57 List<EObject> objects, 60 List<EObject> objects,
58 boolean withID) 61 boolean withID)
59 { 62 {
@@ -63,7 +66,7 @@ class InstanceModel2PartialInterpretation {
63 val referencesUsed = ecore2Logic.allReferencesInScope(ecore2LogicTrace).toSet 66 val referencesUsed = ecore2Logic.allReferencesInScope(ecore2LogicTrace).toSet
64 val attributesUsed = ecore2Logic.allAttributesInScope(ecore2LogicTrace).toSet 67 val attributesUsed = ecore2Logic.allAttributesInScope(ecore2LogicTrace).toSet
65 68
66 val typeScope = createTypeScopesFromKnownAttributeValues(objects,attributesUsed) 69 val typeScope = createTypeScopesFromKnownAttributeValues(objects,attributesUsed, ignoredAttribs)
67 val tracedOutput = partialInterpretationInitialiser.initialisePartialInterpretation(problem, typeScope) 70 val tracedOutput = partialInterpretationInitialiser.initialisePartialInterpretation(problem, typeScope)
68 val partialInterpretation = tracedOutput.output 71 val partialInterpretation = tracedOutput.output
69 val partialInterpretationTrace = tracedOutput.trace 72 val partialInterpretationTrace = tracedOutput.trace
@@ -119,23 +122,26 @@ class InstanceModel2PartialInterpretation {
119 122
120 // Transforming the attributes 123 // Transforming the attributes
121 for(attribute : source.eClass.EAllAttributes.filter[attributesUsed.contains(it) && !it.derived]) { 124 for(attribute : source.eClass.EAllAttributes.filter[attributesUsed.contains(it) && !it.derived]) {
122 val type = ecore2Logic.relationOfAttribute(ecore2LogicTrace,attribute) 125 val isIgnored = checkIfIgnored(source, attribute, ignoredAttribs)
123 val interpretation = type.lookup(partialInterpretationTrace.relation2Interpretation) 126 if (!isIgnored) {
124 val sourceElement = source.lookup(object2DefinedElement) 127 val type = ecore2Logic.relationOfAttribute(ecore2LogicTrace,attribute)
125 if(attribute.isMany) { 128 val interpretation = type.lookup(partialInterpretationTrace.relation2Interpretation)
126 val listOfTargets = source.eGet(attribute) as List<? extends EObject> 129 val sourceElement = source.lookup(object2DefinedElement)
127 for(target : listOfTargets) { 130 if(attribute.isMany) {
128 val value = translateValue(target,ecore2LogicTrace,partialInterpretationTrace) 131 val listOfTargets = source.eGet(attribute) as List<? extends EObject>
129 if(value !== null) { 132 for(target : listOfTargets) {
130 translateLink(interpretation,sourceElement,value) 133 val value = translateValue(target,ecore2LogicTrace,partialInterpretationTrace)
134 if(value !== null) {
135 translateLink(interpretation,sourceElement,value)
136 }
131 } 137 }
132 } 138 } else {
133 } else { 139 val target = source.eGet(attribute)
134 val target = source.eGet(attribute) 140 if(target !== null) {
135 if(target !== null) { 141 val value = translateValue(target,ecore2LogicTrace,partialInterpretationTrace)
136 val value = translateValue(target,ecore2LogicTrace,partialInterpretationTrace) 142 if(value !== null) {
137 if(value !== null) { 143 translateLink(interpretation,sourceElement,value)
138 translateLink(interpretation,sourceElement,value) 144 }
139 } 145 }
140 } 146 }
141 } 147 }
@@ -144,21 +150,29 @@ class InstanceModel2PartialInterpretation {
144 150
145 return partialInterpretation 151 return partialInterpretation
146 } 152 }
147 153
148 private def createTypeScopesFromKnownAttributeValues(List<EObject> objects, Set<EAttribute> attributesUsed) { 154 private def createTypeScopesFromKnownAttributeValues(
155 List<EObject> objects,
156 Set<EAttribute> attributesUsed,
157 Map<String, Map<String, String>> ignoredAttribs)
158 {
149 val Set<Integer> integers = new HashSet 159 val Set<Integer> integers = new HashSet
150 val Set<Double> reals = new HashSet 160 val Set<Double> reals = new HashSet
151 val Set<String> strings = new HashSet 161 val Set<String> strings = new HashSet
152 for(object: objects) { 162 for (object : objects) {
153 for(attribute : object.eClass.EAllAttributes.filter[attributesUsed.contains(it)]) { 163 for (attribute : object.eClass.EAllAttributes.filter[attributesUsed.contains(it)]) {
154 val value = object.eGet(attribute) 164 val isIgnored = checkIfIgnored(object, attribute, ignoredAttribs)
155 if(value !== null) { 165
156 if(value instanceof List<?>) { 166 if(!isIgnored) {
157 for(v : value) { 167 val value = object.eGet(attribute)
158 shortValue(v,integers,reals,strings) 168 if(value !== null) {
169 if(value instanceof List<?>) {
170 for(v : value) {
171 shortValue(v,integers,reals,strings)
172 }
173 } else {
174 shortValue(value,integers,reals,strings)
159 } 175 }
160 } else {
161 shortValue(value,integers,reals,strings)
162 } 176 }
163 } 177 }
164 } 178 }
@@ -169,6 +183,40 @@ class InstanceModel2PartialInterpretation {
169 it.knownStrings += strings 183 it.knownStrings += strings
170 ] 184 ]
171 } 185 }
186 private def boolean checkIfIgnored(
187 EObject object,
188 EAttribute attribute,
189 Map<String, Map<String, String>> ignoredAttribs
190 ) {
191 val classInIgnored = ignoredAttribs.get(object.eClass.name)
192 val mayIgnored = (
193 classInIgnored !== null && classInIgnored.containsKey(attribute.name))
194
195 var isIgnored = false
196 if (mayIgnored) {
197 val specificIgnoredValue = classInIgnored.get(attribute.name)
198 if (specificIgnoredValue.equals("*"))
199 isIgnored = true
200 else {
201 val value = object.eGet(attribute)
202 if (typeof(Number).isAssignableFrom(value.class)) {
203 isIgnored = (Double.valueOf(specificIgnoredValue) == value)
204 } else {
205 isIgnored = specificIgnoredValue.equals(value)
206 }
207 }
208 }
209 // DEBUG
210// println("DEBUG BEGINNING")
211// println(object)
212// println(attribute)
213// println(value)
214//
215// println("MAYIGNORE " + mayIgnored)
216// println("ISIGNORED " + isIgnored)
217 // END DEBUG
218 return isIgnored
219 }
172 private def dispatch shortValue(Boolean value, Set<Integer> integers, Set<Double> reals, Set<String> strings) { 220 private def dispatch shortValue(Boolean value, Set<Integer> integers, Set<Double> reals, Set<String> strings) {
173 // Do nothing 221 // Do nothing
174 } 222 }