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;
}
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());
}
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());
}
}
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);
}
}
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);
}
}
Aggregations