Search in sources :

Example 1 with KiePMMLModel

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

the class KiePMMLModelRetrieverTest method getFromCommonDataAndTransformationDictionaryAndModelWithProvider.

@Test
public void getFromCommonDataAndTransformationDictionaryAndModelWithProvider() throws Exception {
    pmml = KiePMMLUtil.load(getFileInputStream(MULTIPLE_TARGETS_SOURCE), MULTIPLE_TARGETS_SOURCE);
    TestModel model = new TestModel();
    pmml.getModels().set(0, model);
    final CommonCompilationDTO<TestModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, model, new HasClassLoaderMock());
    final Optional<KiePMMLModel> retrieved = getFromCommonDataAndTransformationDictionaryAndModel(compilationDTO);
    assertNotNull(retrieved);
    assertTrue(retrieved.isPresent());
    assertTrue(retrieved.get() instanceof KiePMMLTestingModel);
}
Also used : KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) PMMLModelTestUtils.getPMMLWithMiningRandomTestModel(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getPMMLWithMiningRandomTestModel) PMMLModelTestUtils.getPMMLWithRandomTestModel(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getPMMLWithRandomTestModel) TestModel(org.kie.pmml.compiler.api.mocks.TestModel) Test(org.junit.Test)

Example 2 with KiePMMLModel

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

the class KiePMMLModelRetrieverTest method getFromCommonDataAndTransformationDictionaryAndModelWithSourcesCompiledWithoutProvider.

@Test
public void getFromCommonDataAndTransformationDictionaryAndModelWithSourcesCompiledWithoutProvider() throws Exception {
    pmml = KiePMMLUtil.load(getFileInputStream(MINING_MODEL_WITH_NESTED_REFERS_SOURCE), MINING_MODEL_WITH_NESTED_REFERS_SOURCE);
    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);
    assertFalse(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 3 with KiePMMLModel

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

the class PMMLCompilerService method populateWithPMMLRuleMappers.

static void populateWithPMMLRuleMappers(final List<KiePMMLModel> toReturn, final Resource resource) {
    for (KiePMMLModel kiePMMLModel : toReturn) {
        final List<String> generatedRuleMappers = new ArrayList<>();
        addPMMLRuleMapper(kiePMMLModel, generatedRuleMappers, resource.getSourcePath());
        addPMMLRuleMappers(kiePMMLModel, generatedRuleMappers, resource.getSourcePath());
    }
}
Also used : KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) ArrayList(java.util.ArrayList)

Example 4 with KiePMMLModel

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

the class PMMLCompilerService method addPMMLRuleMapper.

static void addPMMLRuleMapper(final KiePMMLModel kiePMMLModel, final List<String> generatedRuleMappers, final String sourcePath) {
    if (!(kiePMMLModel instanceof HasSourcesMap)) {
        String errorMessage = String.format("Expecting HasSourcesMap instance, retrieved %s inside %s", kiePMMLModel.getClass().getName(), sourcePath);
        throw new KiePMMLException(errorMessage);
    }
    if (kiePMMLModel instanceof HasRule) {
        String pkgUUID = ((HasRule) kiePMMLModel).getPkgUUID();
        String rulesFileName = kiePMMLModel.getKModulePackageName() + "." + RULES_FILE_NAME + pkgUUID;
        String pmmlRuleMapper = kiePMMLModel.getKModulePackageName() + "." + KIE_PMML_RULE_MAPPER_CLASS_NAME;
        String ruleMapperSource = PMMLRuleMapperFactory.getPMMLRuleMapperSource(rulesFileName);
        ((HasRule) kiePMMLModel).addSourceMap(pmmlRuleMapper, ruleMapperSource);
        generatedRuleMappers.add(pmmlRuleMapper);
    }
    if (kiePMMLModel instanceof HasNestedModels) {
        for (KiePMMLModel nestedModel : ((HasNestedModels) kiePMMLModel).getNestedModels()) {
            addPMMLRuleMapper(nestedModel, generatedRuleMappers, sourcePath);
        }
    }
}
Also used : HasRule(org.kie.pmml.commons.HasRule) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) HasNestedModels(org.kie.pmml.commons.model.HasNestedModels) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) HasSourcesMap(org.kie.pmml.commons.model.HasSourcesMap)

Example 5 with KiePMMLModel

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

the class PMMLRuntimeFactoryInternalTest method populateNestedKiePackageList.

@Test
public void populateNestedKiePackageList() {
    // Setup kiebase
    KiePMMLModel kiePMMLModel = getKiePMMLModelWithNested("FAKE");
    InternalKnowledgePackage pmmlKnowledgePackage = getKnowledgePackageWithPMMLResourceType(kiePMMLModel);
    List<KiePackage> kiePackages = ((HasNestedModels) kiePMMLModel).getNestedModels().stream().map(this::getKnowledgePackageWithPMMLResourceType).collect(Collectors.toList());
    InternalKnowledgeBase kieBase = (InternalKnowledgeBase) new KieHelper().build(ExecutableModelProject.class);
    kieBase.addPackage(pmmlKnowledgePackage);
    kieBase.addPackages(kiePackages);
    // Actual test
    final List<KiePackage> toPopulate = new ArrayList<>();
    PMMLRuntimeFactoryInternal.populateNestedKiePackageList(Collections.singleton(kiePMMLModel), toPopulate, kieBase);
    assertFalse(toPopulate.isEmpty());
    assertEquals(kiePackages.size(), toPopulate.size());
}
Also used : KiePackage(org.kie.api.definition.KiePackage) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) ArrayList(java.util.ArrayList) KieHelper(org.kie.internal.utils.KieHelper) ExecutableModelProject(org.drools.modelcompiler.ExecutableModelProject) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) 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