@Test public void setConstructor() { Model model = new MiningModel(); PMML_MODEL pmmlModel = PMML_MODEL.byName(model.getClass().getSimpleName()); ConstructorDeclaration constructorDeclaration = MODEL_TEMPLATE.getDefaultConstructor().get(); String targetField = "TARGET_FIELD"; MINING_FUNCTION miningFunction = MINING_FUNCTION.CLASSIFICATION; String generatedClassName = "GENERATEDCLASSNAME"; String segmentationClass = "SEGMENTATIONCLASS"; KiePMMLMiningModelFactory.setConstructor(generatedClassName, constructorDeclaration, targetField, miningFunction, pmmlModel.name(), segmentationClass); Map<Integer, Expression> superInvocationExpressionsMap = new HashMap<>(); superInvocationExpressionsMap.put(0, new NameExpr(String.format("\"%s\"", pmmlModel.name()))); Map<String, Expression> assignExpressionMap = new HashMap<>(); assignExpressionMap.put("targetField", new StringLiteralExpr(targetField)); assignExpressionMap.put("miningFunction", new NameExpr(miningFunction.getClass().getName() + "." + miningFunction.name())); assignExpressionMap.put("pmmlMODEL", new NameExpr(pmmlModel.getClass().getName() + "." + pmmlModel.name())); ClassOrInterfaceType kiePMMLSegmentationClass = parseClassOrInterfaceType(segmentationClass); ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(kiePMMLSegmentationClass); assignExpressionMap.put("segmentation", objectCreationExpr); assertTrue(commonEvaluateConstructor(constructorDeclaration, generatedClassName, superInvocationExpressionsMap, assignExpressionMap)); }
static void setConstructor(final String generatedClassName, final ConstructorDeclaration constructorDeclaration, final String targetField, final MINING_FUNCTION miningFunction, final String modelName, final String segmentationClass) { setConstructorSuperNameInvocation(generatedClassName, constructorDeclaration, modelName); final BlockStmt body = constructorDeclaration.getBody(); CommonCodegenUtils.setAssignExpressionValue(body, "targetField", new StringLiteralExpr(targetField)); CommonCodegenUtils.setAssignExpressionValue(body, "miningFunction", new NameExpr(miningFunction.getClass().getName() + "." + miningFunction.name())); CommonCodegenUtils.setAssignExpressionValue(body, "pmmlMODEL", new NameExpr(PMML_MODEL.MINING_MODEL.getClass().getName() + "." + PMML_MODEL.MINING_MODEL.name())); ClassOrInterfaceType kiePMMLSegmentationClass = parseClassOrInterfaceType(segmentationClass); ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(kiePMMLSegmentationClass); CommonCodegenUtils.setAssignExpressionValue(body, "segmentation", objectCreationExpr); }
KiePMMLMiningModelFactory { static void setConstructor(final String generatedClassName, final ConstructorDeclaration constructorDeclaration, final String targetField, final MINING_FUNCTION miningFunction, final String modelName, final String segmentationClass) { setConstructorSuperNameInvocation(generatedClassName, constructorDeclaration, modelName); final BlockStmt body = constructorDeclaration.getBody(); CommonCodegenUtils.setAssignExpressionValue(body, "targetField", new StringLiteralExpr(targetField)); CommonCodegenUtils.setAssignExpressionValue(body, "miningFunction", new NameExpr(miningFunction.getClass().getName() + "." + miningFunction.name())); CommonCodegenUtils.setAssignExpressionValue(body, "pmmlMODEL", new NameExpr(PMML_MODEL.MINING_MODEL.getClass().getName() + "." + PMML_MODEL.MINING_MODEL.name())); ClassOrInterfaceType kiePMMLSegmentationClass = parseClassOrInterfaceType(segmentationClass); ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(kiePMMLSegmentationClass); CommonCodegenUtils.setAssignExpressionValue(body, "segmentation", objectCreationExpr); } }
KiePMMLMiningModelFactory { static void setConstructor(final String generatedClassName, final ConstructorDeclaration constructorDeclaration, final String targetField, final MINING_FUNCTION miningFunction, final String modelName, final String segmentationClass) { setConstructorSuperNameInvocation(generatedClassName, constructorDeclaration, modelName); final BlockStmt body = constructorDeclaration.getBody(); CommonCodegenUtils.setAssignExpressionValue(body, "targetField", new StringLiteralExpr(targetField)); CommonCodegenUtils.setAssignExpressionValue(body, "miningFunction", new NameExpr(miningFunction.getClass().getName() + "." + miningFunction.name())); CommonCodegenUtils.setAssignExpressionValue(body, "pmmlMODEL", new NameExpr(PMML_MODEL.MINING_MODEL.getClass().getName() + "." + PMML_MODEL.MINING_MODEL.name())); ClassOrInterfaceType kiePMMLSegmentationClass = parseClassOrInterfaceType(segmentationClass); ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(kiePMMLSegmentationClass); CommonCodegenUtils.setAssignExpressionValue(body, "segmentation", objectCreationExpr); } private  KiePMMLMiningModelFactory(); }
KiePMMLMiningModelFactory { static void setConstructor(final String generatedClassName, final ConstructorDeclaration constructorDeclaration, final String targetField, final MINING_FUNCTION miningFunction, final String modelName, final String segmentationClass) { setConstructorSuperNameInvocation(generatedClassName, constructorDeclaration, modelName); final BlockStmt body = constructorDeclaration.getBody(); CommonCodegenUtils.setAssignExpressionValue(body, "targetField", new StringLiteralExpr(targetField)); CommonCodegenUtils.setAssignExpressionValue(body, "miningFunction", new NameExpr(miningFunction.getClass().getName() + "." + miningFunction.name())); CommonCodegenUtils.setAssignExpressionValue(body, "pmmlMODEL", new NameExpr(PMML_MODEL.MINING_MODEL.getClass().getName() + "." + PMML_MODEL.MINING_MODEL.name())); ClassOrInterfaceType kiePMMLSegmentationClass = parseClassOrInterfaceType(segmentationClass); ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(kiePMMLSegmentationClass); CommonCodegenUtils.setAssignExpressionValue(body, "segmentation", objectCreationExpr); } private  KiePMMLMiningModelFactory(); static KiePMMLMiningModel getKiePMMLMiningModel(final DataDictionary dataDictionary,
                                                           final TransformationDictionary transformationDictionary,
                                                           final MiningModel model,
                                                           final KnowledgeBuilder kBuilder); static Map<String, String> getKiePMMLMiningModelSourcesMap(final DataDictionary dataDictionary,
                                                                      final TransformationDictionary transformationDictionary,
                                                                      final MiningModel model,
                                                                      final String parentPackageName,
                                                                      final KnowledgeBuilder kBuilder,
                                                                      final List<KiePMMLModel> nestedModels); }
KiePMMLMiningModelFactory { static void setConstructor(final String generatedClassName, final ConstructorDeclaration constructorDeclaration, final String targetField, final MINING_FUNCTION miningFunction, final String modelName, final String segmentationClass) { setConstructorSuperNameInvocation(generatedClassName, constructorDeclaration, modelName); final BlockStmt body = constructorDeclaration.getBody(); CommonCodegenUtils.setAssignExpressionValue(body, "targetField", new StringLiteralExpr(targetField)); CommonCodegenUtils.setAssignExpressionValue(body, "miningFunction", new NameExpr(miningFunction.getClass().getName() + "." + miningFunction.name())); CommonCodegenUtils.setAssignExpressionValue(body, "pmmlMODEL", new NameExpr(PMML_MODEL.MINING_MODEL.getClass().getName() + "." + PMML_MODEL.MINING_MODEL.name())); ClassOrInterfaceType kiePMMLSegmentationClass = parseClassOrInterfaceType(segmentationClass); ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(kiePMMLSegmentationClass); CommonCodegenUtils.setAssignExpressionValue(body, "segmentation", objectCreationExpr); } private  KiePMMLMiningModelFactory(); static KiePMMLMiningModel getKiePMMLMiningModel(final DataDictionary dataDictionary,
                                                           final TransformationDictionary transformationDictionary,
                                                           final MiningModel model,
                                                           final KnowledgeBuilder kBuilder); static Map<String, String> getKiePMMLMiningModelSourcesMap(final DataDictionary dataDictionary,
                                                                      final TransformationDictionary transformationDictionary,
                                                                      final MiningModel model,
                                                                      final String parentPackageName,
                                                                      final KnowledgeBuilder kBuilder,
                                                                      final List<KiePMMLModel> nestedModels);  }