From 30c205f552a9c66c69903d4f12dd09f3e27e06ea Mon Sep 17 00:00:00 2001 From: OszkarSemerath Date: Tue, 8 Aug 2017 16:11:45 +0200 Subject: Support for double and string attributes --- .../model/builder/LogicModelInterpretation.xtend | 3 + .../model/builder/LogicStructureBuilder.xtend | 75 +++++++++++----------- 2 files changed, 40 insertions(+), 38 deletions(-) (limited to 'Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner') diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicModelInterpretation.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicModelInterpretation.xtend index aa59836c..905859eb 100644 --- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicModelInterpretation.xtend +++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicModelInterpretation.xtend @@ -27,6 +27,7 @@ interface LogicModelInterpretation{ * Boolean literal Boolean * Integer literal Integer * Real literal BigDecimal + * String literal String *

* @param function The target function to be interpreted. * @param parameterSubstitution The array of the substituted parameters encoded as defined in the table. @@ -41,6 +42,7 @@ interface LogicModelInterpretation{ * Boolean literal Boolean * Integer literal Integer * Real literal BigDecimal + * String literal String *

* @param relation The target relation to be interpreted. * @param parameterSubstitution The array of the substituted parameters encoded as defined in the table. @@ -55,6 +57,7 @@ interface LogicModelInterpretation{ * Boolean literal Boolean * Integer literal Integer * Real literal BigDecimal + * String literal String *

* @param constant The target constant to be interpreted. * @return The value of the constant encoded as specified in the table. diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicStructureBuilder.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicStructureBuilder.xtend index 760aa8b8..42f85a2d 100644 --- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicStructureBuilder.xtend +++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicStructureBuilder.xtend @@ -55,6 +55,10 @@ import org.eclipse.xtend.lib.annotations.Data import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.InstanceOf +import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeReference +import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.BoolTypeReference +import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealTypeReference +import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.StringTypeReference @Data class InterpretationValidationResult { val List problems; @@ -381,14 +385,28 @@ class LogicStructureBuilder{ return (left as Number).asInteger == (right as Number).asInteger } } else return left.equals(right) - } + } - def allIntegers(LogicModelInterpretation interpretation) { - if(interpretation.minimalInteger <= interpretation.maximalInteger) { - (interpretation.minimalInteger .. interpretation.maximalInteger).map[asInteger] - } else return emptySet + private dispatch def allObjects(LogicModelInterpretation interpretation, ComplexTypeReference type) { + return interpretation.getElements(type.referred) + } + private dispatch def allObjects(LogicModelInterpretation interpretation, BoolTypeReference type) { + return #[true,false] + } + private dispatch def allObjects(LogicModelInterpretation interpretation, IntTypeReference type) { + return interpretation.allIntegersInStructure + } + private dispatch def allObjects(LogicModelInterpretation interpretation, RealTypeReference type) { + return interpretation.allRealsInStructure + } + private dispatch def allObjects(LogicModelInterpretation interpretation, StringTypeReference type) { + return interpretation.allStringsInStructure + } + private dispatch def allObjects(LogicModelInterpretation interpretation, TypeReference type) { + throw new UnsupportedOperationException('''Unknown type :«type.class.simpleName»!''') } + def private boolean executeExists( Term expression, LogicModelInterpretation interpretation, @@ -401,23 +419,13 @@ class LogicStructureBuilder{ } else { val unfoldedVariable = variablesToBind.head - val possibleValuesType = unfoldedVariable.range - if(possibleValuesType instanceof ComplexTypeReference) { - return this.getElements(interpretation,possibleValuesType.referred).exists[newBinding | - executeExists( - expression, - interpretation, - new HashMap(variableBinding) => [put(unfoldedVariable,newBinding)], - variablesToBind.subList(1,variablesToBind.size))] - } else if(possibleValuesType instanceof IntTypeReference) { - return interpretation.allIntegers.exists[newBinding | - executeExists( - expression, - interpretation, - new HashMap(variableBinding) => [put(unfoldedVariable,newBinding)], - variablesToBind.subList(1,variablesToBind.size))] - } - else throw new UnsupportedOperationException('''Quantifying over type "«possibleValuesType»" is unsupported.''') + val possibleValues = interpretation.allObjects(unfoldedVariable.range) + return possibleValues.exists[newBinding | + executeExists( + expression, + interpretation, + new HashMap(variableBinding) => [put(unfoldedVariable,newBinding)], + variablesToBind.subList(1,variablesToBind.size))] } } @@ -432,22 +440,13 @@ class LogicStructureBuilder{ } else { val unfoldedVariable = variablesToBind.head - val possibleValuesType = unfoldedVariable.range - if(possibleValuesType instanceof ComplexTypeReference) { - return this.getElements(interpretation,possibleValuesType.referred).forall[newBinding | - executeForall( - expression, - interpretation, - new HashMap(variableBinding) => [put(unfoldedVariable,newBinding)], - variablesToBind.subList(1,variablesToBind.size))] - } else if(possibleValuesType instanceof IntTypeReference) { - return interpretation.allIntegers.forall[newBinding | - executeForall( - expression, - interpretation, - new HashMap(variableBinding) => [put(unfoldedVariable,newBinding)], - variablesToBind.subList(1,variablesToBind.size))] - } else throw new UnsupportedOperationException('''Quantifying over type "«possibleValuesType»" is unsupported.''') + val possibleValues = interpretation.allObjects(unfoldedVariable.range) + return possibleValues.forall[newBinding | + executeForall( + expression, + interpretation, + new HashMap(variableBinding) => [put(unfoldedVariable,newBinding)], + variablesToBind.subList(1,variablesToBind.size))] } } } \ No newline at end of file -- cgit v1.2.3-54-g00ecf