Search in sources :

Example 1 with SegmentCompilationDTO

use of org.kie.pmml.models.mining.compiler.dto.SegmentCompilationDTO in project drools by kiegroup.

the class KiePMMLSegmentFactoryTest method getSegmentSourcesMapHasSourcesWithKiePMMLModelClass.

@Test
public void getSegmentSourcesMapHasSourcesWithKiePMMLModelClass() {
    final Segment segment = MINING_MODEL.getSegmentation().getSegments().get(0);
    final String regressionModelName = "CategoricalVariablesRegression";
    final String kiePMMLModelClass = PACKAGE_NAME + "." + regressionModelName;
    final Map<String, String> sourcesMap = new HashMap<>();
    sourcesMap.put(kiePMMLModelClass, String.format("public class %s {}", regressionModelName));
    final CommonCompilationDTO<MiningModel> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, MINING_MODEL, new HasKnowledgeBuilderMock(KNOWLEDGE_BUILDER));
    final MiningModelCompilationDTO compilationDTO = MiningModelCompilationDTO.fromCompilationDTO(source);
    final SegmentCompilationDTO segmentCompilationDTO = SegmentCompilationDTO.fromGeneratedPackageNameAndFields(compilationDTO, segment, compilationDTO.getFields());
    final Map<String, String> retrieved = KiePMMLSegmentFactory.getSegmentSourcesMap(segmentCompilationDTO, true);
    commonEvaluateMap(retrieved, segment);
}
Also used : HasKnowledgeBuilderMock(org.kie.pmml.models.mining.compiler.HasKnowledgeBuilderMock) MiningModel(org.dmg.pmml.mining.MiningModel) HashMap(java.util.HashMap) SegmentCompilationDTO(org.kie.pmml.models.mining.compiler.dto.SegmentCompilationDTO) MiningModelCompilationDTO(org.kie.pmml.models.mining.compiler.dto.MiningModelCompilationDTO) Segment(org.dmg.pmml.mining.Segment) Test(org.junit.Test)

Example 2 with SegmentCompilationDTO

use of org.kie.pmml.models.mining.compiler.dto.SegmentCompilationDTO in project drools by kiegroup.

the class KiePMMLSegmentFactoryTest method getSegmentSourcesMapCompiled.

@Test
public void getSegmentSourcesMapCompiled() throws Exception {
    final Segment segment = MINING_MODEL.getSegmentation().getSegments().get(0);
    final List<KiePMMLModel> nestedModels = new ArrayList<>();
    final String expectedNestedModelGeneratedClass = getExpectedNestedModelClass(segment);
    final HasKnowledgeBuilderMock hasKnowledgeBuilderMock = new HasKnowledgeBuilderMock(KNOWLEDGE_BUILDER);
    try {
        hasKnowledgeBuilderMock.getClassLoader().loadClass(expectedNestedModelGeneratedClass);
        fail("Expecting class not found: " + expectedNestedModelGeneratedClass);
    } catch (Exception e) {
        assertTrue(e instanceof ClassNotFoundException);
    }
    final CommonCompilationDTO<MiningModel> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, MINING_MODEL, hasKnowledgeBuilderMock);
    final MiningModelCompilationDTO compilationDTO = MiningModelCompilationDTO.fromCompilationDTO(source);
    final SegmentCompilationDTO segmentCompilationDTO = SegmentCompilationDTO.fromGeneratedPackageNameAndFields(compilationDTO, segment, compilationDTO.getFields());
    final Map<String, String> retrieved = KiePMMLSegmentFactory.getSegmentSourcesMapCompiled(segmentCompilationDTO, nestedModels);
    commonEvaluateNestedModels(nestedModels);
    commonEvaluateMap(retrieved, segment);
    hasKnowledgeBuilderMock.getClassLoader().loadClass(expectedNestedModelGeneratedClass);
}
Also used : HasKnowledgeBuilderMock(org.kie.pmml.models.mining.compiler.HasKnowledgeBuilderMock) ArrayList(java.util.ArrayList) SegmentCompilationDTO(org.kie.pmml.models.mining.compiler.dto.SegmentCompilationDTO) Segment(org.dmg.pmml.mining.Segment) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) MiningModel(org.dmg.pmml.mining.MiningModel) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) MiningModelCompilationDTO(org.kie.pmml.models.mining.compiler.dto.MiningModelCompilationDTO) Test(org.junit.Test)

Example 3 with SegmentCompilationDTO

use of org.kie.pmml.models.mining.compiler.dto.SegmentCompilationDTO in project drools by kiegroup.

the class KiePMMLSegmentFactoryTest method getSegmentSourcesMap.

@Test
public void getSegmentSourcesMap() {
    final Segment segment = MINING_MODEL.getSegmentation().getSegments().get(0);
    final List<KiePMMLModel> nestedModels = new ArrayList<>();
    final CommonCompilationDTO<MiningModel> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, MINING_MODEL, new HasKnowledgeBuilderMock(KNOWLEDGE_BUILDER));
    final MiningModelCompilationDTO compilationDTO = MiningModelCompilationDTO.fromCompilationDTO(source);
    final SegmentCompilationDTO segmentCompilationDTO = SegmentCompilationDTO.fromGeneratedPackageNameAndFields(compilationDTO, segment, compilationDTO.getFields());
    final Map<String, String> retrieved = KiePMMLSegmentFactory.getSegmentSourcesMap(segmentCompilationDTO, nestedModels);
    commonEvaluateNestedModels(nestedModels);
    commonEvaluateMap(retrieved, segment);
}
Also used : HasKnowledgeBuilderMock(org.kie.pmml.models.mining.compiler.HasKnowledgeBuilderMock) MiningModel(org.dmg.pmml.mining.MiningModel) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) ArrayList(java.util.ArrayList) SegmentCompilationDTO(org.kie.pmml.models.mining.compiler.dto.SegmentCompilationDTO) MiningModelCompilationDTO(org.kie.pmml.models.mining.compiler.dto.MiningModelCompilationDTO) Segment(org.dmg.pmml.mining.Segment) Test(org.junit.Test)

Example 4 with SegmentCompilationDTO

use of org.kie.pmml.models.mining.compiler.dto.SegmentCompilationDTO in project drools by kiegroup.

the class KiePMMLSegmentFactory method getSegmentsSourcesMap.

public static Map<String, String> getSegmentsSourcesMap(final MiningModelCompilationDTO compilationDTO, final List<KiePMMLModel> nestedModels) {
    final List<Segment> segments = compilationDTO.getModel().getSegmentation().getSegments();
    logger.debug(GET_SEGMENTS, segments);
    final Map<String, String> toReturn = new HashMap<>();
    segments.forEach(segment -> {
        final SegmentCompilationDTO segmentCompilationDTO = SegmentCompilationDTO.fromGeneratedPackageNameAndFields(compilationDTO, segment, compilationDTO.getFields());
        toReturn.putAll(getSegmentSourcesMap(segmentCompilationDTO, nestedModels));
        compilationDTO.addFields(segmentCompilationDTO.getFields());
    });
    return toReturn;
}
Also used : HashMap(java.util.HashMap) SegmentCompilationDTO(org.kie.pmml.models.mining.compiler.dto.SegmentCompilationDTO) Segment(org.dmg.pmml.mining.Segment)

Example 5 with SegmentCompilationDTO

use of org.kie.pmml.models.mining.compiler.dto.SegmentCompilationDTO in project drools by kiegroup.

the class KiePMMLSegmentFactory method getSegmentsSourcesMapCompiled.

public static Map<String, String> getSegmentsSourcesMapCompiled(final MiningModelCompilationDTO compilationDTO, final List<KiePMMLModel> nestedModels) {
    logger.debug(GET_SEGMENTS, compilationDTO.getSegments());
    final Map<String, String> toReturn = new HashMap<>();
    compilationDTO.getSegments().forEach(segment -> {
        final SegmentCompilationDTO segmentCompilationDTO = SegmentCompilationDTO.fromGeneratedPackageNameAndFields(compilationDTO, segment, compilationDTO.getFields());
        toReturn.putAll(getSegmentSourcesMapCompiled(segmentCompilationDTO, nestedModels));
        compilationDTO.addFields(segmentCompilationDTO.getFields());
    });
    return toReturn;
}
Also used : HashMap(java.util.HashMap) SegmentCompilationDTO(org.kie.pmml.models.mining.compiler.dto.SegmentCompilationDTO)

Aggregations

SegmentCompilationDTO (org.kie.pmml.models.mining.compiler.dto.SegmentCompilationDTO)5 Segment (org.dmg.pmml.mining.Segment)4 HashMap (java.util.HashMap)3 MiningModel (org.dmg.pmml.mining.MiningModel)3 Test (org.junit.Test)3 HasKnowledgeBuilderMock (org.kie.pmml.models.mining.compiler.HasKnowledgeBuilderMock)3 MiningModelCompilationDTO (org.kie.pmml.models.mining.compiler.dto.MiningModelCompilationDTO)3 ArrayList (java.util.ArrayList)2 KiePMMLModel (org.kie.pmml.commons.model.KiePMMLModel)2 IOException (java.io.IOException)1 JAXBException (javax.xml.bind.JAXBException)1 SAXException (org.xml.sax.SAXException)1