use of org.kie.pmml.api.enums.ARRAY_TYPE in project drools by kiegroup.
the class KiePMMLSimpleSetPredicateFactory method getSimpleSetPredicateVariableDeclaration.
static BlockStmt getSimpleSetPredicateVariableDeclaration(final String variableName, final SimpleSetPredicate simpleSetPredicate) {
final MethodDeclaration methodDeclaration = SIMPLESET_PREDICATE_TEMPLATE.getMethodsByName(GETKIEPMMLSIMPLESETPREDICATE).get(0).clone();
final BlockStmt simpleSetPredicateBody = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(simpleSetPredicateBody, SIMPLESET_PREDICATE).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, SIMPLESET_PREDICATE, simpleSetPredicateBody)));
variableDeclarator.setName(variableName);
final BlockStmt toReturn = new BlockStmt();
final NodeList<Expression> arguments = new NodeList<>();
List<Object> values = getObjectsFromArray(simpleSetPredicate.getArray());
for (Object value : values) {
arguments.add(getExpressionForObject(value));
}
final ARRAY_TYPE arrayType = ARRAY_TYPE.byName(simpleSetPredicate.getArray().getType().value());
final NameExpr arrayTypeExpr = new NameExpr(ARRAY_TYPE.class.getName() + "." + arrayType.name());
final IN_NOTIN inNotIn = IN_NOTIN.byName(simpleSetPredicate.getBooleanOperator().value());
final NameExpr inNotInExpr = new NameExpr(IN_NOTIN.class.getName() + "." + inNotIn.name());
final MethodCallExpr initializer = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, SIMPLESET_PREDICATE, simpleSetPredicateBody))).asMethodCallExpr();
final MethodCallExpr builder = getChainedMethodCallExprFrom("builder", initializer);
builder.setArgument(0, new StringLiteralExpr(simpleSetPredicate.getField().getValue()));
builder.setArgument(2, arrayTypeExpr);
builder.setArgument(3, inNotInExpr);
getChainedMethodCallExprFrom("asList", initializer).setArguments(arguments);
simpleSetPredicateBody.getStatements().forEach(toReturn::addStatement);
return toReturn;
}
use of org.kie.pmml.api.enums.ARRAY_TYPE in project drools by kiegroup.
the class KiePMMLCompoundPredicateTest method evaluateCompoundPredicateAnd.
@Test
public void evaluateCompoundPredicateAnd() {
ARRAY_TYPE arrayType = ARRAY_TYPE.STRING;
List<Object> stringValues = getObjects(arrayType, 4);
KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicateString = getKiePMMLSimpleSetPredicate(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues, arrayType, IN_NOTIN.IN);
arrayType = ARRAY_TYPE.INT;
List<Object> intValues = getObjects(arrayType, 4);
KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicateInt = getKiePMMLSimpleSetPredicate(SIMPLE_SET_PREDICATE_INT_NAME, intValues, arrayType, IN_NOTIN.NOT_IN);
KiePMMLCompoundPredicate kiePMMLCompoundPredicate = getKiePMMLCompoundPredicate(BOOLEAN_OPERATOR.AND, Arrays.asList(kiePMMLSimpleSetPredicateString, kiePMMLSimpleSetPredicateInt));
Map<String, Object> inputData = new HashMap<>();
inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues.get(0));
inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, intValues.get(0));
assertFalse(kiePMMLCompoundPredicate.evaluate(inputData));
inputData = new HashMap<>();
inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, "NOT");
inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, "234");
assertFalse(kiePMMLCompoundPredicate.evaluate(inputData));
inputData = new HashMap<>();
inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues.get(0));
inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, "234");
assertTrue(kiePMMLCompoundPredicate.evaluate(inputData));
}
use of org.kie.pmml.api.enums.ARRAY_TYPE in project drools by kiegroup.
the class KiePMMLCompoundPredicateTest method evaluateCompoundPredicateSurrogate.
@Test
public void evaluateCompoundPredicateSurrogate() {
ARRAY_TYPE arrayType = ARRAY_TYPE.STRING;
List<Object> stringValues = getObjects(arrayType, 4);
KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicateString = getKiePMMLSimpleSetPredicate(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues, arrayType, IN_NOTIN.IN);
arrayType = ARRAY_TYPE.INT;
List<Object> intValues = getObjects(arrayType, 4);
KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicateInt = getKiePMMLSimpleSetPredicate(SIMPLE_SET_PREDICATE_INT_NAME, intValues, arrayType, IN_NOTIN.NOT_IN);
KiePMMLCompoundPredicate kiePMMLCompoundPredicate = getKiePMMLCompoundPredicate(BOOLEAN_OPERATOR.SURROGATE, Arrays.asList(kiePMMLSimpleSetPredicateString, kiePMMLSimpleSetPredicateInt));
Map<String, Object> inputData = new HashMap<>();
// This predicate verify the "IN" condition
inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, "NOT");
// This predicate verify the "NOT_IN" condition
inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, intValues.get(0));
assertFalse(kiePMMLCompoundPredicate.evaluate(inputData));
// This predicate verify the "IN" condition
inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues.get(0));
// This predicate verify the "NOT_IN" condition
inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, intValues.get(0));
assertTrue(kiePMMLCompoundPredicate.evaluate(inputData));
// This predicate verify the "IN" condition
inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, "NOT");
// This predicate verify the "NOT_IN" condition
inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, 1);
assertFalse(kiePMMLCompoundPredicate.evaluate(inputData));
// This predicate verify the "IN" condition
inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues.get(0));
// This predicate verify the "NOT_IN" condition
inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, 1);
assertTrue(kiePMMLCompoundPredicate.evaluate(inputData));
}
use of org.kie.pmml.api.enums.ARRAY_TYPE in project drools by kiegroup.
the class KiePMMLSimpleSetPredicateTest method evaluateRealNotIn.
@Test
public void evaluateRealNotIn() {
ARRAY_TYPE arrayType = ARRAY_TYPE.REAL;
List<Object> values = getObjects(arrayType, 4);
KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicate = getKiePMMLSimpleSetPredicate(values, arrayType, IN_NOTIN.NOT_IN);
Map<String, Object> inputData = new HashMap<>();
inputData.put("FAKE", "23.4");
assertFalse(kiePMMLSimpleSetPredicate.evaluate(inputData));
inputData.put(SIMPLE_SET_PREDICATE_NAME, values.get(0));
assertFalse(kiePMMLSimpleSetPredicate.evaluate(inputData));
inputData.put(SIMPLE_SET_PREDICATE_NAME, "4.32");
assertTrue(kiePMMLSimpleSetPredicate.evaluate(inputData));
}
use of org.kie.pmml.api.enums.ARRAY_TYPE in project drools by kiegroup.
the class KiePMMLSimpleSetPredicateTest method evaluateIntNotIn.
@Test
public void evaluateIntNotIn() {
ARRAY_TYPE arrayType = ARRAY_TYPE.INT;
List<Object> values = getObjects(arrayType, 4);
KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicate = getKiePMMLSimpleSetPredicate(values, arrayType, IN_NOTIN.NOT_IN);
Map<String, Object> inputData = new HashMap<>();
inputData.put("FAKE", "234");
assertFalse(kiePMMLSimpleSetPredicate.evaluate(inputData));
inputData.put(SIMPLE_SET_PREDICATE_NAME, values.get(0));
assertFalse(kiePMMLSimpleSetPredicate.evaluate(inputData));
inputData.put(SIMPLE_SET_PREDICATE_NAME, "432");
assertTrue(kiePMMLSimpleSetPredicate.evaluate(inputData));
}
Aggregations