KiePMMLRegressionTableClassificationFactory { static void populateOutputFieldsMapWithProbability(final BlockStmt body, final List<KiePMMLOutputField> outputFields) { outputFields.stream() .filter(outputField -> PROBABILITY.equals(outputField.getResultFeature())) .forEach(outputField -> { StringLiteralExpr key = new StringLiteralExpr(outputField.getName()); Expression value = null; if (outputField.getValue() != null) { NodeList<Expression> expressions = NodeList.nodeList(new StringLiteralExpr(outputField.getValue().toString())); value = new MethodCallExpr(new NameExpr("probabilityMap"), "get", expressions); } else if (outputField.getTargetField().isPresent()) { NodeList<Expression> expressions = NodeList.nodeList(new StringLiteralExpr(outputField.getTargetField().get())); value = new MethodCallExpr(new NameExpr("probabilityMap"), "get", expressions); } if (value != null) { NodeList<Expression> expressions = NodeList.nodeList(key, value); body.addStatement(new MethodCallExpr(new NameExpr("outputFieldsMap"), "put", expressions)); } }); } private  KiePMMLRegressionTableClassificationFactory(); static Map<String, KiePMMLTableSourceCategory> getRegressionTables(final List<RegressionTable> regressionTables, final RegressionModel.NormalizationMethod normalizationMethod, final OpType opType, final List<KiePMMLOutputField> outputFields, final String targetField, final String packageName); static Map.Entry<String, String> getRegressionTable(final LinkedHashMap<String, KiePMMLTableSourceCategory> regressionTablesMap, final RegressionModel.NormalizationMethod normalizationMethod, final OpType opType, final List<KiePMMLOutputField> outputFields, final String targetField, final String packageName); static final String KIE_PMML_REGRESSION_TABLE_CLASSIFICATION_TEMPLATE_JAVA; static final String KIE_PMML_REGRESSION_TABLE_CLASSIFICATION_TEMPLATE; }
@Test public void populateOutputFieldsMapWithProbability() { final List<KiePMMLOutputField> outputFields = IntStream.range(0, 2) .mapToObj(index -> getOutputField("KOF-PROB-" + index, RESULT_FEATURE.PROBABILITY, "PROB-" + index)) .collect(Collectors.toList()); final MethodDeclaration methodDeclaration = modelTemplate.getMethodsByName("populateOutputFieldsMapWithProbability").get(0); final BlockStmt body = methodDeclaration.getBody().get(); KiePMMLRegressionTableClassificationFactory.populateOutputFieldsMapWithProbability(body, outputFields); NodeList<Statement> retrieved = body.getStatements(); assertEquals(outputFields.size(), retrieved.size()); retrieved.forEach(statement -> { assertTrue(statement instanceof ExpressionStmt); assertTrue(((ExpressionStmt) statement).getExpression() instanceof MethodCallExpr); MethodCallExpr methodCallExpr = (MethodCallExpr) ((ExpressionStmt) statement).getExpression(); assertEquals("outputFieldsMap", methodCallExpr.getScope().get().asNameExpr().toString()); assertEquals("put", methodCallExpr.getName().asString()); assertTrue(methodCallExpr.getArguments().get(1) instanceof MethodCallExpr); MethodCallExpr nestedMethodCallExpr = (MethodCallExpr) methodCallExpr.getArguments().get(1); assertEquals("probabilityMap", nestedMethodCallExpr.getScope().get().asNameExpr().toString()); assertEquals("get", nestedMethodCallExpr.getName().asString()); }); List<MethodCallExpr> methodCallExprs = retrieved.stream() .map(statement -> (MethodCallExpr) ((ExpressionStmt) statement).getExpression()) .collect(Collectors.toList()); outputFields.forEach(outputField -> assertTrue(methodCallExprs.stream() .anyMatch(methodCallExpr -> { StringLiteralExpr stringLiteralExpr = (StringLiteralExpr) methodCallExpr.getArguments().get(0); MethodCallExpr nestedMethodCallExpr = (MethodCallExpr) methodCallExpr.getArguments().get(1); StringLiteralExpr nestedStringLiteralExpr = (StringLiteralExpr) nestedMethodCallExpr.getArguments().get(0); return outputField.getName().equals(stringLiteralExpr.getValue()) && outputField.getTargetField().get().equals(nestedStringLiteralExpr.getValue()); }))); }