Search in sources :

Example 1 with KiePMMLScoreDistribution

use of org.kie.pmml.models.tree.model.KiePMMLScoreDistribution in project drools by kiegroup.

the class KiePMMLNodeFactory method populateEvaluateNodeWithScoreDistributions.

/**
 * Set the <b>scoreDistribution</b> <code>VariableDeclarator</code> initializer of the given <code>BlockStmt</code>.
 * If <b>scoreDistributionsParam</b> is <code>null</code>, a <code>NullLiteralExpr</code> is set.
 * <p>
 *     <code>List<KiePMMLScoreDistribution> scoreDistributions = null;</code>
 * </p>
 * Otherwise
 * <p>
 *     <code>List<KiePMMLScoreDistribution> scoreDistributions = arrays.asList(new KiePMMLScoreDistribution(....));</code>
 * </p>
 *
 * @param toPopulate
 * @param scoreDistributionsParam
 */
static void populateEvaluateNodeWithScoreDistributions(final BlockStmt toPopulate, final List<ScoreDistribution> scoreDistributionsParam) {
    final Expression scoreDistributionsExpression;
    if (scoreDistributionsParam == null) {
        scoreDistributionsExpression = new NullLiteralExpr();
    } else {
        int counter = 0;
        final NodeList<Expression> scoreDistributionsArguments = new NodeList<>();
        for (ScoreDistribution scoreDistribution : scoreDistributionsParam) {
            String nestedVariableName = String.format("scoreDistribution_%s", counter);
            scoreDistributionsArguments.add(getKiePMMLScoreDistribution(nestedVariableName, scoreDistribution));
            counter++;
        }
        scoreDistributionsExpression = new MethodCallExpr();
        ((MethodCallExpr) scoreDistributionsExpression).setScope(new NameExpr(Arrays.class.getSimpleName()));
        ((MethodCallExpr) scoreDistributionsExpression).setName("asList");
        ((MethodCallExpr) scoreDistributionsExpression).setArguments(scoreDistributionsArguments);
    }
    CommonCodegenUtils.setVariableDeclaratorValue(toPopulate, SCORE_DISTRIBUTIONS, scoreDistributionsExpression);
}
Also used : NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) KiePMMLScoreDistribution(org.kie.pmml.models.tree.model.KiePMMLScoreDistribution) ScoreDistribution(org.dmg.pmml.ScoreDistribution) Expression(com.github.javaparser.ast.expr.Expression) NodeList(com.github.javaparser.ast.NodeList) NameExpr(com.github.javaparser.ast.expr.NameExpr) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

NodeList (com.github.javaparser.ast.NodeList)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 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)1 ScoreDistribution (org.dmg.pmml.ScoreDistribution)1 KiePMMLScoreDistribution (org.kie.pmml.models.tree.model.KiePMMLScoreDistribution)1