Search in sources :

Example 1 with REGRESSION_NORMALIZATION_METHOD

use of org.kie.pmml.models.regression.model.enums.REGRESSION_NORMALIZATION_METHOD in project drools by kiegroup.

the class KiePMMLClassificationTableFactory method setStaticGetter.

// not-public code-generation
static void setStaticGetter(final RegressionCompilationDTO compilationDTO, final LinkedHashMap<String, KiePMMLTableSourceCategory> regressionTablesMap, final MethodDeclaration staticGetterMethod, final String variableName) {
    final BlockStmt classificationTableBody = staticGetterMethod.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, staticGetterMethod)));
    final VariableDeclarator variableDeclarator = getVariableDeclarator(classificationTableBody, TO_RETURN).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, TO_RETURN, classificationTableBody)));
    final BlockStmt newBody = new BlockStmt();
    final Map<String, Expression> regressionTableCategoriesMap = new LinkedHashMap<>();
    regressionTablesMap.forEach((className, tableSourceCategory) -> {
        MethodCallExpr methodCallExpr = new MethodCallExpr();
        methodCallExpr.setScope(new NameExpr(className));
        methodCallExpr.setName(KiePMMLRegressionTableFactory.GETKIEPMML_TABLE);
        regressionTableCategoriesMap.put(tableSourceCategory.getCategory(), methodCallExpr);
    });
    // populate map
    String categoryTableMapName = String.format(VARIABLE_NAME_TEMPLATE, CATEGORICAL_TABLE_MAP, variableName);
    createPopulatedLinkedHashMap(newBody, categoryTableMapName, Arrays.asList(String.class.getSimpleName(), KiePMMLRegressionTable.class.getName()), regressionTableCategoriesMap);
    final MethodCallExpr initializer = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, TO_RETURN, classificationTableBody))).asMethodCallExpr();
    final MethodCallExpr builder = getChainedMethodCallExprFrom("builder", initializer);
    builder.setArgument(0, new StringLiteralExpr(variableName));
    final REGRESSION_NORMALIZATION_METHOD regressionNormalizationMethod = compilationDTO.getDefaultREGRESSION_NORMALIZATION_METHOD();
    getChainedMethodCallExprFrom("withRegressionNormalizationMethod", initializer).setArgument(0, new NameExpr(regressionNormalizationMethod.getClass().getSimpleName() + "." + regressionNormalizationMethod.name()));
    OP_TYPE opType = compilationDTO.getOP_TYPE();
    getChainedMethodCallExprFrom("withOpType", initializer).setArgument(0, new NameExpr(opType.getClass().getSimpleName() + "." + opType.name()));
    getChainedMethodCallExprFrom("withCategoryTableMap", initializer).setArgument(0, new NameExpr(categoryTableMapName));
    boolean isBinary = compilationDTO.isBinary(regressionTablesMap.size());
    final Expression probabilityMapFunctionExpression = getProbabilityMapFunctionExpression(compilationDTO.getModelNormalizationMethod(), isBinary);
    getChainedMethodCallExprFrom("withProbabilityMapFunction", initializer).setArgument(0, probabilityMapFunctionExpression);
    getChainedMethodCallExprFrom("withIsBinary", initializer).setArgument(0, getExpressionForObject(isBinary));
    getChainedMethodCallExprFrom("withTargetField", initializer).setArgument(0, getExpressionForObject(compilationDTO.getTargetFieldName()));
    getChainedMethodCallExprFrom("withTargetCategory", initializer).setArgument(0, getExpressionForObject(null));
    classificationTableBody.getStatements().forEach(newBody::addStatement);
    staticGetterMethod.setBody(newBody);
}
Also used : BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) CommonCodegenUtils.getVariableDeclarator(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.getVariableDeclarator) LinkedHashMap(java.util.LinkedHashMap) CommonCodegenUtils.createPopulatedLinkedHashMap(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.createPopulatedLinkedHashMap) Expression(com.github.javaparser.ast.expr.Expression) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) REGRESSION_NORMALIZATION_METHOD(org.kie.pmml.models.regression.model.enums.REGRESSION_NORMALIZATION_METHOD) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)1 Expression (com.github.javaparser.ast.expr.Expression)1 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)1 NameExpr (com.github.javaparser.ast.expr.NameExpr)1 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)1 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 LinkedHashMap (java.util.LinkedHashMap)1 OP_TYPE (org.kie.pmml.api.enums.OP_TYPE)1 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)1 CommonCodegenUtils.createPopulatedLinkedHashMap (org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.createPopulatedLinkedHashMap)1 CommonCodegenUtils.getVariableDeclarator (org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.getVariableDeclarator)1 REGRESSION_NORMALIZATION_METHOD (org.kie.pmml.models.regression.model.enums.REGRESSION_NORMALIZATION_METHOD)1