Search in sources :

Example 6 with CommonCompilationDTO

use of org.kie.pmml.compiler.api.dto.CommonCompilationDTO in project drools by kiegroup.

the class KiePMMLModelRetrieverTest method getFromCommonDataAndTransformationDictionaryAndModelWithoutProvider.

@Test
public void getFromCommonDataAndTransformationDictionaryAndModelWithoutProvider() throws Exception {
    pmml = KiePMMLUtil.load(getFileInputStream(ONE_MINING_TARGET_SOURCE), ONE_MINING_TARGET_SOURCE);
    final CommonCompilationDTO compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, pmml.getModels().get(0), new HasClassLoaderMock());
    final Optional<KiePMMLModel> retrieved = getFromCommonDataAndTransformationDictionaryAndModel(compilationDTO);
    assertNotNull(retrieved);
    assertFalse(retrieved.isPresent());
}
Also used : KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Example 7 with CommonCompilationDTO

use of org.kie.pmml.compiler.api.dto.CommonCompilationDTO in project drools by kiegroup.

the class KiePMMLModelRetrieverTest method getFromCommonDataAndTransformationDictionaryAndModelWithSourcesCompiledWithProvider.

@Test
public void getFromCommonDataAndTransformationDictionaryAndModelWithSourcesCompiledWithProvider() throws Exception {
    pmml = getPMMLWithMiningRandomTestModel();
    MiningModel parentModel = (MiningModel) pmml.getModels().get(0);
    Model model = parentModel.getSegmentation().getSegments().get(0).getModel();
    final CommonCompilationDTO compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, model, new HasClassLoaderMock());
    final Optional<KiePMMLModel> retrieved = getFromCommonDataAndTransformationDictionaryAndModelWithSourcesCompiled(compilationDTO);
    assertNotNull(retrieved);
    assertTrue(retrieved.isPresent());
}
Also used : MiningModel(org.dmg.pmml.mining.MiningModel) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) PMMLModelTestUtils.getPMMLWithMiningRandomTestModel(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getPMMLWithMiningRandomTestModel) Model(org.dmg.pmml.Model) PMMLModelTestUtils.getPMMLWithRandomTestModel(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getPMMLWithRandomTestModel) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) TestModel(org.kie.pmml.compiler.api.mocks.TestModel) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) KiePMMLModelRetriever.getFromCommonDataAndTransformationDictionaryAndModel(org.kie.pmml.compiler.commons.implementations.KiePMMLModelRetriever.getFromCommonDataAndTransformationDictionaryAndModel) MiningModel(org.dmg.pmml.mining.MiningModel) CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Example 8 with CommonCompilationDTO

use of org.kie.pmml.compiler.api.dto.CommonCompilationDTO in project drools by kiegroup.

the class KiePMMLModelRetrieverTest method getFromCommonDataAndTransformationDictionaryAndModelWithSourcesWithProvider.

@Test
public void getFromCommonDataAndTransformationDictionaryAndModelWithSourcesWithProvider() {
    pmml = getPMMLWithRandomTestModel();
    final CommonCompilationDTO compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, pmml.getModels().get(0), new HasClassLoaderMock());
    final Optional<KiePMMLModel> retrieved = getFromCommonDataAndTransformationDictionaryAndModelWithSources(compilationDTO);
    assertNotNull(retrieved);
}
Also used : KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Example 9 with CommonCompilationDTO

use of org.kie.pmml.compiler.api.dto.CommonCompilationDTO in project drools by kiegroup.

the class KiePMMLMiningModelFactoryTest method getKiePMMLMiningModelSourcesMapCompiled.

@Test
public void getKiePMMLMiningModelSourcesMapCompiled() {
    final List<KiePMMLModel> nestedModels = new ArrayList<>();
    final HasKnowledgeBuilderMock hasKnowledgeBuilderMock = new HasKnowledgeBuilderMock(KNOWLEDGE_BUILDER);
    final CommonCompilationDTO<MiningModel> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, MINING_MODEL, hasKnowledgeBuilderMock);
    final MiningModelCompilationDTO compilationDTO = MiningModelCompilationDTO.fromCompilationDTO(source);
    final List<String> expectedGeneratedClasses = MINING_MODEL.getSegmentation().getSegments().stream().map(segment -> {
        String modelName = segment.getModel().getModelName();
        String sanitizedPackageName = getSanitizedPackageName(compilationDTO.getSegmentationPackageName() + "." + segment.getId());
        String sanitizedClassName = getSanitizedClassName(modelName);
        return String.format(PACKAGE_CLASS_TEMPLATE, sanitizedPackageName, sanitizedClassName);
    }).collect(Collectors.toList());
    expectedGeneratedClasses.forEach(expectedGeneratedClass -> {
        try {
            hasKnowledgeBuilderMock.getClassLoader().loadClass(expectedGeneratedClass);
            fail("Expecting class not found: " + expectedGeneratedClass);
        } catch (Exception e) {
            assertTrue(e instanceof ClassNotFoundException);
        }
    });
    final Map<String, String> retrieved = KiePMMLMiningModelFactory.getKiePMMLMiningModelSourcesMapCompiled(compilationDTO, nestedModels);
    assertNotNull(retrieved);
    int expectedNestedModels = MINING_MODEL.getSegmentation().getSegments().size();
    assertEquals(expectedNestedModels, nestedModels.size());
    expectedGeneratedClasses.forEach(expectedGeneratedClass -> {
        try {
            hasKnowledgeBuilderMock.getClassLoader().loadClass(expectedGeneratedClass);
        } catch (Exception e) {
            fail("Expecting class to be loaded, but got: " + e.getClass().getName() + " -> " + e.getMessage());
            e.printStackTrace();
        }
    });
}
Also used : StaticJavaParser.parseClassOrInterfaceType(com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) BeforeClass(org.junit.BeforeClass) JavaParserUtils.getFromFileName(org.kie.pmml.compiler.commons.utils.JavaParserUtils.getFromFileName) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) CodegenTestUtils.commonEvaluateConstructor(org.kie.pmml.compiler.commons.testutils.CodegenTestUtils.commonEvaluateConstructor) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) PMML_MODEL(org.kie.pmml.api.enums.PMML_MODEL) ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) Map(java.util.Map) Expression(com.github.javaparser.ast.expr.Expression) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) Assert.fail(org.junit.Assert.fail) CompilationUnit(com.github.javaparser.ast.CompilationUnit) KiePMMLModelUtils.getSanitizedPackageName(org.kie.pmml.commons.utils.KiePMMLModelUtils.getSanitizedPackageName) MiningModel(org.dmg.pmml.mining.MiningModel) MINING_FUNCTION(org.kie.pmml.api.enums.MINING_FUNCTION) HasKnowledgeBuilderMock(org.kie.pmml.models.mining.compiler.HasKnowledgeBuilderMock) PACKAGE_NAME(org.kie.pmml.commons.Constants.PACKAGE_NAME) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) NameExpr(com.github.javaparser.ast.expr.NameExpr) MiningModelCompilationDTO(org.kie.pmml.models.mining.compiler.dto.MiningModelCompilationDTO) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) List(java.util.List) CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) SAXException(org.xml.sax.SAXException) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) PACKAGE_CLASS_TEMPLATE(org.kie.pmml.commons.Constants.PACKAGE_CLASS_TEMPLATE) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) Assert.assertEquals(org.junit.Assert.assertEquals) KiePMMLModelUtils.getSanitizedClassName(org.kie.pmml.commons.utils.KiePMMLModelUtils.getSanitizedClassName) HasKnowledgeBuilderMock(org.kie.pmml.models.mining.compiler.HasKnowledgeBuilderMock) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) MiningModel(org.dmg.pmml.mining.MiningModel) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) MiningModelCompilationDTO(org.kie.pmml.models.mining.compiler.dto.MiningModelCompilationDTO) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 CommonCompilationDTO (org.kie.pmml.compiler.api.dto.CommonCompilationDTO)9 HasClassLoaderMock (org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock)9 KiePMMLModel (org.kie.pmml.commons.model.KiePMMLModel)5 IOException (java.io.IOException)4 Map (java.util.Map)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 BeforeClass (org.junit.BeforeClass)4 PACKAGE_NAME (org.kie.pmml.commons.Constants.PACKAGE_NAME)4 HashMap (java.util.HashMap)3 List (java.util.List)3 DataDictionary (org.dmg.pmml.DataDictionary)3 DataField (org.dmg.pmml.DataField)3 PMML (org.dmg.pmml.PMML)3 Assert.assertNotNull (org.junit.Assert.assertNotNull)3 PMML_MODEL (org.kie.pmml.api.enums.PMML_MODEL)3 KiePMMLModelUtils.getSanitizedClassName (org.kie.pmml.commons.utils.KiePMMLModelUtils.getSanitizedClassName)3 KiePMMLModelUtils.getSanitizedPackageName (org.kie.pmml.commons.utils.KiePMMLModelUtils.getSanitizedPackageName)3 CompilationUnit (com.github.javaparser.ast.CompilationUnit)2