Search in sources :

Example 6 with KiePMMLModel

use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.

the class PMMLAssemblerService method addModels.

protected void addModels(KnowledgeBuilderImpl kbuilderImpl, List<KiePMMLModel> toAdd) {
    for (KiePMMLModel kiePMMLModel : toAdd) {
        PackageDescr pkgDescr = new PackageDescr(kiePMMLModel.getKModulePackageName());
        PackageRegistry pkgReg = kbuilderImpl.getOrCreatePackageRegistry(pkgDescr);
        InternalKnowledgePackage kpkgs = pkgReg.getPackage();
        ResourceTypePackageRegistry rpkg = kpkgs.getResourceTypePackages();
        PMMLPackage pmmlPkg = rpkg.computeIfAbsent(ResourceType.PMML, rtp -> new PMMLPackageImpl());
        pmmlPkg.addAll(Collections.singletonList(kiePMMLModel));
        if (kiePMMLModel instanceof HasNestedModels) {
            addModels(kbuilderImpl, ((HasNestedModels) kiePMMLModel).getNestedModels());
        }
    }
}
Also used : PMMLPackage(org.kie.pmml.evaluator.api.container.PMMLPackage) ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) PackageRegistry(org.drools.compiler.compiler.PackageRegistry) PMMLPackageImpl(org.kie.pmml.evaluator.assembler.container.PMMLPackageImpl) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) HasNestedModels(org.kie.pmml.commons.model.HasNestedModels) PackageDescr(org.drools.drl.ast.descr.PackageDescr) ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 7 with KiePMMLModel

use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.

the class PMMLCompilerServiceTest method addPMMLRuleMapperNoHasSourceMap.

@Test(expected = KiePMMLException.class)
public void addPMMLRuleMapperNoHasSourceMap() {
    final KiePMMLModel kiePmmlModel = new KiePMMLTestingModel("name", Collections.emptyList());
    PMMLCompilerService.addPMMLRuleMapper(kiePmmlModel, new ArrayList<>(), "source_path");
}
Also used : KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) Test(org.junit.Test)

Example 8 with KiePMMLModel

use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.

the class PMMLCompilerServiceTest method populateWithPMMLRuleMappers.

@Test
public void populateWithPMMLRuleMappers() {
    final List<KiePMMLModel> toPopulate = new ArrayList<>();
    toPopulate.add(new KiePMMLTestingModelWithSources("TEST", "kmodulePackageName", Collections.emptyMap()));
    toPopulate.add(new KiePMMLModelHasRule("TEST", Collections.emptyList()));
    toPopulate.add(new KiePMMLModelHasNestedModelsHasRule("TEST", Collections.emptyList()));
    toPopulate.add(new KiePMMLModelHasNestedModelsHasSourceMap("TEST", Collections.emptyList()));
    toPopulate.forEach(kiePMMLModel -> assertTrue(((HasSourcesMap) kiePMMLModel).getSourcesMap().isEmpty()));
    final File file = new File("foo.pmml");
    final Resource resource = new FileSystemResource(file);
    PMMLCompilerService.populateWithPMMLRuleMappers(toPopulate, resource);
    toPopulate.forEach(kiePmmlModel -> {
        if (kiePmmlModel instanceof HasRule || kiePmmlModel instanceof KiePMMLModelHasNestedModelsHasRule) {
            assertFalse(((HasSourcesMap) kiePmmlModel).getSourcesMap().isEmpty());
            String expected = kiePmmlModel.getKModulePackageName() + "." + KIE_PMML_RULE_MAPPERS_CLASS_NAME;
            assertTrue(((HasSourcesMap) kiePmmlModel).getSourcesMap().containsKey(expected));
            if (kiePmmlModel instanceof HasRule) {
                expected = kiePmmlModel.getKModulePackageName() + "." + KIE_PMML_RULE_MAPPER_CLASS_NAME;
                assertTrue(((HasSourcesMap) kiePmmlModel).getSourcesMap().containsKey(expected));
            }
        } else {
            assertTrue(((HasSourcesMap) kiePmmlModel).getSourcesMap().isEmpty());
        }
    });
}
Also used : KiePMMLTestingModelWithSources(org.kie.pmml.commons.testingutility.KiePMMLTestingModelWithSources) ArrayList(java.util.ArrayList) FileSystemResource(org.drools.core.io.impl.FileSystemResource) Resource(org.kie.api.io.Resource) FileSystemResource(org.drools.core.io.impl.FileSystemResource) HasRule(org.kie.pmml.commons.HasRule) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) HasSourcesMap(org.kie.pmml.commons.model.HasSourcesMap) File(java.io.File) Test(org.junit.Test)

Example 9 with KiePMMLModel

use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.

the class PMMLCompilerServiceTest method addPMMLRuleMappersHasSourceMap.

@Test
public void addPMMLRuleMappersHasSourceMap() {
    KiePMMLTestingModelWithSources kiePmmlModel = new KiePMMLTestingModelWithSources("TEST", "kmodulePackageName", new HashMap<>());
    assertTrue(kiePmmlModel.getSourcesMap().isEmpty());
    final List<String> generatedRuleMappers = IntStream.range(0, 3).mapToObj(i -> "apackage" + i + "." + KIE_PMML_RULE_MAPPER_CLASS_NAME).collect(Collectors.toList());
    PMMLCompilerService.addPMMLRuleMappers(kiePmmlModel, generatedRuleMappers, "source_path");
    assertFalse(kiePmmlModel.getSourcesMap().isEmpty());
    String expected = kiePmmlModel.getKModulePackageName() + "." + KIE_PMML_RULE_MAPPERS_CLASS_NAME;
    assertTrue(kiePmmlModel.getSourcesMap().containsKey(expected));
}
Also used : IntStream(java.util.stream.IntStream) HasRule(org.kie.pmml.commons.HasRule) HashMap(java.util.HashMap) FileSystemResource(org.drools.core.io.impl.FileSystemResource) ArrayList(java.util.ArrayList) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) StringUtils.generateUUID(org.drools.core.util.StringUtils.generateUUID) KIE_PMML_RULE_MAPPER_CLASS_NAME(org.kie.pmml.evaluator.assembler.factories.PMMLRuleMapperFactory.KIE_PMML_RULE_MAPPER_CLASS_NAME) MINING_FUNCTION(org.kie.pmml.api.enums.MINING_FUNCTION) KiePMMLTestingModelWithSources(org.kie.pmml.commons.testingutility.KiePMMLTestingModelWithSources) HasNestedModels(org.kie.pmml.commons.model.HasNestedModels) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) File(java.io.File) Resource(org.kie.api.io.Resource) List(java.util.List) HasSourcesMap(org.kie.pmml.commons.model.HasSourcesMap) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) Assert.assertFalse(org.junit.Assert.assertFalse) KiePMMLExtension(org.kie.pmml.commons.model.KiePMMLExtension) Collections(java.util.Collections) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) Assert.assertEquals(org.junit.Assert.assertEquals) KIE_PMML_RULE_MAPPERS_CLASS_NAME(org.kie.pmml.evaluator.assembler.factories.PMMLRuleMappersFactory.KIE_PMML_RULE_MAPPERS_CLASS_NAME) KiePMMLTestingModelWithSources(org.kie.pmml.commons.testingutility.KiePMMLTestingModelWithSources) Test(org.junit.Test)

Example 10 with KiePMMLModel

use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.

the class PMMLCompilerServiceTest method addPMMLRuleMappersNotHasSourceMap.

@Test(expected = KiePMMLException.class)
public void addPMMLRuleMappersNotHasSourceMap() {
    final KiePMMLModel kiePmmlModel = KiePMMLTestingModel.builder("name", Collections.emptyList(), MINING_FUNCTION.REGRESSION).build();
    final List<String> generatedRuleMappers = IntStream.range(0, 3).mapToObj(i -> "apackage" + i + "." + KIE_PMML_RULE_MAPPER_CLASS_NAME).collect(Collectors.toList());
    PMMLCompilerService.addPMMLRuleMappers(kiePmmlModel, generatedRuleMappers, "source_path");
}
Also used : IntStream(java.util.stream.IntStream) HasRule(org.kie.pmml.commons.HasRule) HashMap(java.util.HashMap) FileSystemResource(org.drools.core.io.impl.FileSystemResource) ArrayList(java.util.ArrayList) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) StringUtils.generateUUID(org.drools.core.util.StringUtils.generateUUID) KIE_PMML_RULE_MAPPER_CLASS_NAME(org.kie.pmml.evaluator.assembler.factories.PMMLRuleMapperFactory.KIE_PMML_RULE_MAPPER_CLASS_NAME) MINING_FUNCTION(org.kie.pmml.api.enums.MINING_FUNCTION) KiePMMLTestingModelWithSources(org.kie.pmml.commons.testingutility.KiePMMLTestingModelWithSources) HasNestedModels(org.kie.pmml.commons.model.HasNestedModels) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) File(java.io.File) Resource(org.kie.api.io.Resource) List(java.util.List) HasSourcesMap(org.kie.pmml.commons.model.HasSourcesMap) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) Assert.assertFalse(org.junit.Assert.assertFalse) KiePMMLExtension(org.kie.pmml.commons.model.KiePMMLExtension) Collections(java.util.Collections) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) Assert.assertEquals(org.junit.Assert.assertEquals) KIE_PMML_RULE_MAPPERS_CLASS_NAME(org.kie.pmml.evaluator.assembler.factories.PMMLRuleMappersFactory.KIE_PMML_RULE_MAPPERS_CLASS_NAME) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) Test(org.junit.Test)

Aggregations

KiePMMLModel (org.kie.pmml.commons.model.KiePMMLModel)37 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)17 MiningModel (org.dmg.pmml.mining.MiningModel)9 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)9 KiePMMLTestingModel (org.kie.pmml.commons.testingutility.KiePMMLTestingModel)8 CommonCompilationDTO (org.kie.pmml.compiler.api.dto.CommonCompilationDTO)7 HasClassLoaderMock (org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 HasKnowledgeBuilderMock (org.kie.pmml.models.mining.compiler.HasKnowledgeBuilderMock)6 MiningModelCompilationDTO (org.kie.pmml.models.mining.compiler.dto.MiningModelCompilationDTO)6 HasSourcesMap (org.kie.pmml.commons.model.HasSourcesMap)5 File (java.io.File)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 MINING_FUNCTION (org.kie.pmml.api.enums.MINING_FUNCTION)4