Search in sources :

Example 16 with Constant

use of org.dmg.pmml.Constant in project drools by kiegroup.

the class KiePMMLDerivedFieldFactoryTest method getDerivedFieldVariableDeclarationWithApply.

@Test
public void getDerivedFieldVariableDeclarationWithApply() throws IOException {
    final String variableName = "variableName";
    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);
    DerivedField derivedField = new DerivedField();
    derivedField.setName(FieldName.create(PARAM_1));
    derivedField.setDataType(DataType.DOUBLE);
    derivedField.setOpType(OpType.CONTINUOUS);
    derivedField.setExpression(apply);
    String dataType = getDATA_TYPEString(derivedField.getDataType());
    String opType = getOP_TYPEString(derivedField.getOpType());
    BlockStmt retrieved = KiePMMLDerivedFieldFactory.getDerivedFieldVariableDeclaration(variableName, derivedField);
    String text = getFileContent(TEST_03_SOURCE);
    Statement expected = JavaParserUtils.parseBlock(String.format(text, constant.getValue(), fieldRef.getField().getValue(), apply.getFunction(), apply.getInvalidValueTreatment().value(), variableName, derivedField.getName().getValue(), dataType, opType));
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
    List<Class<?>> imports = Arrays.asList(KiePMMLConstant.class, KiePMMLFieldRef.class, KiePMMLApply.class, KiePMMLDerivedField.class, Arrays.class, Collections.class);
    commonValidateCompilationWithImports(retrieved, imports);
}
Also used : FieldRef(org.dmg.pmml.FieldRef) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) 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) 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 17 with Constant

use of org.dmg.pmml.Constant in project drools by kiegroup.

the class KiePMMLLocalTransformationsFactoryTest method getDerivedField.

private DerivedField getDerivedField(int counter) {
    Constant constant = new Constant();
    constant.setValue(value1);
    DerivedField toReturn = new DerivedField();
    toReturn.setName(FieldName.create(PARAM_2 + counter));
    toReturn.setDataType(DataType.DOUBLE);
    toReturn.setOpType(OpType.CONTINUOUS);
    toReturn.setExpression(constant);
    return toReturn;
}
Also used : KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Constant(org.dmg.pmml.Constant) DerivedField(org.dmg.pmml.DerivedField) KiePMMLDerivedField(org.kie.pmml.commons.transformations.KiePMMLDerivedField)

Example 18 with Constant

use of org.dmg.pmml.Constant in project drools by kiegroup.

the class KiePMMLCharacteristicFactoryTest method getComplexPartialScore.

private ComplexPartialScore getComplexPartialScore() {
    Constant constant = new Constant();
    constant.setValue(value1);
    ComplexPartialScore toReturn = new ComplexPartialScore();
    toReturn.setExpression(constant);
    return toReturn;
}
Also used : KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Constant(org.dmg.pmml.Constant) KiePMMLComplexPartialScore(org.kie.pmml.models.scorecard.model.KiePMMLComplexPartialScore) ComplexPartialScore(org.dmg.pmml.scorecard.ComplexPartialScore)

Example 19 with Constant

use of org.dmg.pmml.Constant in project drools by kiegroup.

the class KiePMMLComplexPartialScoreFactoryTest method getComplexPartialScoreVariableDeclarationWithApply.

@Test
public void getComplexPartialScoreVariableDeclarationWithApply() throws IOException {
    final String variableName = "variableName";
    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);
    ComplexPartialScore complexPartialScore = new ComplexPartialScore();
    complexPartialScore.setExpression(apply);
    BlockStmt retrieved = KiePMMLComplexPartialScoreFactory.getComplexPartialScoreVariableDeclaration(variableName, complexPartialScore);
    String text = getFileContent(TEST_03_SOURCE);
    Statement expected = JavaParserUtils.parseBlock(String.format(text, constant.getValue(), fieldRef.getField().getValue(), apply.getFunction(), apply.getInvalidValueTreatment().value(), variableName));
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
    List<Class<?>> imports = Arrays.asList(KiePMMLConstant.class, KiePMMLFieldRef.class, KiePMMLApply.class, KiePMMLComplexPartialScore.class, Arrays.class, Collections.class);
    commonValidateCompilationWithImports(retrieved, imports);
}
Also used : FieldRef(org.dmg.pmml.FieldRef) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) 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) KiePMMLComplexPartialScore(org.kie.pmml.models.scorecard.model.KiePMMLComplexPartialScore) ComplexPartialScore(org.dmg.pmml.scorecard.ComplexPartialScore) Test(org.junit.Test)

Example 20 with Constant

use of org.dmg.pmml.Constant in project drools by kiegroup.

the class KiePMMLAttributeFactoryTest method getComplexPartialScore.

private ComplexPartialScore getComplexPartialScore() {
    Constant constant = new Constant();
    constant.setValue(value1);
    ComplexPartialScore toReturn = new ComplexPartialScore();
    toReturn.setExpression(constant);
    return toReturn;
}
Also used : KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Constant(org.dmg.pmml.Constant) KiePMMLComplexPartialScore(org.kie.pmml.models.scorecard.model.KiePMMLComplexPartialScore) ComplexPartialScore(org.dmg.pmml.scorecard.ComplexPartialScore)

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