Search in sources :

Example 21 with KiePMMLModel

use of org.kie.pmml.commons.model.KiePMMLModel 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 22 with KiePMMLModel

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

the class PMMLRuntimeFactoryInternal method getNestedKiePackages.

protected static List<KiePackage> getNestedKiePackages(final InternalKnowledgePackage kiePackage, final KieBase kieBase) {
    PMMLPackage pmmlPackage = (PMMLPackage) kiePackage.getResourceTypePackages().get(ResourceType.PMML);
    final Map<String, KiePMMLModel> kiePmmlModels = pmmlPackage.getAllModels();
    final List<KiePackage> toReturn = new ArrayList<>();
    populateNestedKiePackageList(kiePmmlModels.values(), toReturn, kieBase);
    return toReturn;
}
Also used : PMMLPackage(org.kie.pmml.evaluator.api.container.PMMLPackage) KiePackage(org.kie.api.definition.KiePackage) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) ArrayList(java.util.ArrayList)

Example 23 with KiePMMLModel

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

the class PMMLAssemblerService method addResourceAfterRules.

@Override
public void addResourceAfterRules(Object kbuilder, Resource resource, ResourceType type, ResourceConfiguration configuration) {
    logger.warn("invoked legacy addResourceAfterRules (no control on the order of the assembler compilation): {}", resource.getSourcePath());
    KnowledgeBuilderImpl kbuilderImpl = (KnowledgeBuilderImpl) kbuilder;
    if (isjPMMLAvailableToClassLoader(kbuilderImpl.getRootClassLoader())) {
        return;
    }
    if (isBuildFromMaven()) {
        addModels(kbuilderImpl, getKiePMMLModelsFromResourceWithSources(kbuilderImpl, resource));
    } else {
        List<KiePMMLModel> toAdd = getKiePMMLModelsLoadedFromResource(kbuilderImpl, resource);
        if (toAdd.isEmpty()) {
            toAdd = getKiePMMLModelsCompiledFromResource(kbuilderImpl, resource);
        }
        addModels(kbuilderImpl, toAdd);
    }
}
Also used : KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel)

Example 24 with KiePMMLModel

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

the class PMMLAssemblerService method addResourcesAfterRules.

@Override
public void addResourcesAfterRules(Object kbuilder, Collection<ResourceWithConfiguration> resources, ResourceType type) {
    KnowledgeBuilderImpl kbuilderImpl = (KnowledgeBuilderImpl) kbuilder;
    if (isjPMMLAvailableToClassLoader(kbuilderImpl.getRootClassLoader())) {
        return;
    }
    if (isBuildFromMaven()) {
        addModels(kbuilderImpl, getKiePMMLModelsFromResourcesWithConfigurationsWithSources(kbuilderImpl, resources));
    } else {
        List<KiePMMLModel> toAdd = getKiePMMLModelsLoadedFromResourcesWithConfigurations(kbuilderImpl, resources);
        if (toAdd.isEmpty()) {
            toAdd = getKiePMMLModelsCompiledFromResourcesWithConfigurations(kbuilderImpl, resources);
        }
        addModels(kbuilderImpl, toAdd);
    }
}
Also used : KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel)

Example 25 with KiePMMLModel

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

the class PMMLCompilerServiceTest method addPMMLRuleMapperHasSourcesMap.

@Test
public void addPMMLRuleMapperHasSourcesMap() {
    KiePMMLTestingModelWithSources kiePmmlModel = new KiePMMLTestingModelWithSources("TEST", "kmodulePackageName", Collections.emptyMap());
    assertTrue(kiePmmlModel.getSourcesMap().isEmpty());
    final List<String> generatedRuleMappers = IntStream.range(0, 3).mapToObj(i -> "apackage.Rule_" + i).collect(Collectors.toList());
    PMMLCompilerService.addPMMLRuleMapper(kiePmmlModel, generatedRuleMappers, "source_path");
    assertTrue(kiePmmlModel.getSourcesMap().isEmpty());
}
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)

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