Search in sources :

Example 6 with Constant

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);
}
Also used : KiePMMLApply(org.kie.pmml.commons.model.expressions.KiePMMLApply) Apply(org.dmg.pmml.Apply) KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Constant(org.dmg.pmml.Constant) Statement(com.github.javaparser.ast.stmt.Statement) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) InvalidValueTreatmentMethod(org.dmg.pmml.InvalidValueTreatmentMethod) Test(org.junit.Test)

Example 7 with Constant

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);
}
Also used : KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) FieldRef(org.dmg.pmml.FieldRef) KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Constant(org.dmg.pmml.Constant) KiePMMLApply(org.kie.pmml.commons.model.expressions.KiePMMLApply) Apply(org.dmg.pmml.Apply) Statement(com.github.javaparser.ast.stmt.Statement) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) DefineFunction(org.dmg.pmml.DefineFunction) KiePMMLDefineFunction(org.kie.pmml.commons.transformations.KiePMMLDefineFunction) CommonTestingUtils.getOP_TYPEString(org.kie.pmml.compiler.api.CommonTestingUtils.getOP_TYPEString) CommonTestingUtils.getDATA_TYPEString(org.kie.pmml.compiler.api.CommonTestingUtils.getDATA_TYPEString) KiePMMLParameterField(org.kie.pmml.commons.transformations.KiePMMLParameterField) ParameterField(org.dmg.pmml.ParameterField) Test(org.junit.Test)

Example 8 with Constant

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);
}
Also used : KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Constant(org.dmg.pmml.Constant) Statement(com.github.javaparser.ast.stmt.Statement) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) CommonTestingUtils.getOP_TYPEString(org.kie.pmml.compiler.api.CommonTestingUtils.getOP_TYPEString) CommonTestingUtils.getDATA_TYPEString(org.kie.pmml.compiler.api.CommonTestingUtils.getDATA_TYPEString) DerivedField(org.dmg.pmml.DerivedField) KiePMMLDerivedField(org.kie.pmml.commons.transformations.KiePMMLDerivedField) Test(org.junit.Test)

Example 9 with Constant

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;
}
Also used : KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) FieldRef(org.dmg.pmml.FieldRef) KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Constant(org.dmg.pmml.Constant) KiePMMLApply(org.kie.pmml.commons.model.expressions.KiePMMLApply) Apply(org.dmg.pmml.Apply) DefineFunction(org.dmg.pmml.DefineFunction) KiePMMLDefineFunction(org.kie.pmml.commons.transformations.KiePMMLDefineFunction) KiePMMLParameterField(org.kie.pmml.commons.transformations.KiePMMLParameterField) ParameterField(org.dmg.pmml.ParameterField)

Example 10 with Constant

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);
}
Also used : KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) InstanceFactoriesTestCommon.commonVerifyKiePMMLConstant(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLConstant) Constant(org.dmg.pmml.Constant) KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) InstanceFactoriesTestCommon.commonVerifyKiePMMLConstant(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLConstant) Test(org.junit.Test)

Aggregations

Constant (org.dmg.pmml.Constant)23 KiePMMLConstant (org.kie.pmml.commons.model.expressions.KiePMMLConstant)13 Test (org.junit.Test)10 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)7 Statement (com.github.javaparser.ast.stmt.Statement)7 Apply (org.dmg.pmml.Apply)7 DerivedField (org.dmg.pmml.DerivedField)7 FieldRef (org.dmg.pmml.FieldRef)6 KiePMMLApply (org.kie.pmml.commons.model.expressions.KiePMMLApply)5 DefineFunction (org.dmg.pmml.DefineFunction)4 ComplexPartialScore (org.dmg.pmml.scorecard.ComplexPartialScore)4 KiePMMLFieldRef (org.kie.pmml.commons.model.expressions.KiePMMLFieldRef)4 KiePMMLDerivedField (org.kie.pmml.commons.transformations.KiePMMLDerivedField)4 KiePMMLComplexPartialScore (org.kie.pmml.models.scorecard.model.KiePMMLComplexPartialScore)4 CommonTestingUtils.getDATA_TYPEString (org.kie.pmml.compiler.api.CommonTestingUtils.getDATA_TYPEString)3 CommonTestingUtils.getOP_TYPEString (org.kie.pmml.compiler.api.CommonTestingUtils.getOP_TYPEString)3 Expression (org.dmg.pmml.Expression)2 ParameterField (org.dmg.pmml.ParameterField)2 ContinuousFeature (org.jpmml.converter.ContinuousFeature)2 Feature (org.jpmml.converter.Feature)2