@Test public void addNumericPredictorWithoutExponent() { String predictorName = "predictorName"; int exponent = 1; double coefficient = 1.23; NumericPredictor numericPredictor = PMMLModelTestUtils.getNumericPredictor(predictorName, exponent, coefficient); int arity = 3; ClassOrInterfaceDeclaration tableTemplate = new ClassOrInterfaceDeclaration(); MethodDeclaration retrieved = KiePMMLRegressionTableRegressionFactory.addNumericPredictor(numericPredictor, tableTemplate, arity); BlockStmt body = retrieved.getBody().get(); String expected = String.format("{\n" + " double coefficient = %s;\n" + " " return input * coefficient;\n" + "}", coefficient); assertEquals(expected, body.toString()); }
static MethodDeclaration addNumericPredictor(final NumericPredictor numericPredictor, final ClassOrInterfaceDeclaration tableTemplate, int predictorArity) { try { templateEvaluate = getFromFileName(KIE_PMML_EVALUATE_METHOD_TEMPLATE_JAVA); cloneEvaluate = templateEvaluate.clone(); ClassOrInterfaceDeclaration evaluateTemplateClass = cloneEvaluate.getClassByName(KIE_PMML_EVALUATE_METHOD_TEMPLATE) .orElseThrow(() -> new RuntimeException(MAIN_CLASS_NOT_FOUND)); MethodDeclaration methodTemplate; if (Objects.equals(1, numericPredictor.getExponent())) { methodTemplate = getNumericPredictorWithoutExponentTemplate(numericPredictor, evaluateTemplateClass); } else { methodTemplate = getNumericPredictorWithExponentTemplate(numericPredictor, evaluateTemplateClass); } return addMethod(methodTemplate, tableTemplate, "evaluateNumericPredictor" + predictorArity); } catch (Exception e) { throw new KiePMMLInternalException(String.format("Failed to add NumericPredictor %s", numericPredictor.getName()), e); } }
KiePMMLRegressionTableRegressionFactory { static MethodDeclaration addNumericPredictor(final NumericPredictor numericPredictor, final ClassOrInterfaceDeclaration tableTemplate, int predictorArity) { try { templateEvaluate = getFromFileName(KIE_PMML_EVALUATE_METHOD_TEMPLATE_JAVA); cloneEvaluate = templateEvaluate.clone(); ClassOrInterfaceDeclaration evaluateTemplateClass = cloneEvaluate.getClassByName(KIE_PMML_EVALUATE_METHOD_TEMPLATE) .orElseThrow(() -> new RuntimeException(MAIN_CLASS_NOT_FOUND)); MethodDeclaration methodTemplate; if (Objects.equals(1, numericPredictor.getExponent())) { methodTemplate = getNumericPredictorWithoutExponentTemplate(numericPredictor, evaluateTemplateClass); } else { methodTemplate = getNumericPredictorWithExponentTemplate(numericPredictor, evaluateTemplateClass); } return addMethod(methodTemplate, tableTemplate, "evaluateNumericPredictor" + predictorArity); } catch (Exception e) { throw new KiePMMLInternalException(String.format("Failed to add NumericPredictor %s", numericPredictor.getName()), e); } } }
KiePMMLRegressionTableRegressionFactory { static MethodDeclaration addNumericPredictor(final NumericPredictor numericPredictor, final ClassOrInterfaceDeclaration tableTemplate, int predictorArity) { try { templateEvaluate = getFromFileName(KIE_PMML_EVALUATE_METHOD_TEMPLATE_JAVA); cloneEvaluate = templateEvaluate.clone(); ClassOrInterfaceDeclaration evaluateTemplateClass = cloneEvaluate.getClassByName(KIE_PMML_EVALUATE_METHOD_TEMPLATE) .orElseThrow(() -> new RuntimeException(MAIN_CLASS_NOT_FOUND)); MethodDeclaration methodTemplate; if (Objects.equals(1, numericPredictor.getExponent())) { methodTemplate = getNumericPredictorWithoutExponentTemplate(numericPredictor, evaluateTemplateClass); } else { methodTemplate = getNumericPredictorWithExponentTemplate(numericPredictor, evaluateTemplateClass); } return addMethod(methodTemplate, tableTemplate, "evaluateNumericPredictor" + predictorArity); } catch (Exception e) { throw new KiePMMLInternalException(String.format("Failed to add NumericPredictor %s", numericPredictor.getName()), e); } } private  KiePMMLRegressionTableRegressionFactory(); }
KiePMMLRegressionTableRegressionFactory { static MethodDeclaration addNumericPredictor(final NumericPredictor numericPredictor, final ClassOrInterfaceDeclaration tableTemplate, int predictorArity) { try { templateEvaluate = getFromFileName(KIE_PMML_EVALUATE_METHOD_TEMPLATE_JAVA); cloneEvaluate = templateEvaluate.clone(); ClassOrInterfaceDeclaration evaluateTemplateClass = cloneEvaluate.getClassByName(KIE_PMML_EVALUATE_METHOD_TEMPLATE) .orElseThrow(() -> new RuntimeException(MAIN_CLASS_NOT_FOUND)); MethodDeclaration methodTemplate; if (Objects.equals(1, numericPredictor.getExponent())) { methodTemplate = getNumericPredictorWithoutExponentTemplate(numericPredictor, evaluateTemplateClass); } else { methodTemplate = getNumericPredictorWithExponentTemplate(numericPredictor, evaluateTemplateClass); } return addMethod(methodTemplate, tableTemplate, "evaluateNumericPredictor" + predictorArity); } catch (Exception e) { throw new KiePMMLInternalException(String.format("Failed to add NumericPredictor %s", numericPredictor.getName()), e); } } private  KiePMMLRegressionTableRegressionFactory(); static LinkedHashMap<String, KiePMMLTableSourceCategory> getRegressionTables(final List<RegressionTable> regressionTables,
                                                                                        final RegressionModel.NormalizationMethod normalizationMethod,
                                                                                        final List<KiePMMLOutputField> outputFields,
                                                                                        final String targetField,
                                                                                        final String packageName); static Map.Entry<String, String> getRegressionTable(final RegressionTable regressionTable,
                                                               final RegressionModel.NormalizationMethod normalizationMethod,
                                                               final List<KiePMMLOutputField> outputFields,
                                                               final String targetField,
                                                               final String packageName); }
KiePMMLRegressionTableRegressionFactory { static MethodDeclaration addNumericPredictor(final NumericPredictor numericPredictor, final ClassOrInterfaceDeclaration tableTemplate, int predictorArity) { try { templateEvaluate = getFromFileName(KIE_PMML_EVALUATE_METHOD_TEMPLATE_JAVA); cloneEvaluate = templateEvaluate.clone(); ClassOrInterfaceDeclaration evaluateTemplateClass = cloneEvaluate.getClassByName(KIE_PMML_EVALUATE_METHOD_TEMPLATE) .orElseThrow(() -> new RuntimeException(MAIN_CLASS_NOT_FOUND)); MethodDeclaration methodTemplate; if (Objects.equals(1, numericPredictor.getExponent())) { methodTemplate = getNumericPredictorWithoutExponentTemplate(numericPredictor, evaluateTemplateClass); } else { methodTemplate = getNumericPredictorWithExponentTemplate(numericPredictor, evaluateTemplateClass); } return addMethod(methodTemplate, tableTemplate, "evaluateNumericPredictor" + predictorArity); } catch (Exception e) { throw new KiePMMLInternalException(String.format("Failed to add NumericPredictor %s", numericPredictor.getName()), e); } } private  KiePMMLRegressionTableRegressionFactory(); static LinkedHashMap<String, KiePMMLTableSourceCategory> getRegressionTables(final List<RegressionTable> regressionTables,
                                                                                        final RegressionModel.NormalizationMethod normalizationMethod,
                                                                                        final List<KiePMMLOutputField> outputFields,
                                                                                        final String targetField,
                                                                                        final String packageName); static Map.Entry<String, String> getRegressionTable(final RegressionTable regressionTable,
                                                               final RegressionModel.NormalizationMethod normalizationMethod,
                                                               final List<KiePMMLOutputField> outputFields,
                                                               final String targetField,
                                                               final String packageName); static final String KIE_PMML_REGRESSION_TABLE_REGRESSION_TEMPLATE_JAVA; static final String KIE_PMML_REGRESSION_TABLE_REGRESSION_TEMPLATE; }