use of org.dmg.pmml.Constant in project drools by kiegroup.
the class KiePMMLApplyFactoryTest method getApplyVariableDeclarationWithConstants.
@Test
public void getApplyVariableDeclarationWithConstants() throws IOException {
String variableName = "variableName";
Apply apply = new Apply();
apply.setFunction(function);
String mapMissingTo = "mapMissingTo";
apply.setMapMissingTo(mapMissingTo);
String defaultValue = "defaultValue";
apply.setDefaultValue(defaultValue);
InvalidValueTreatmentMethod invalidValueTreatmentMethod = InvalidValueTreatmentMethod.AS_MISSING;
apply.setInvalidValueTreatment(invalidValueTreatmentMethod);
Constant constant1 = new Constant();
constant1.setValue(value1);
Constant constant2 = new Constant();
constant2.setValue(value2);
apply.addExpressions(constant1, constant2);
BlockStmt retrieved = KiePMMLApplyFactory.getApplyVariableDeclaration(variableName, apply);
String text = getFileContent(TEST_01_SOURCE);
Statement expected = JavaParserUtils.parseBlock(String.format(text, value1, value2, variableName, function, defaultValue, mapMissingTo, invalidValueTreatmentMethod.value()));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(KiePMMLConstant.class, KiePMMLApply.class, Collections.class, Arrays.class);
commonValidateCompilationWithImports(retrieved, imports);
}
use of org.dmg.pmml.Constant in project drools by kiegroup.
the class KiePMMLDefineFunctionFactoryTest method getDefineFunctionVariableDeclaration.
@Test
public void getDefineFunctionVariableDeclaration() throws IOException {
ParameterField parameterField1 = new ParameterField(FieldName.create(PARAM_1));
parameterField1.setDataType(DataType.DOUBLE);
parameterField1.setOpType(OpType.CONTINUOUS);
parameterField1.setDisplayName("displayName1");
ParameterField parameterField2 = new ParameterField(FieldName.create(PARAM_2));
parameterField2.setDataType(DataType.DOUBLE);
parameterField2.setOpType(OpType.CONTINUOUS);
parameterField2.setDisplayName("displayName2");
Constant constant = new Constant();
constant.setValue(value1);
FieldRef fieldRef = new FieldRef();
fieldRef.setField(FieldName.create("FIELD_REF"));
Apply apply = new Apply();
apply.setFunction("/");
apply.addExpressions(constant, fieldRef);
DefineFunction defineFunction = new DefineFunction();
defineFunction.setName(CUSTOM_FUNCTION);
defineFunction.addParameterFields(parameterField1, parameterField2);
defineFunction.setDataType(DataType.DOUBLE);
defineFunction.setOpType(OpType.CONTINUOUS);
defineFunction.setExpression(apply);
String dataType1 = getDATA_TYPEString(parameterField1.getDataType());
String dataType2 = getDATA_TYPEString(parameterField2.getDataType());
String dataType3 = getDATA_TYPEString(defineFunction.getDataType());
String opType1 = getOP_TYPEString(parameterField1.getOpType());
String opType2 = getOP_TYPEString(parameterField2.getOpType());
String opType3 = getOP_TYPEString(defineFunction.getOpType());
BlockStmt retrieved = KiePMMLDefineFunctionFactory.getDefineFunctionVariableDeclaration(defineFunction);
String text = getFileContent(TEST_01_SOURCE);
Statement expected = JavaParserUtils.parseBlock(String.format(text, parameterField1.getName().getValue(), dataType1, opType1, parameterField1.getDisplayName(), parameterField2.getName().getValue(), dataType2, opType2, parameterField2.getDisplayName(), constant.getValue(), fieldRef.getField().getValue(), apply.getFunction(), apply.getInvalidValueTreatment().value(), dataType3, opType3));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(KiePMMLParameterField.class, KiePMMLConstant.class, KiePMMLFieldRef.class, KiePMMLApply.class, KiePMMLDefineFunction.class, Arrays.class, Collections.class);
commonValidateCompilationWithImports(retrieved, imports);
}
use of org.dmg.pmml.Constant in project drools by kiegroup.
the class KiePMMLDerivedFieldFactoryTest method getDerivedFieldVariableDeclarationWithConstant.
@Test
public void getDerivedFieldVariableDeclarationWithConstant() throws IOException {
final String variableName = "variableName";
Constant constant = new Constant();
constant.setValue(value1);
DerivedField derivedField = new DerivedField();
derivedField.setName(FieldName.create(PARAM_1));
derivedField.setDataType(DataType.DOUBLE);
derivedField.setOpType(OpType.CONTINUOUS);
derivedField.setExpression(constant);
String dataType = getDATA_TYPEString(derivedField.getDataType());
String opType = getOP_TYPEString(derivedField.getOpType());
BlockStmt retrieved = KiePMMLDerivedFieldFactory.getDerivedFieldVariableDeclaration(variableName, derivedField);
String text = getFileContent(TEST_01_SOURCE);
Statement expected = JavaParserUtils.parseBlock(String.format(text, constant.getValue(), variableName, derivedField.getName().getValue(), dataType, opType));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(KiePMMLConstant.class, KiePMMLDerivedField.class, Collections.class);
commonValidateCompilationWithImports(retrieved, imports);
}
use of org.dmg.pmml.Constant in project drools by kiegroup.
the class KiePMMLTransformationDictionaryFactoryTest method getDefineFunction.
private DefineFunction getDefineFunction(int counter) {
ParameterField parameterField1 = new ParameterField(FieldName.create(PARAM_1 + counter));
parameterField1.setDataType(DataType.DOUBLE);
parameterField1.setOpType(OpType.CONTINUOUS);
parameterField1.setDisplayName("displayName1" + counter);
ParameterField parameterField2 = new ParameterField(FieldName.create(PARAM_2 + counter));
parameterField2.setDataType(DataType.DOUBLE);
parameterField2.setOpType(OpType.CONTINUOUS);
parameterField2.setDisplayName("displayName2" + counter);
Constant constant = new Constant();
constant.setValue(value1);
FieldRef fieldRef = new FieldRef();
fieldRef.setField(FieldName.create("FIELD_REF" + counter));
Apply apply = new Apply();
apply.setFunction("/");
apply.addExpressions(constant, fieldRef);
DefineFunction toReturn = new DefineFunction();
toReturn.setName(CUSTOM_FUNCTION + counter);
toReturn.addParameterFields(parameterField1, parameterField2);
toReturn.setDataType(DataType.DOUBLE);
toReturn.setOpType(OpType.CONTINUOUS);
toReturn.setExpression(apply);
return toReturn;
}
use of org.dmg.pmml.Constant in project drools by kiegroup.
the class KiePMMLConstantInstanceFactoryTest method getKiePMMLConstant.
@Test
public void getKiePMMLConstant() {
Object value = 2342.21;
Constant toConvert = new Constant();
toConvert.setValue(value);
KiePMMLConstant retrieved = KiePMMLConstantInstanceFactory.getKiePMMLConstant(toConvert);
commonVerifyKiePMMLConstant(retrieved, toConvert);
}
Aggregations