Search in sources :

Example 1 with KiePMMLModelWithSources

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

the class ModelImplementationProvider method getKiePMMLModelWithSourcesCompiled.

/**
 * Method provided only to have <b>drools</b> models working when invoked by a <code>MiningModel</code>
 * Default implementation provided for <b>not-drools</b> models.
 * @param compilationDTO
 * @return
 * @throws KiePMMLInternalException
 */
default KiePMMLModelWithSources getKiePMMLModelWithSourcesCompiled(final CompilationDTO<T> compilationDTO) {
    KiePMMLModelWithSources toReturn = getKiePMMLModelWithSources(compilationDTO);
    final Map<String, String> sourcesMap = ((HasSourcesMap) toReturn).getSourcesMap();
    try {
        compilationDTO.compileAndLoadClass(sourcesMap);
    } catch (Exception e) {
        throw new KiePMMLException(e);
    }
    return toReturn;
}
Also used : KiePMMLModelWithSources(org.kie.pmml.commons.model.KiePMMLModelWithSources) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) HasSourcesMap(org.kie.pmml.commons.model.HasSourcesMap) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException)

Example 2 with KiePMMLModelWithSources

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

the class ScorecardModelImplementationProviderTest method getKiePMMLModelWithSources.

@Test
public void getKiePMMLModelWithSources() {
    final CommonCompilationDTO<Scorecard> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, basicComplexPartialScorePmml, basicComplexPartialScore, new HasClassLoaderMock());
    KiePMMLModelWithSources retrieved = provider.getKiePMMLModelWithSources(compilationDTO);
    assertNotNull(retrieved);
    Map<String, String> retrievedSourcesMap = retrieved.getSourcesMap();
    assertNotNull(retrievedSourcesMap);
    assertFalse(retrievedSourcesMap.isEmpty());
}
Also used : KiePMMLModelWithSources(org.kie.pmml.commons.model.KiePMMLModelWithSources) Scorecard(org.dmg.pmml.scorecard.Scorecard) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Example 3 with KiePMMLModelWithSources

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

the class TreeModelImplementationProviderTest method getKiePMMLModelWithSources.

@Test
public void getKiePMMLModelWithSources() {
    TreeModel treeModel = (TreeModel) pmml.getModels().get(0);
    final CommonCompilationDTO<TreeModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, treeModel, new HasClassLoaderMock());
    final KiePMMLModelWithSources retrieved = PROVIDER.getKiePMMLModelWithSources(compilationDTO);
    assertNotNull(retrieved);
    final Map<String, String> sourcesMap = retrieved.getSourcesMap();
    assertNotNull(sourcesMap);
    assertFalse(sourcesMap.isEmpty());
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try {
        final Map<String, Class<?>> compiled = KieMemoryCompiler.compile(sourcesMap, classLoader);
        for (Class<?> clazz : compiled.values()) {
            assertTrue(clazz instanceof Serializable);
        }
    } catch (Throwable t) {
        fail(t.getMessage());
    }
}
Also used : TreeModel(org.dmg.pmml.tree.TreeModel) KiePMMLTreeModel(org.kie.pmml.models.tree.model.KiePMMLTreeModel) KiePMMLModelWithSources(org.kie.pmml.commons.model.KiePMMLModelWithSources) Serializable(java.io.Serializable) BeforeClass(org.junit.BeforeClass) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Example 4 with KiePMMLModelWithSources

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

the class ClusteringModelImplementationProviderTest method getKiePMMLModelWithSources.

@Test
public void getKiePMMLModelWithSources() throws Exception {
    PMML pmml = TestUtils.loadFromFile(SOURCE_FILE);
    ClusteringModel model = getModel(pmml);
    final CommonCompilationDTO<ClusteringModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, model, new HasClassLoaderMock());
    KiePMMLModelWithSources retrieved = PROVIDER.getKiePMMLModelWithSources(compilationDTO);
    assertNotNull(retrieved);
    Map<String, String> sourcesMap = retrieved.getSourcesMap();
    assertNotNull(sourcesMap);
    assertFalse(sourcesMap.isEmpty());
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    Map<String, Class<?>> compiled = KieMemoryCompiler.compile(sourcesMap, classLoader);
    for (Class<?> clazz : compiled.values()) {
        assertTrue(clazz instanceof Serializable);
    }
}
Also used : KiePMMLModelWithSources(org.kie.pmml.commons.model.KiePMMLModelWithSources) Serializable(java.io.Serializable) PMML(org.dmg.pmml.PMML) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) KiePMMLClusteringModel(org.kie.pmml.models.clustering.model.KiePMMLClusteringModel) ClusteringModel(org.dmg.pmml.clustering.ClusteringModel) Test(org.junit.Test)

Example 5 with KiePMMLModelWithSources

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

the class RegressionModelImplementationProviderTest method getKiePMMLModelWithSources.

@Test
public void getKiePMMLModelWithSources() throws Exception {
    final PMML pmml = TestUtils.loadFromFile(SOURCE_1);
    assertNotNull(pmml);
    assertEquals(1, pmml.getModels().size());
    assertTrue(pmml.getModels().get(0) instanceof RegressionModel);
    RegressionModel regressionModel = (RegressionModel) pmml.getModels().get(0);
    final CommonCompilationDTO<RegressionModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, regressionModel, new HasClassLoaderMock());
    final KiePMMLModelWithSources retrieved = PROVIDER.getKiePMMLModelWithSources(compilationDTO);
    assertNotNull(retrieved);
    final Map<String, String> sourcesMap = retrieved.getSourcesMap();
    assertNotNull(sourcesMap);
    assertFalse(sourcesMap.isEmpty());
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    final Map<String, Class<?>> compiled = KieMemoryCompiler.compile(sourcesMap, classLoader);
    for (Class<?> clazz : compiled.values()) {
        assertTrue(clazz instanceof Serializable);
    }
}
Also used : KiePMMLModelWithSources(org.kie.pmml.commons.model.KiePMMLModelWithSources) Serializable(java.io.Serializable) PMML(org.dmg.pmml.PMML) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) RegressionModel(org.dmg.pmml.regression.RegressionModel) KiePMMLRegressionModel(org.kie.pmml.models.regression.model.KiePMMLRegressionModel) Test(org.junit.Test)

Aggregations

KiePMMLModelWithSources (org.kie.pmml.commons.model.KiePMMLModelWithSources)5 Test (org.junit.Test)4 HasClassLoaderMock (org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock)4 Serializable (java.io.Serializable)3 PMML (org.dmg.pmml.PMML)2 ClusteringModel (org.dmg.pmml.clustering.ClusteringModel)1 RegressionModel (org.dmg.pmml.regression.RegressionModel)1 Scorecard (org.dmg.pmml.scorecard.Scorecard)1 TreeModel (org.dmg.pmml.tree.TreeModel)1 BeforeClass (org.junit.BeforeClass)1 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)1 KiePMMLInternalException (org.kie.pmml.api.exceptions.KiePMMLInternalException)1 HasSourcesMap (org.kie.pmml.commons.model.HasSourcesMap)1 KiePMMLClusteringModel (org.kie.pmml.models.clustering.model.KiePMMLClusteringModel)1 KiePMMLRegressionModel (org.kie.pmml.models.regression.model.KiePMMLRegressionModel)1 KiePMMLTreeModel (org.kie.pmml.models.tree.model.KiePMMLTreeModel)1