Search in sources :

Example 1 with KiePMMLMiningModelWithSources

use of org.kie.pmml.models.mining.model.KiePMMLMiningModelWithSources in project drools by kiegroup.

the class MiningModelImplementationProviderTest method commonGetKiePMMLModelWithSources.

private void commonGetKiePMMLModelWithSources(String source) throws Exception {
    final PMML pmml = getPMML(source);
    KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
    final MiningModel miningmodel = (MiningModel) pmml.getModels().get(0);
    final CommonCompilationDTO<MiningModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, miningmodel, new HasKnowledgeBuilderMock(knowledgeBuilder));
    final KiePMMLMiningModelWithSources retrieved = (KiePMMLMiningModelWithSources) PROVIDER.getKiePMMLModelWithSources(compilationDTO);
    assertNotNull(retrieved);
    commonVerifyIsDeepCloneable(retrieved);
    assertNotNull(retrieved.getNestedModels());
    assertFalse(retrieved.getNestedModels().isEmpty());
    final Map<String, String> sourcesMap = new HashMap<>(retrieved.getSourcesMap());
    assertFalse(sourcesMap.isEmpty());
    try {
        KieMemoryCompiler.compile(sourcesMap, Thread.currentThread().getContextClassLoader());
        fail("Expecting compilation error without nested models sources");
    } catch (Exception e) {
    // Expected
    }
    retrieved.getNestedModels().forEach(nestedModel -> sourcesMap.putAll(((HasSourcesMap) nestedModel).getSourcesMap()));
    try {
        KieMemoryCompiler.compile(sourcesMap, Thread.currentThread().getContextClassLoader());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : KiePMMLMiningModelWithSources(org.kie.pmml.models.mining.model.KiePMMLMiningModelWithSources) HasKnowledgeBuilderMock(org.kie.pmml.models.mining.compiler.HasKnowledgeBuilderMock) KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) MiningModel(org.dmg.pmml.mining.MiningModel) HashMap(java.util.HashMap) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) PMML(org.dmg.pmml.PMML) HasSourcesMap(org.kie.pmml.commons.model.HasSourcesMap)

Aggregations

HashMap (java.util.HashMap)1 PMML (org.dmg.pmml.PMML)1 MiningModel (org.dmg.pmml.mining.MiningModel)1 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1 HasSourcesMap (org.kie.pmml.commons.model.HasSourcesMap)1 HasKnowledgeBuilderMock (org.kie.pmml.models.mining.compiler.HasKnowledgeBuilderMock)1 KiePMMLMiningModel (org.kie.pmml.models.mining.model.KiePMMLMiningModel)1 KiePMMLMiningModelWithSources (org.kie.pmml.models.mining.model.KiePMMLMiningModelWithSources)1