Search in sources :

Example 36 with HasClassLoaderMock

use of org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock in project drools by kiegroup.

the class KiePMMLRegressionModelFactoryTest method getRegressionTablesMap.

@Test
public void getRegressionTablesMap() {
    final CompilationDTO<RegressionModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, regressionModel, new HasClassLoaderMock());
    Map<String, KiePMMLTableSourceCategory> retrieved = KiePMMLRegressionModelFactory.getRegressionTablesMap(RegressionCompilationDTO.fromCompilationDTO(compilationDTO));
    // One for classification
    int expectedSize = regressionTables.size() + 1;
    assertEquals(expectedSize, retrieved.size());
    final Collection<KiePMMLTableSourceCategory> values = retrieved.values();
    regressionTables.forEach(regressionTable -> assertTrue(values.stream().anyMatch(kiePMMLTableSourceCategory -> kiePMMLTableSourceCategory.getCategory().equals(regressionTable.getTargetCategory()))));
}
Also used : KiePMMLTableSourceCategory(org.kie.pmml.models.regression.model.tuples.KiePMMLTableSourceCategory) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) PMMLModelTestUtils.getRegressionModel(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRegressionModel) RegressionModel(org.dmg.pmml.regression.RegressionModel) KiePMMLRegressionModel(org.kie.pmml.models.regression.model.KiePMMLRegressionModel) Test(org.junit.Test)

Example 37 with HasClassLoaderMock

use of org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock in project drools by kiegroup.

the class KiePMMLRegressionModelFactoryTest method getKiePMMLRegressionModelClasses.

@Test
public void getKiePMMLRegressionModelClasses() throws IOException, IllegalAccessException, InstantiationException {
    final CompilationDTO<RegressionModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, regressionModel, new HasClassLoaderMock());
    KiePMMLRegressionModel retrieved = KiePMMLRegressionModelFactory.getKiePMMLRegressionModelClasses(RegressionCompilationDTO.fromCompilationDTO(compilationDTO));
    assertNotNull(retrieved);
    assertEquals(regressionModel.getModelName(), retrieved.getName());
    assertEquals(MINING_FUNCTION.byName(regressionModel.getMiningFunction().value()), retrieved.getMiningFunction());
    assertEquals(miningFields.get(0).getName().getValue(), retrieved.getTargetField());
    final AbstractKiePMMLTable regressionTable = retrieved.getRegressionTable();
    assertNotNull(regressionTable);
    assertTrue(regressionTable instanceof KiePMMLClassificationTable);
    evaluateCategoricalRegressionTable((KiePMMLClassificationTable) regressionTable);
}
Also used : KiePMMLRegressionModel(org.kie.pmml.models.regression.model.KiePMMLRegressionModel) AbstractKiePMMLTable(org.kie.pmml.models.regression.model.AbstractKiePMMLTable) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) KiePMMLClassificationTable(org.kie.pmml.models.regression.model.KiePMMLClassificationTable) PMMLModelTestUtils.getRegressionModel(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRegressionModel) RegressionModel(org.dmg.pmml.regression.RegressionModel) KiePMMLRegressionModel(org.kie.pmml.models.regression.model.KiePMMLRegressionModel) Test(org.junit.Test)

Example 38 with HasClassLoaderMock

use of org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock in project drools by kiegroup.

the class KiePMMLRegressionModelFactoryTest method getKiePMMLRegressionModelSourcesMap.

@Test
public void getKiePMMLRegressionModelSourcesMap() throws IOException {
    final CommonCompilationDTO<RegressionModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, regressionModel, new HasClassLoaderMock());
    Map<String, String> retrieved = KiePMMLRegressionModelFactory.getKiePMMLRegressionModelSourcesMap(RegressionCompilationDTO.fromCompilationDTO(compilationDTO));
    assertNotNull(retrieved);
    int expectedSize = regressionTables.size() + // One for classification and one for the whole model
    2;
    assertEquals(expectedSize, retrieved.size());
}
Also used : HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) PMMLModelTestUtils.getRegressionModel(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRegressionModel) RegressionModel(org.dmg.pmml.regression.RegressionModel) KiePMMLRegressionModel(org.kie.pmml.models.regression.model.KiePMMLRegressionModel) Test(org.junit.Test)

Example 39 with HasClassLoaderMock

use of org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock in project drools by kiegroup.

the class RegressionModelImplementationProviderTest method getKiePMMLModel.

@Test
public void getKiePMMLModel() 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 KiePMMLRegressionModel retrieved = PROVIDER.getKiePMMLModel(compilationDTO);
    assertNotNull(retrieved);
    assertTrue(retrieved instanceof Serializable);
}
Also used : Serializable(java.io.Serializable) KiePMMLRegressionModel(org.kie.pmml.models.regression.model.KiePMMLRegressionModel) 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)

Example 40 with HasClassLoaderMock

use of org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock 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

Test (org.junit.Test)48 HasClassLoaderMock (org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock)48 RegressionModel (org.dmg.pmml.regression.RegressionModel)15 PMML (org.dmg.pmml.PMML)14 CommonCompilationDTO (org.kie.pmml.compiler.api.dto.CommonCompilationDTO)14 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)11 DataDictionary (org.dmg.pmml.DataDictionary)10 DataField (org.dmg.pmml.DataField)10 MiningField (org.dmg.pmml.MiningField)10 MiningSchema (org.dmg.pmml.MiningSchema)10 RegressionCompilationDTO (org.kie.pmml.models.regression.compiler.dto.RegressionCompilationDTO)10 Scorecard (org.dmg.pmml.scorecard.Scorecard)9 CompilationDTO (org.kie.pmml.compiler.api.dto.CompilationDTO)8 Serializable (java.io.Serializable)6 TreeModel (org.dmg.pmml.tree.TreeModel)6 KiePMMLModel (org.kie.pmml.commons.model.KiePMMLModel)6 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)5 Expression (com.github.javaparser.ast.expr.Expression)5 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)5 RegressionTable (org.dmg.pmml.regression.RegressionTable)5