Search in sources :

Example 6 with HasKnowledgeBuilderMock

use of org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock in project drools by kiegroup.

the class KiePMMLTreeModelFactoryTest method setConstructor.

@Test
public void setConstructor() {
    final String targetField = "whatIdo";
    final ClassOrInterfaceDeclaration modelTemplate = classOrInterfaceDeclaration.clone();
    KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
    final CommonCompilationDTO<TreeModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, treeModel, new HasKnowledgeBuilderMock(knowledgeBuilder));
    final DroolsCompilationDTO<TreeModel> droolsCompilationDTO = DroolsCompilationDTO.fromCompilationDTO(compilationDTO, new HashMap<>());
    KiePMMLTreeModelFactory.setConstructor(droolsCompilationDTO, modelTemplate);
    Map<Integer, Expression> superInvocationExpressionsMap = new HashMap<>();
    superInvocationExpressionsMap.put(0, new NameExpr(String.format("\"%s\"", treeModel.getModelName())));
    superInvocationExpressionsMap.put(2, new NameExpr(String.format("\"%s\"", treeModel.getAlgorithmName())));
    MINING_FUNCTION miningFunction = MINING_FUNCTION.byName(treeModel.getMiningFunction().value());
    PMML_MODEL pmmlModel = PMML_MODEL.byName(treeModel.getClass().getSimpleName());
    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()));
    ConstructorDeclaration constructorDeclaration = modelTemplate.getDefaultConstructor().get();
    assertTrue(commonEvaluateConstructor(constructorDeclaration, getSanitizedClassName(treeModel.getModelName()), superInvocationExpressionsMap, assignExpressionMap));
}
Also used : HasKnowledgeBuilderMock(org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) HashMap(java.util.HashMap) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) KiePMMLTreeModel(org.kie.pmml.models.drools.tree.model.KiePMMLTreeModel) TreeModel(org.dmg.pmml.tree.TreeModel) Expression(com.github.javaparser.ast.expr.Expression) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) PMML_MODEL(org.kie.pmml.api.enums.PMML_MODEL) MINING_FUNCTION(org.kie.pmml.api.enums.MINING_FUNCTION) Test(org.junit.Test)

Example 7 with HasKnowledgeBuilderMock

use of org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock in project drools by kiegroup.

the class KiePMMLScorecardModelFactoryTest method setConstructor.

@Test
public void setConstructor() {
    final String targetField = "overallScore";
    final ClassOrInterfaceDeclaration modelTemplate = classOrInterfaceDeclaration.clone();
    KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
    final CommonCompilationDTO<Scorecard> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, scorecardModel, new HasKnowledgeBuilderMock(knowledgeBuilder));
    final DroolsCompilationDTO<Scorecard> droolsCompilationDTO = DroolsCompilationDTO.fromCompilationDTO(compilationDTO, new HashMap<>());
    KiePMMLScorecardModelFactory.setConstructor(droolsCompilationDTO, modelTemplate);
    Map<Integer, Expression> superInvocationExpressionsMap = new HashMap<>();
    superInvocationExpressionsMap.put(0, new NameExpr(String.format("\"%s\"", scorecardModel.getModelName())));
    MINING_FUNCTION miningFunction = MINING_FUNCTION.byName(scorecardModel.getMiningFunction().value());
    PMML_MODEL pmmlModel = PMML_MODEL.byName(scorecardModel.getClass().getSimpleName());
    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()));
    ConstructorDeclaration constructorDeclaration = modelTemplate.getDefaultConstructor().get();
    assertTrue(commonEvaluateConstructor(constructorDeclaration, getSanitizedClassName(scorecardModel.getModelName()), superInvocationExpressionsMap, assignExpressionMap));
}
Also used : HasKnowledgeBuilderMock(org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) HashMap(java.util.HashMap) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) Expression(com.github.javaparser.ast.expr.Expression) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) Scorecard(org.dmg.pmml.scorecard.Scorecard) PMML_MODEL(org.kie.pmml.api.enums.PMML_MODEL) MINING_FUNCTION(org.kie.pmml.api.enums.MINING_FUNCTION) Test(org.junit.Test)

Example 8 with HasKnowledgeBuilderMock

use of org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock in project drools by kiegroup.

the class KiePMMLScorecardModelFactoryTest method getKiePMMLScorecardModelSourcesMap.

@Test
public void getKiePMMLScorecardModelSourcesMap() {
    final DataDictionary dataDictionary = pmml.getDataDictionary();
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = getFieldTypeMap(dataDictionary, pmml.getTransformationDictionary(), scorecardModel.getLocalTransformations());
    KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
    final CommonCompilationDTO<Scorecard> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, scorecardModel, new HasKnowledgeBuilderMock(knowledgeBuilder));
    final DroolsCompilationDTO<Scorecard> droolsCompilationDTO = DroolsCompilationDTO.fromCompilationDTO(compilationDTO, fieldTypeMap);
    Map<String, String> retrieved = KiePMMLScorecardModelFactory.getKiePMMLScorecardModelSourcesMap(droolsCompilationDTO);
    assertNotNull(retrieved);
    assertEquals(1, retrieved.size());
}
Also used : HasKnowledgeBuilderMock(org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) Scorecard(org.dmg.pmml.scorecard.Scorecard) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Example 9 with HasKnowledgeBuilderMock

use of org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock in project drools by kiegroup.

the class KiePMMLScorecardModelFactoryTest method getKiePMMLScorecardModel.

@Test
public void getKiePMMLScorecardModel() throws Exception {
    final DataDictionary dataDictionary = pmml.getDataDictionary();
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = getFieldTypeMap(dataDictionary, pmml.getTransformationDictionary(), scorecardModel.getLocalTransformations());
    KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
    final CommonCompilationDTO<Scorecard> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, scorecardModel, new HasKnowledgeBuilderMock(knowledgeBuilder));
    final DroolsCompilationDTO<Scorecard> droolsCompilationDTO = DroolsCompilationDTO.fromCompilationDTO(compilationDTO, fieldTypeMap);
    KiePMMLScorecardModel retrieved = KiePMMLScorecardModelFactory.getKiePMMLScorecardModel(droolsCompilationDTO);
    assertNotNull(retrieved);
    assertEquals(scorecardModel.getModelName(), retrieved.getName());
    assertEquals(TARGET_FIELD, retrieved.getTargetField());
}
Also used : KiePMMLScorecardModel(org.kie.pmml.models.drools.scorecard.model.KiePMMLScorecardModel) HasKnowledgeBuilderMock(org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) Scorecard(org.dmg.pmml.scorecard.Scorecard) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Example 10 with HasKnowledgeBuilderMock

use of org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock in project drools by kiegroup.

the class ScorecardModelImplementationProviderTest method getKiePMMLModelWithSources.

@Test
public void getKiePMMLModelWithSources() throws Exception {
    final PMML pmml = getPMML(SOURCE_1);
    KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
    final CommonCompilationDTO<Scorecard> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, (Scorecard) pmml.getModels().get(0), new HasKnowledgeBuilderMock(knowledgeBuilder));
    final KiePMMLDroolsModelWithSources retrieved = PROVIDER.getKiePMMLModelWithSources(compilationDTO);
    assertNotNull(retrieved);
    commonVerifyIsDeepCloneable(retrieved);
}
Also used : HasKnowledgeBuilderMock(org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) PMML(org.dmg.pmml.PMML) Scorecard(org.dmg.pmml.scorecard.Scorecard) KiePMMLDroolsModelWithSources(org.kie.pmml.models.drools.commons.model.KiePMMLDroolsModelWithSources) Test(org.junit.Test)

Aggregations

KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)14 Test (org.junit.Test)14 HasKnowledgeBuilderMock (org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock)14 Scorecard (org.dmg.pmml.scorecard.Scorecard)9 PMML (org.dmg.pmml.PMML)6 TreeModel (org.dmg.pmml.tree.TreeModel)5 KiePMMLDroolsModelWithSources (org.kie.pmml.models.drools.commons.model.KiePMMLDroolsModelWithSources)5 KiePMMLTreeModel (org.kie.pmml.models.drools.tree.model.KiePMMLTreeModel)5 HashMap (java.util.HashMap)4 DataDictionary (org.dmg.pmml.DataDictionary)4 CompositePackageDescr (org.drools.compiler.lang.descr.CompositePackageDescr)4 PackageDescr (org.drools.drl.ast.descr.PackageDescr)4 PMML_MODEL (org.kie.pmml.api.enums.PMML_MODEL)4 KiePMMLOriginalTypeGeneratedType (org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType)4 IOException (java.io.IOException)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 DataField (org.dmg.pmml.DataField)2