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