Search in sources :

Example 21 with KiePMMLInternalException

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);
    }
}
Also used : UnknownType(com.github.javaparser.ast.type.UnknownType) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) Parameter(com.github.javaparser.ast.body.Parameter) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException)

Example 22 with KiePMMLInternalException

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));
}
Also used : NodeList(com.github.javaparser.ast.NodeList) Characteristic(org.dmg.pmml.scorecard.Characteristic) KiePMMLCharacteristic(org.kie.pmml.models.scorecard.model.KiePMMLCharacteristic) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt) Expression(com.github.javaparser.ast.expr.Expression) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 23 with KiePMMLInternalException

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()));
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) REASONCODE_ALGORITHM(org.kie.pmml.api.enums.REASONCODE_ALGORITHM) NameExpr(com.github.javaparser.ast.expr.NameExpr) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt) StaticJavaParser.parseClassOrInterfaceType(com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType)

Aggregations

KiePMMLInternalException (org.kie.pmml.api.exceptions.KiePMMLInternalException)23 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)17 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)15 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)14 CompilationUnit (com.github.javaparser.ast.CompilationUnit)7 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)7 Expression (com.github.javaparser.ast.expr.Expression)7 NameExpr (com.github.javaparser.ast.expr.NameExpr)7 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)5 NodeList (com.github.javaparser.ast.NodeList)4 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)4 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)4 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)4 ExplicitConstructorInvocationStmt (com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt)4 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)4 HashMap (java.util.HashMap)4 MethodReferenceExpr (com.github.javaparser.ast.expr.MethodReferenceExpr)3 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)3 Map (java.util.Map)3 MINING_FUNCTION (org.kie.pmml.api.enums.MINING_FUNCTION)3