From 8ac747b1b84513c70f8445a7c84c6a3644a1f6fa Mon Sep 17 00:00:00 2001 From: Aren Babikian Date: Fri, 22 Jan 2021 00:50:08 +0100 Subject: implement ignored attribute values as a config option --- .../InstanceModel2Logic.xtend | 7 +- .../InstanceModel2PartialInterpretation.xtend | 108 +++++++++++++++------ 2 files changed, 82 insertions(+), 33 deletions(-) (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage') diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend index d2b59754..7cec6327 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend @@ -4,8 +4,8 @@ import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem import java.util.List +import java.util.Map import org.eclipse.emf.ecore.EObject -import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes class InstanceModel2Logic { val InstanceModel2PartialInterpretation instanceModel2PartialInterpretation = new InstanceModel2PartialInterpretation @@ -13,9 +13,10 @@ class InstanceModel2Logic { public def transform( TracedOutput metamodelTranslationResult, - List objects) + List objects, + Map> ignoredAttribs) { - val res1 = instanceModel2PartialInterpretation.transform(metamodelTranslationResult,objects,true) + val res1 = instanceModel2PartialInterpretation.transform(metamodelTranslationResult, ignoredAttribs, objects,true) this.partialInterpretation2Logic.transformPartialIntepretation2Logic(metamodelTranslationResult.output,res1) return metamodelTranslationResult//.output } 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 import com.google.common.collect.ImmutableList import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace +import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicSolverConfiguration import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement @@ -33,7 +34,8 @@ class InstanceModel2PartialInterpretation { public def transform( TracedOutput metamodelTranslationResult, - Resource resource, + Map> ignoredAttribs, + Resource resource, boolean withID) { val objectsBuilder = ImmutableList.builder @@ -49,11 +51,12 @@ class InstanceModel2PartialInterpretation { } } val objects = objectsBuilder.build - return transform(metamodelTranslationResult,objects,withID) + return transform(metamodelTranslationResult, ignoredAttribs, objects, withID) } public def transform( TracedOutput metamodelTranslationResult, + Map> ignoredAttribs, List objects, boolean withID) { @@ -63,7 +66,7 @@ class InstanceModel2PartialInterpretation { val referencesUsed = ecore2Logic.allReferencesInScope(ecore2LogicTrace).toSet val attributesUsed = ecore2Logic.allAttributesInScope(ecore2LogicTrace).toSet - val typeScope = createTypeScopesFromKnownAttributeValues(objects,attributesUsed) + val typeScope = createTypeScopesFromKnownAttributeValues(objects,attributesUsed, ignoredAttribs) val tracedOutput = partialInterpretationInitialiser.initialisePartialInterpretation(problem, typeScope) val partialInterpretation = tracedOutput.output val partialInterpretationTrace = tracedOutput.trace @@ -119,23 +122,26 @@ class InstanceModel2PartialInterpretation { // Transforming the attributes for(attribute : source.eClass.EAllAttributes.filter[attributesUsed.contains(it) && !it.derived]) { - val type = ecore2Logic.relationOfAttribute(ecore2LogicTrace,attribute) - val interpretation = type.lookup(partialInterpretationTrace.relation2Interpretation) - val sourceElement = source.lookup(object2DefinedElement) - if(attribute.isMany) { - val listOfTargets = source.eGet(attribute) as List - for(target : listOfTargets) { - val value = translateValue(target,ecore2LogicTrace,partialInterpretationTrace) - if(value !== null) { - translateLink(interpretation,sourceElement,value) + val isIgnored = checkIfIgnored(source, attribute, ignoredAttribs) + if (!isIgnored) { + val type = ecore2Logic.relationOfAttribute(ecore2LogicTrace,attribute) + val interpretation = type.lookup(partialInterpretationTrace.relation2Interpretation) + val sourceElement = source.lookup(object2DefinedElement) + if(attribute.isMany) { + val listOfTargets = source.eGet(attribute) as List + for(target : listOfTargets) { + val value = translateValue(target,ecore2LogicTrace,partialInterpretationTrace) + if(value !== null) { + translateLink(interpretation,sourceElement,value) + } } - } - } else { - val target = source.eGet(attribute) - if(target !== null) { - val value = translateValue(target,ecore2LogicTrace,partialInterpretationTrace) - if(value !== null) { - translateLink(interpretation,sourceElement,value) + } else { + val target = source.eGet(attribute) + if(target !== null) { + val value = translateValue(target,ecore2LogicTrace,partialInterpretationTrace) + if(value !== null) { + translateLink(interpretation,sourceElement,value) + } } } } @@ -144,21 +150,29 @@ class InstanceModel2PartialInterpretation { return partialInterpretation } - - private def createTypeScopesFromKnownAttributeValues(List objects, Set attributesUsed) { + + private def createTypeScopesFromKnownAttributeValues( + List objects, + Set attributesUsed, + Map> ignoredAttribs) + { val Set integers = new HashSet val Set reals = new HashSet val Set strings = new HashSet - for(object: objects) { - for(attribute : object.eClass.EAllAttributes.filter[attributesUsed.contains(it)]) { - val value = object.eGet(attribute) - if(value !== null) { - if(value instanceof List) { - for(v : value) { - shortValue(v,integers,reals,strings) + for (object : objects) { + for (attribute : object.eClass.EAllAttributes.filter[attributesUsed.contains(it)]) { + val isIgnored = checkIfIgnored(object, attribute, ignoredAttribs) + + if(!isIgnored) { + val value = object.eGet(attribute) + if(value !== null) { + if(value instanceof List) { + for(v : value) { + shortValue(v,integers,reals,strings) + } + } else { + shortValue(value,integers,reals,strings) } - } else { - shortValue(value,integers,reals,strings) } } } @@ -169,6 +183,40 @@ class InstanceModel2PartialInterpretation { it.knownStrings += strings ] } + private def boolean checkIfIgnored( + EObject object, + EAttribute attribute, + Map> ignoredAttribs + ) { + val classInIgnored = ignoredAttribs.get(object.eClass.name) + val mayIgnored = ( + classInIgnored !== null && classInIgnored.containsKey(attribute.name)) + + var isIgnored = false + if (mayIgnored) { + val specificIgnoredValue = classInIgnored.get(attribute.name) + if (specificIgnoredValue.equals("*")) + isIgnored = true + else { + val value = object.eGet(attribute) + if (typeof(Number).isAssignableFrom(value.class)) { + isIgnored = (Double.valueOf(specificIgnoredValue) == value) + } else { + isIgnored = specificIgnoredValue.equals(value) + } + } + } + // DEBUG +// println("DEBUG BEGINNING") +// println(object) +// println(attribute) +// println(value) +// +// println("MAYIGNORE " + mayIgnored) +// println("ISIGNORED " + isIgnored) + // END DEBUG + return isIgnored + } private def dispatch shortValue(Boolean value, Set integers, Set reals, Set strings) { // Do nothing } -- cgit v1.2.3-70-g09d2