use of org.kie.pmml.api.enums.OPERATOR in project drools by kiegroup.
the class KiePMMLScorecardModelCharacteristicASTFactoryTest method commonValidateKiePMMLOperatorValue.
private void commonValidateKiePMMLOperatorValue(KiePMMLOperatorValue toValidate, SimplePredicate simplePredicate) {
OPERATOR expectedOperator = OPERATOR.byName(simplePredicate.getOperator().value());
assertEquals(expectedOperator, toValidate.getOperator());
Object expectedValue = getExpectedValue(simplePredicate);
assertEquals(expectedValue, toValidate.getValue());
}
use of org.kie.pmml.api.enums.OPERATOR in project drools by kiegroup.
the class KiePMMLOperatorValueTest method getConstraintsAsString.
@Test
public void getConstraintsAsString() {
OPERATOR operator = OPERATOR.LESS_THAN;
Object value = 234;
KiePMMLOperatorValue kiePMMLOperatorValue = new KiePMMLOperatorValue(operator, value);
String retrieved = kiePMMLOperatorValue.getConstraintsAsString();
String expected = String.format(VALUE_CONSTRAINT_PATTERN, operator.getOperator(), value);
assertEquals(expected, retrieved);
}
use of org.kie.pmml.api.enums.OPERATOR in project drools by kiegroup.
the class KiePMMLSimplePredicateFactory method getSimplePredicateVariableDeclaration.
static BlockStmt getSimplePredicateVariableDeclaration(final String variableName, final SimplePredicate simplePredicate, final List<Field<?>> fields) {
final MethodDeclaration methodDeclaration = SIMPLE_PREDICATE_TEMPLATE.getMethodsByName(GETKIEPMMLSIMPLEPREDICATE).get(0).clone();
final BlockStmt simplePredicateBody = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(simplePredicateBody, SIMPLE_PREDICATE).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, SIMPLE_PREDICATE, simplePredicateBody)));
variableDeclarator.setName(variableName);
final BlockStmt toReturn = new BlockStmt();
final OPERATOR operator = OPERATOR.byName(simplePredicate.getOperator().value());
final NameExpr operatorExpr = new NameExpr(OPERATOR.class.getName() + "." + operator.name());
final MethodCallExpr initializer = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, SIMPLE_PREDICATE, simplePredicateBody))).asMethodCallExpr();
final MethodCallExpr builder = getChainedMethodCallExprFrom("builder", initializer);
builder.setArgument(0, new StringLiteralExpr(simplePredicate.getField().getValue()));
builder.setArgument(2, operatorExpr);
DataType dataType = getDataType(fields, simplePredicate.getField().getValue());
Object actualValue = DATA_TYPE.byName(dataType.value()).getActualValue(simplePredicate.getValue());
getChainedMethodCallExprFrom("withValue", initializer).setArgument(0, getExpressionForObject(actualValue));
simplePredicateBody.getStatements().forEach(toReturn::addStatement);
return toReturn;
}
use of org.kie.pmml.api.enums.OPERATOR in project drools by kiegroup.
the class KiePMMLSimplePredicateASTFactory method getBuilderForSimplePredicate.
/**
* This method will create a <b>rule</b> that, in the RHS,
* 1) update the status (used for flowing between rules)
* 2) add <i>outputfields</i> to result variables
* 3) eventually set the value to accumulate
* <p>
* rule "_ResidenceStateScore_1"
* when
* $statusHolder : KiePMMLStatusHolder( status == "_ResidenceStateScore" )
* <p>
* RESIDENCESTATE( value == "KN" )
* then
* <p>
* $statusHolder.setStatus("_ResidenceStateScore_1");
* $statusHolder.accumulate("10.0");
* update($statusHolder);
* <p>
* end
* <p>
* end
* @param statusToSet
* @return
*/
protected KiePMMLDroolsRule.Builder getBuilderForSimplePredicate(final String statusToSet) {
logger.trace("getBuilderForSimplePredicate {}", statusToSet);
String statusConstraint = StringUtils.isEmpty(predicateASTFactoryData.getParentPath()) ? KiePMMLAbstractModelASTFactory.STATUS_NULL : String.format(STATUS_PATTERN, predicateASTFactoryData.getParentPath());
String key = predicateASTFactoryData.getFieldTypeMap().get(((SimplePredicate) predicateASTFactoryData.getPredicate()).getField().getValue()).getGeneratedType();
OPERATOR operator = OPERATOR.byName(((SimplePredicate) predicateASTFactoryData.getPredicate()).getOperator().value());
Object value = KiePMMLASTFactoryUtils.getCorrectlyFormattedObject(((SimplePredicate) predicateASTFactoryData.getPredicate()), predicateASTFactoryData.getFieldTypeMap());
List<KiePMMLFieldOperatorValue> andConstraints = Collections.singletonList(new KiePMMLFieldOperatorValue(key, BOOLEAN_OPERATOR.AND, Collections.singletonList(new KiePMMLOperatorValue(operator, value)), null));
return KiePMMLDroolsRule.builder(predicateASTFactoryData.getCurrentRule(), statusToSet, predicateASTFactoryData.getOutputFields()).withStatusConstraint(statusConstraint).withAndConstraints(andConstraints);
}
use of org.kie.pmml.api.enums.OPERATOR in project drools by kiegroup.
the class KiePMMLOperatorValueTest method buildConstraintsString.
@Test
public void buildConstraintsString() {
OPERATOR operator = OPERATOR.LESS_THAN;
Object value = 234;
KiePMMLOperatorValue kiePMMLOperatorValue = new KiePMMLOperatorValue(operator, value);
String retrieved = kiePMMLOperatorValue.buildConstraintsString();
String expected = String.format(VALUE_CONSTRAINT_PATTERN, operator.getOperator(), value);
assertEquals(expected, retrieved);
}
Aggregations