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();
}
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);
}
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;
}
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);
}
Aggregations