Search in sources :

Example 11 with TargetField

use of org.kie.pmml.api.models.TargetField in project drools by kiegroup.

the class PostProcessTest method executeTargets.

@Test
public void executeTargets() {
    // Build model
    String TARGET_NAME = "TARGET_NAME";
    String FIELD_NAME = "FIELD_NAME";
    TargetField targetField = new TargetField(Collections.emptyList(), null, FIELD_NAME, null, 4.34, null, null, null);
    KiePMMLTarget kiePMMLTarget = KiePMMLTarget.builder(TARGET_NAME, Collections.emptyList(), targetField).build();
    List<KiePMMLTarget> kiePMMLTargets = Arrays.asList(kiePMMLTarget, KiePMMLTarget.builder("NEW_TARGET", Collections.emptyList(), new TargetField(Collections.emptyList(), null, "NEW_TARGET", null, null, null, null, null)).build());
    KiePMMLTestingModel model = KiePMMLTestingModel.builder("TESTINGMODEL", Collections.emptyList(), MINING_FUNCTION.REGRESSION).withKiePMMLTargets(kiePMMLTargets).build();
    // Build PMML4Result
    PMML4Result toModify = new PMML4Result();
    toModify.setResultCode(ResultCode.FAIL.getName());
    toModify.addResultVariable(FIELD_NAME, 4.33);
    assertEquals(4.33, toModify.getResultVariables().get(FIELD_NAME));
    ProcessingDTO processingDTO = getProcessingDTO(model, new ArrayList<>());
    PostProcess.executeTargets(toModify, processingDTO);
    assertEquals(4.33, toModify.getResultVariables().get(FIELD_NAME));
    toModify.setResultCode(ResultCode.OK.getName());
    PostProcess.executeTargets(toModify, processingDTO);
    assertEquals(4.33, toModify.getResultVariables().get(FIELD_NAME));
    toModify.setResultObjectName(FIELD_NAME);
    PostProcess.executeTargets(toModify, processingDTO);
    assertEquals(4.34, toModify.getResultVariables().get(FIELD_NAME));
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) PMML4Result(org.kie.api.pmml.PMML4Result) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) TargetField(org.kie.pmml.api.models.TargetField) KiePMMLTarget(org.kie.pmml.commons.model.KiePMMLTarget) Test(org.junit.Test)

Example 12 with TargetField

use of org.kie.pmml.api.models.TargetField in project drools by kiegroup.

the class ModelUtils method convertToKieTargetField.

/**
 * Return a <code>org.kie.pmml.api.models.TargetField</code> out of a <code>org.dmg.pmml.Target</code>
 * @param toConvert
 * @return
 */
public static TargetField convertToKieTargetField(final Target toConvert) {
    final List<org.kie.pmml.api.models.TargetValue> targetValues = convertToKieTargetValueList(toConvert.getTargetValues());
    final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
    final CAST_INTEGER castInteger = toConvert.getCastInteger() != null ? CAST_INTEGER.byName(toConvert.getCastInteger().value()) : null;
    final Double min = toConvert.getMin() != null ? toConvert.getMin().doubleValue() : null;
    final Double max = toConvert.getMax() != null ? toConvert.getMax().doubleValue() : null;
    final Double rescaleConstant = toConvert.getRescaleConstant() != null ? toConvert.getRescaleConstant().doubleValue() : null;
    final Double rescaleFactor = toConvert.getRescaleFactor() != null ? toConvert.getRescaleFactor().doubleValue() : null;
    return new TargetField(targetValues, opType, toConvert.getField().getValue(), castInteger, min, max, rescaleConstant, rescaleFactor);
}
Also used : TargetValue(org.dmg.pmml.TargetValue) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) CAST_INTEGER(org.kie.pmml.api.enums.CAST_INTEGER) TargetField(org.kie.pmml.api.models.TargetField)

Example 13 with TargetField

use of org.kie.pmml.api.models.TargetField in project drools by kiegroup.

the class KiePMMLTargetTest method applyMax.

@Test
public void applyMax() {
    TargetField targetField = new TargetField(Collections.emptyList(), null, "string", null, null, null, null, null);
    KiePMMLTarget kiePMMLTarget = getBuilder(targetField).build();
    assertEquals(4.33, kiePMMLTarget.applyMax(4.33), 0.0);
    targetField = new TargetField(Collections.emptyList(), null, "string", null, null, 4.34, null, null);
    kiePMMLTarget = getBuilder(targetField).build();
    assertEquals(4.33, kiePMMLTarget.applyMax(4.33), 0.0);
    assertEquals(4.34, kiePMMLTarget.applyMax(4.35), 0.0);
}
Also used : TargetField(org.kie.pmml.api.models.TargetField) Test(org.junit.Test)

Example 14 with TargetField

use of org.kie.pmml.api.models.TargetField in project drools by kiegroup.

the class KiePMMLTargetTest method modifyPrediction.

@Test
public void modifyPrediction() {
    Object object = "STRING";
    TargetField targetField = new TargetField(Collections.emptyList(), null, "string", null, null, null, null, null);
    KiePMMLTarget kiePMMLTarget = getBuilder(targetField).build();
    assertEquals(object, kiePMMLTarget.modifyPrediction(object));
    object = 4.33;
    assertEquals(object, kiePMMLTarget.modifyPrediction(object));
    targetField = new TargetField(Collections.emptyList(), null, "string", null, 4.34, null, null, null);
    kiePMMLTarget = getBuilder(targetField).build();
    object = "STRING";
    assertEquals(object, kiePMMLTarget.modifyPrediction(object));
    object = 4.33;
    assertEquals(4.34, kiePMMLTarget.modifyPrediction(object));
}
Also used : TargetField(org.kie.pmml.api.models.TargetField) Test(org.junit.Test)

Example 15 with TargetField

use of org.kie.pmml.api.models.TargetField in project drools by kiegroup.

the class KiePMMLTargetTest method applyRescaleConstant.

@Test
public void applyRescaleConstant() {
    TargetField targetField = new TargetField(Collections.emptyList(), null, "string", null, null, null, null, null);
    KiePMMLTarget kiePMMLTarget = getBuilder(targetField).build();
    assertEquals(6.0, kiePMMLTarget.applyRescaleConstant(6.0), 0.0);
    targetField = new TargetField(Collections.emptyList(), null, "string", null, null, null, 2.0, null);
    kiePMMLTarget = getBuilder(targetField).build();
    assertEquals(8.0, kiePMMLTarget.applyRescaleConstant(6.0), 0.0);
}
Also used : TargetField(org.kie.pmml.api.models.TargetField) Test(org.junit.Test)

Aggregations

TargetField (org.kie.pmml.api.models.TargetField)15 Test (org.junit.Test)12 Expression (com.github.javaparser.ast.expr.Expression)6 TargetValue (org.kie.pmml.api.models.TargetValue)6 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)5 CAST_INTEGER (org.kie.pmml.api.enums.CAST_INTEGER)5 OP_TYPE (org.kie.pmml.api.enums.OP_TYPE)5 KiePMMLTarget (org.kie.pmml.commons.model.KiePMMLTarget)5 KiePMMLTargetValue (org.kie.pmml.commons.model.KiePMMLTargetValue)5 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)4 NameExpr (com.github.javaparser.ast.expr.NameExpr)4 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)4 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)4 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)4 CompilationUnit (com.github.javaparser.ast.CompilationUnit)3 NodeList (com.github.javaparser.ast.NodeList)3 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)3 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)3 ExplicitConstructorInvocationStmt (com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt)3 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)3