diff options
author | 2018-07-16 18:25:34 +0200 | |
---|---|---|
committer | 2018-07-16 18:25:34 +0200 | |
commit | 59a53fc819355fb2809b23544a5ca19ffff802fb (patch) | |
tree | e67cba5ca12cfbba7d2dc68e6c07fe36c996e3f2 /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic | |
parent | Support for building float, double and BigDecimal literals (diff) | |
download | VIATRA-Generator-59a53fc819355fb2809b23544a5ca19ffff802fb.tar.gz VIATRA-Generator-59a53fc819355fb2809b23544a5ca19ffff802fb.tar.zst VIATRA-Generator-59a53fc819355fb2809b23544a5ca19ffff802fb.zip |
Scope support for attributes
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic')
2 files changed, 94 insertions, 9 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 | |||
20 | import org.eclipse.emf.ecore.resource.Resource | 20 | import org.eclipse.emf.ecore.resource.Resource |
21 | 21 | ||
22 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 22 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
23 | import java.util.HashSet | ||
24 | import java.util.Set | ||
25 | import java.math.BigDecimal | ||
26 | import org.eclipse.emf.ecore.EAttribute | ||
23 | 27 | ||
24 | class InstanceModel2PartialInterpretation { | 28 | class 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 |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend index 5d8d9313..bba4ae92 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend | |||
@@ -24,6 +24,9 @@ import org.eclipse.xtend.lib.annotations.Data | |||
24 | 24 | ||
25 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 25 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
26 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement | 26 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement |
27 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BooleanElement | ||
28 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement | ||
29 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RealElement | ||
27 | 30 | ||
28 | @Data class PartialInterpretation2Logic_Trace { | 31 | @Data class PartialInterpretation2Logic_Trace { |
29 | Map<DefinedElement,DefinedElement> new2Old = new HashMap | 32 | Map<DefinedElement,DefinedElement> new2Old = new HashMap |
@@ -148,7 +151,7 @@ class PartialInterpretation2Logic { | |||
148 | val ^annotation= Partial2logicannotationsFactory.eINSTANCE.createPartialModelRelation2Assertion | 151 | val ^annotation= Partial2logicannotationsFactory.eINSTANCE.createPartialModelRelation2Assertion |
149 | ^annotation.target = assertion | 152 | ^annotation.target = assertion |
150 | ^annotation.targetRelation = relation | 153 | ^annotation.targetRelation = relation |
151 | ^annotation.links += links.map[EcoreUtil.copy(it)] | 154 | //^annotation.links += links.map[EcoreUtil.copy(it)] |
152 | //val error= assertion.eAllContents.toIterable.filter(SymbolicValue).filter[it.symbolicReference === null] | 155 | //val error= assertion.eAllContents.toIterable.filter(SymbolicValue).filter[it.symbolicReference === null] |
153 | //error.forEach[println("error")] | 156 | //error.forEach[println("error")] |
154 | p.add(assertion) | 157 | p.add(assertion) |
@@ -162,12 +165,25 @@ class PartialInterpretation2Logic { | |||
162 | if((link.param1 !== null) && (link.param2 !== null)) { | 165 | if((link.param1 !== null) && (link.param2 !== null)) { |
163 | return createSymbolicValue=>[ | 166 | return createSymbolicValue=>[ |
164 | it.symbolicReference=relationDeclaration | 167 | it.symbolicReference=relationDeclaration |
165 | it.parameterSubstitutions += createSymbolicValue => [it.symbolicReference = link.param1] | 168 | it.parameterSubstitutions += createValueInLink(link.param1) |
166 | it.parameterSubstitutions += createSymbolicValue => [it.symbolicReference = link.param2] | 169 | it.parameterSubstitutions += createValueInLink(link.param2) |
167 | ] | 170 | ] |
168 | } else { | 171 | } else { |
169 | throw new IllegalArgumentException | 172 | throw new IllegalArgumentException |
170 | } | 173 | } |
171 | } else throw new UnsupportedOperationException | 174 | } else throw new UnsupportedOperationException |
172 | } | 175 | } |
176 | |||
177 | def private dispatch createValueInLink(BooleanElement element) { | ||
178 | return element.value.asTerm | ||
179 | } | ||
180 | def private dispatch createValueInLink(IntegerElement element) { | ||
181 | return element.value.asTerm | ||
182 | } | ||
183 | def private dispatch createValueInLink(RealElement element) { | ||
184 | return element.value.asTerm | ||
185 | } | ||
186 | def private dispatch createValueInLink(DefinedElement element) { | ||
187 | return createSymbolicValue => [it.symbolicReference = element] | ||
188 | } | ||
173 | } \ No newline at end of file | 189 | } \ No newline at end of file |