use of org.kie.pmml.api.exceptions.KiePMMLInternalException in project drools by kiegroup.
the class KiePMMLRegressionTableFactory method getPredictorTermFunction.
/**
* Get the <b>PredictorTerm</b> <code>VariableDeclarationExpr</code>
* @param predictorTerm
* @return
*/
static LambdaExpr getPredictorTermFunction(final PredictorTerm predictorTerm) {
try {
LambdaExpr toReturn = new LambdaExpr();
toReturn.setParameters(NodeList.nodeList(new Parameter(new UnknownType(), "resultMap")));
final BlockStmt body = getPredictorTermBody(predictorTerm);
toReturn.setBody(body);
return toReturn;
} catch (Exception e) {
throw new KiePMMLInternalException(String.format("Failed to get PredictorTermFunction for %s", predictorTerm), e);
}
}
use of org.kie.pmml.api.exceptions.KiePMMLInternalException in project drools by kiegroup.
the class KiePMMLCharacteristicsFactory method setCharacteristicsVariableDeclaration.
static void setCharacteristicsVariableDeclaration(final String characteristicsClassName, final Characteristics characteristics, final List<Field<?>> fields, final ClassOrInterfaceDeclaration characteristicsTemplate) {
int counter = 0;
NodeList<Expression> arguments = new NodeList<>();
for (Characteristic characteristic : characteristics.getCharacteristics()) {
String characteristicVariableName = String.format(VARIABLE_NAME_TEMPLATE, characteristicsClassName, counter);
addGetCharacteristicMethod(characteristicVariableName, characteristic, fields, characteristicsTemplate);
MethodCallExpr toAdd = new MethodCallExpr();
toAdd.setScope(new NameExpr(characteristicsClassName));
toAdd.setName("get" + characteristicVariableName);
arguments.add(toAdd);
counter++;
}
final ConstructorDeclaration constructorDeclaration = characteristicsTemplate.getDefaultConstructor().orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, characteristicsTemplate.getName())));
constructorDeclaration.setName(characteristicsClassName);
final BlockStmt body = constructorDeclaration.getBody();
final ExplicitConstructorInvocationStmt superStatement = CommonCodegenUtils.getExplicitConstructorInvocationStmt(body).orElseThrow(() -> new KiePMMLException(String.format(MISSING_CONSTRUCTOR_IN_BODY, body)));
superStatement.setArgument(0, new StringLiteralExpr(characteristicsClassName));
superStatement.setArgument(2, getArraysAsListInvocationMethodCall(arguments));
}
use of org.kie.pmml.api.exceptions.KiePMMLInternalException in project drools by kiegroup.
the class KiePMMLScorecardModelFactory method setConstructor.
static void setConstructor(final ScorecardCompilationDTO compilationDTO, final ClassOrInterfaceDeclaration modelTemplate, final String fullCharacteristicsClassName) {
KiePMMLModelFactoryUtils.init(compilationDTO, modelTemplate);
final ConstructorDeclaration constructorDeclaration = modelTemplate.getDefaultConstructor().orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, modelTemplate.getName())));
final BlockStmt body = constructorDeclaration.getBody();
final ExplicitConstructorInvocationStmt superStatement = CommonCodegenUtils.getExplicitConstructorInvocationStmt(body).orElseThrow(() -> new KiePMMLException(String.format(MISSING_CONSTRUCTOR_IN_BODY, body)));
ClassOrInterfaceType characteristicsClass = parseClassOrInterfaceType(fullCharacteristicsClassName);
ObjectCreationExpr characteristicsReference = new ObjectCreationExpr();
characteristicsReference.setType(characteristicsClass);
superStatement.setArgument(2, characteristicsReference);
superStatement.setArgument(3, getExpressionForObject(compilationDTO.getInitialScore()));
superStatement.setArgument(4, getExpressionForObject(compilationDTO.isUseReasonCodes()));
REASONCODE_ALGORITHM reasoncodeAlgorithm = compilationDTO.getREASONCODE_ALGORITHM();
NameExpr reasonCodeExpr = new NameExpr(REASONCODE_ALGORITHM.class.getName() + "." + reasoncodeAlgorithm.name());
superStatement.setArgument(5, reasonCodeExpr);
superStatement.setArgument(6, getExpressionForObject(compilationDTO.getBaselineScore()));
}
Aggregations