use of org.kie.pmml.api.models.MiningField in project drools by kiegroup.
the class KiePMMLModelFactoryUtilsTest method commonVerifyMiningFieldsObjectCreation.
private void commonVerifyMiningFieldsObjectCreation(List<Expression> toVerify, List<MiningField> miningFields) {
toVerify.forEach(expression -> {
assertTrue(expression instanceof ObjectCreationExpr);
ObjectCreationExpr objCrt = (ObjectCreationExpr) expression;
assertEquals(MiningField.class.getCanonicalName(), objCrt.getType().asString());
Optional<MiningField> miningFieldOpt = miningFields.stream().filter(miningField -> miningField.getName().equals(objCrt.getArgument(0).asStringLiteralExpr().asString())).findFirst();
assertTrue(miningFieldOpt.isPresent());
MiningField miningField = miningFieldOpt.get();
assertEquals(MiningField.class.getCanonicalName(), objCrt.getType().asString());
String expected = miningField.getUsageType() != null ? FIELD_USAGE_TYPE.class.getCanonicalName() + "." + miningField.getUsageType() : "null";
assertEquals(expected, objCrt.getArgument(1).toString());
expected = miningField.getOpType() != null ? OP_TYPE.class.getCanonicalName() + "." + miningField.getOpType() : "null";
assertEquals(expected, objCrt.getArgument(2).toString());
expected = miningField.getDataType() != null ? DATA_TYPE.class.getCanonicalName() + "." + miningField.getDataType() : "null";
assertEquals(expected, objCrt.getArgument(3).toString());
expected = miningField.getMissingValueTreatmentMethod() != null ? MISSING_VALUE_TREATMENT_METHOD.class.getCanonicalName() + "." + miningField.getMissingValueTreatmentMethod() : "null";
assertEquals(expected, objCrt.getArgument(4).toString());
expected = miningField.getInvalidValueTreatmentMethod() != null ? INVALID_VALUE_TREATMENT_METHOD.class.getCanonicalName() + "." + miningField.getInvalidValueTreatmentMethod() : "null";
assertEquals(expected, objCrt.getArgument(5).toString());
expected = miningField.getMissingValueReplacement() != null ? miningField.getMissingValueReplacement() : "null";
assertEquals(expected, objCrt.getArgument(6).asStringLiteralExpr().asString());
expected = miningField.getInvalidValueReplacement() != null ? miningField.getInvalidValueReplacement() : "null";
assertEquals(expected, objCrt.getArgument(7).asStringLiteralExpr().asString());
MethodCallExpr allowedValuesMethod = objCrt.getArgument(8).asMethodCallExpr();
IntStream.range(0, 3).forEach(i -> {
String exp = miningField.getAllowedValues().get(i);
assertEquals(exp, allowedValuesMethod.getArgument(i).asStringLiteralExpr().asString());
});
MethodCallExpr intervalsMethod = objCrt.getArgument(9).asMethodCallExpr();
IntStream.range(0, 3).forEach(i -> {
Interval interval = miningField.getIntervals().get(i);
ObjectCreationExpr objectCreationExpr = intervalsMethod.getArgument(i).asObjectCreationExpr();
String exp = interval.getLeftMargin().toString();
assertEquals(exp, objectCreationExpr.getArgument(0).asNameExpr().toString());
exp = interval.getRightMargin().toString();
assertEquals(exp, objectCreationExpr.getArgument(1).asNameExpr().toString());
});
});
}
use of org.kie.pmml.api.models.MiningField in project drools by kiegroup.
the class BUILTIN_FUNCTIONSTest method getSupportedValueEmptyInput.
@Test
public void getSupportedValueEmptyInput() {
final Object[] input = {};
supportedBuiltinFunctions.forEach(builtinFunction -> {
try {
builtinFunction.getValue(input, new MiningField(null, null, null, null, null, null, null, null, null, null));
fail("Expecting IllegalArgumentException");
} catch (Exception e) {
assertTrue(e instanceof IllegalArgumentException);
}
});
}
use of org.kie.pmml.api.models.MiningField in project drools by kiegroup.
the class BooleanFunctionsTest method getIsValidValueWrongSizeInput.
@Test(expected = IllegalArgumentException.class)
public void getIsValidValueWrongSizeInput() {
final Object[] input = { 34, 34 };
MiningField referredByFieldRef = getReferredByFieldRef(null, null, Arrays.asList(new Interval(20, 29), new Interval(30, 40), new Interval(41, 50)));
BooleanFunctions.IS_VALID.getValue(input, referredByFieldRef);
}
use of org.kie.pmml.api.models.MiningField in project drools by kiegroup.
the class BooleanFunctionsTest method getIsValidValueCorrectInput.
@Test
public void getIsValidValueCorrectInput() {
Object[] input1 = { 35 };
MiningField referredByFieldRef = getReferredByFieldRef(null, null, Arrays.asList(new Interval(20, 29), new Interval(30, 40), new Interval(41, 50)));
Object retrieved = BooleanFunctions.IS_VALID.getValue(input1, referredByFieldRef);
assertTrue((boolean) retrieved);
referredByFieldRef = getReferredByFieldRef(null, null, Arrays.asList(new Interval(20, 29), new Interval(41, 50)));
retrieved = BooleanFunctions.IS_VALID.getValue(input1, referredByFieldRef);
assertFalse((boolean) retrieved);
referredByFieldRef = getReferredByFieldRef(null, Arrays.asList("123", "35"), Arrays.asList(new Interval(20, 29), new Interval(41, 50)));
retrieved = BooleanFunctions.IS_VALID.getValue(input1, referredByFieldRef);
assertTrue((boolean) retrieved);
referredByFieldRef = getReferredByFieldRef(null, Arrays.asList("123", "36"), Arrays.asList(new Interval(20, 29), new Interval(41, 50)));
retrieved = BooleanFunctions.IS_VALID.getValue(input1, referredByFieldRef);
assertFalse((boolean) retrieved);
Object[] input2 = { "VALUE" };
referredByFieldRef = getReferredByFieldRef(null, Arrays.asList("123", "VALUE"), Collections.emptyList());
retrieved = BooleanFunctions.IS_VALID.getValue(input2, referredByFieldRef);
assertTrue((boolean) retrieved);
referredByFieldRef = getReferredByFieldRef(null, Arrays.asList("123", "VELUE"), Collections.emptyList());
retrieved = BooleanFunctions.IS_VALID.getValue(input2, referredByFieldRef);
assertFalse((boolean) retrieved);
Object[] input3 = { null };
retrieved = BooleanFunctions.IS_VALID.getValue(input3, referredByFieldRef);
assertFalse((boolean) retrieved);
}
use of org.kie.pmml.api.models.MiningField in project drools by kiegroup.
the class BooleanFunctionsTest method getIsNotMissingValueCorrectInput.
@Test
public void getIsNotMissingValueCorrectInput() {
Object[] input1 = { 35 };
Object retrieved = BooleanFunctions.IS_NOT_MISSING.getValue(input1, EMPTY_MINING_FIELD);
assertTrue((boolean) retrieved);
Object[] input2 = { null };
retrieved = BooleanFunctions.IS_NOT_MISSING.getValue(input2, EMPTY_MINING_FIELD);
assertFalse((boolean) retrieved);
for (INVALID_VALUE_TREATMENT_METHOD invalidValueTreatmentMethod : INVALID_VALUE_TREATMENT_METHOD.values()) {
MiningField referredByFieldRef = getReferredByFieldRef(invalidValueTreatmentMethod, null, Arrays.asList(new Interval(20, 29), new Interval(41, 50)));
boolean expected = !INVALID_VALUE_TREATMENT_METHOD.AS_MISSING.equals(invalidValueTreatmentMethod);
assertEquals(expected, BooleanFunctions.IS_NOT_MISSING.getValue(input1, referredByFieldRef));
}
}
Aggregations