Search in sources :

Example 1 with CAST_INTEGER

use of org.kie.pmml.api.enums.CAST_INTEGER in project drools by kiegroup.

the class KiePMMLTargetInstanceFactory method getKiePMMLTarget.

public static KiePMMLTarget getKiePMMLTarget(final Target target) {
    final List<TargetValue> targetValues = target.hasTargetValues() ? target.getTargetValues().stream().map(KiePMMLTargetInstanceFactory::getKieTargetValue).collect(Collectors.toList()) : Collections.emptyList();
    final OP_TYPE opType = target.getOpType() != null ? OP_TYPE.byName(target.getOpType().value()) : null;
    final String field = target.getField() != null ? target.getField().getValue() : null;
    final CAST_INTEGER castInteger = target.getCastInteger() != null ? CAST_INTEGER.byName(target.getCastInteger().value()) : null;
    TargetField targetField = new TargetField(targetValues, opType, field, castInteger, target.getMin(), target.getMax(), target.getRescaleConstant(), target.getRescaleFactor());
    final KiePMMLTarget.Builder builder = KiePMMLTarget.builder(targetField.getName(), Collections.emptyList(), targetField);
    return builder.build();
}
Also used : TargetValue(org.kie.pmml.api.models.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) KiePMMLTarget(org.kie.pmml.commons.model.KiePMMLTarget)

Example 2 with CAST_INTEGER

use of org.kie.pmml.api.enums.CAST_INTEGER in project drools by kiegroup.

the class InstanceFactoriesTestCommon method commonVerifyKiePMMLTarget.

static void commonVerifyKiePMMLTarget(KiePMMLTarget toVerify, Target source) {
    assertNotNull(toVerify);
    assertEquals(toVerify.getTargetValues().size(), source.getTargetValues().size());
    OP_TYPE expectedOpType = OP_TYPE.byName(source.getOpType().value());
    assertEquals(expectedOpType, toVerify.getOpType());
    assertEquals(source.getField().getValue(), toVerify.getField());
    CAST_INTEGER expectedCastInteger = CAST_INTEGER.byName(source.getCastInteger().value());
    assertEquals(expectedCastInteger, toVerify.getCastInteger());
    assertEquals(source.getMin().doubleValue(), toVerify.getMin(), 0.0);
    assertEquals(source.getMax().doubleValue(), toVerify.getMax(), 0.0);
    assertEquals(source.getRescaleConstant().doubleValue(), toVerify.getRescaleConstant(), 0.0);
    assertEquals(source.getRescaleFactor().doubleValue(), toVerify.getRescaleFactor(), 0.0);
}
Also used : OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) CAST_INTEGER(org.kie.pmml.api.enums.CAST_INTEGER)

Example 3 with CAST_INTEGER

use of org.kie.pmml.api.enums.CAST_INTEGER in project drools by kiegroup.

the class TargetFieldFactory method getTargetFieldVariableInitializer.

static ObjectCreationExpr getTargetFieldVariableInitializer(final TargetField targetField) {
    final MethodDeclaration methodDeclaration = TARGET_TEMPLATE.getMethodsByName(GETTARGET_FIELD).get(0).clone();
    final BlockStmt targetBody = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
    final VariableDeclarator variableDeclarator = getVariableDeclarator(targetBody, TARGET_FIELD).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, TARGET_FIELD, targetBody)));
    variableDeclarator.setName(targetField.getName());
    final ObjectCreationExpr toReturn = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, TARGET_FIELD, targetBody))).asObjectCreationExpr();
    final NodeList<Expression> arguments = new NodeList<>();
    if (targetField.getTargetValues() != null) {
        for (TargetValue targetValue : targetField.getTargetValues()) {
            arguments.add(getTargetValueVariableInitializer(targetValue));
        }
    }
    toReturn.getArgument(0).asMethodCallExpr().setArguments(arguments);
    OP_TYPE oPT = targetField.getOpType();
    Expression opType = oPT != null ? new NameExpr(oPT.getClass().getName() + "." + oPT.name()) : new NullLiteralExpr();
    toReturn.setArgument(1, opType);
    toReturn.setArgument(2, getExpressionForObject(targetField.getField()));
    CAST_INTEGER cstInt = targetField.getCastInteger();
    Expression castInteger = cstInt != null ? new NameExpr(cstInt.getClass().getName() + "." + cstInt.name()) : new NullLiteralExpr();
    toReturn.setArgument(3, castInteger);
    toReturn.setArgument(4, getExpressionForObject(targetField.getMin()));
    toReturn.setArgument(5, getExpressionForObject(targetField.getMax()));
    toReturn.setArgument(6, getExpressionForObject(targetField.getRescaleConstant()));
    toReturn.setArgument(7, getExpressionForObject(targetField.getRescaleFactor()));
    return toReturn;
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) TargetValue(org.kie.pmml.api.models.TargetValue) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NodeList(com.github.javaparser.ast.NodeList) NameExpr(com.github.javaparser.ast.expr.NameExpr) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) CommonCodegenUtils.getVariableDeclarator(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.getVariableDeclarator) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) Expression(com.github.javaparser.ast.expr.Expression) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) CAST_INTEGER(org.kie.pmml.api.enums.CAST_INTEGER)

Example 4 with CAST_INTEGER

use of org.kie.pmml.api.enums.CAST_INTEGER 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)

Aggregations

CAST_INTEGER (org.kie.pmml.api.enums.CAST_INTEGER)4 OP_TYPE (org.kie.pmml.api.enums.OP_TYPE)4 TargetField (org.kie.pmml.api.models.TargetField)2 TargetValue (org.kie.pmml.api.models.TargetValue)2 NodeList (com.github.javaparser.ast.NodeList)1 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)1 Expression (com.github.javaparser.ast.expr.Expression)1 NameExpr (com.github.javaparser.ast.expr.NameExpr)1 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)1 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)1 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 TargetValue (org.dmg.pmml.TargetValue)1 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)1 KiePMMLTarget (org.kie.pmml.commons.model.KiePMMLTarget)1 CommonCodegenUtils.getVariableDeclarator (org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.getVariableDeclarator)1