use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.
the class KiePMMLModelRetrieverTest method getFromCommonDataAndTransformationDictionaryAndModelWithProvider.
@Test
public void getFromCommonDataAndTransformationDictionaryAndModelWithProvider() throws Exception {
pmml = KiePMMLUtil.load(getFileInputStream(MULTIPLE_TARGETS_SOURCE), MULTIPLE_TARGETS_SOURCE);
TestModel model = new TestModel();
pmml.getModels().set(0, model);
final CommonCompilationDTO<TestModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, model, new HasClassLoaderMock());
final Optional<KiePMMLModel> retrieved = getFromCommonDataAndTransformationDictionaryAndModel(compilationDTO);
assertNotNull(retrieved);
assertTrue(retrieved.isPresent());
assertTrue(retrieved.get() instanceof KiePMMLTestingModel);
}
use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.
the class KiePMMLModelRetrieverTest method getFromCommonDataAndTransformationDictionaryAndModelWithSourcesCompiledWithoutProvider.
@Test
public void getFromCommonDataAndTransformationDictionaryAndModelWithSourcesCompiledWithoutProvider() throws Exception {
pmml = KiePMMLUtil.load(getFileInputStream(MINING_MODEL_WITH_NESTED_REFERS_SOURCE), MINING_MODEL_WITH_NESTED_REFERS_SOURCE);
MiningModel parentModel = (MiningModel) pmml.getModels().get(0);
Model model = parentModel.getSegmentation().getSegments().get(0).getModel();
final CommonCompilationDTO compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, model, new HasClassLoaderMock());
final Optional<KiePMMLModel> retrieved = getFromCommonDataAndTransformationDictionaryAndModelWithSourcesCompiled(compilationDTO);
assertNotNull(retrieved);
assertFalse(retrieved.isPresent());
}
use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.
the class PMMLCompilerService method populateWithPMMLRuleMappers.
static void populateWithPMMLRuleMappers(final List<KiePMMLModel> toReturn, final Resource resource) {
for (KiePMMLModel kiePMMLModel : toReturn) {
final List<String> generatedRuleMappers = new ArrayList<>();
addPMMLRuleMapper(kiePMMLModel, generatedRuleMappers, resource.getSourcePath());
addPMMLRuleMappers(kiePMMLModel, generatedRuleMappers, resource.getSourcePath());
}
}
use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.
the class PMMLCompilerService method addPMMLRuleMapper.
static void addPMMLRuleMapper(final KiePMMLModel kiePMMLModel, final List<String> generatedRuleMappers, final String sourcePath) {
if (!(kiePMMLModel instanceof HasSourcesMap)) {
String errorMessage = String.format("Expecting HasSourcesMap instance, retrieved %s inside %s", kiePMMLModel.getClass().getName(), sourcePath);
throw new KiePMMLException(errorMessage);
}
if (kiePMMLModel instanceof HasRule) {
String pkgUUID = ((HasRule) kiePMMLModel).getPkgUUID();
String rulesFileName = kiePMMLModel.getKModulePackageName() + "." + RULES_FILE_NAME + pkgUUID;
String pmmlRuleMapper = kiePMMLModel.getKModulePackageName() + "." + KIE_PMML_RULE_MAPPER_CLASS_NAME;
String ruleMapperSource = PMMLRuleMapperFactory.getPMMLRuleMapperSource(rulesFileName);
((HasRule) kiePMMLModel).addSourceMap(pmmlRuleMapper, ruleMapperSource);
generatedRuleMappers.add(pmmlRuleMapper);
}
if (kiePMMLModel instanceof HasNestedModels) {
for (KiePMMLModel nestedModel : ((HasNestedModels) kiePMMLModel).getNestedModels()) {
addPMMLRuleMapper(nestedModel, generatedRuleMappers, sourcePath);
}
}
}
use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.
the class PMMLRuntimeFactoryInternalTest method populateNestedKiePackageList.
@Test
public void populateNestedKiePackageList() {
// Setup kiebase
KiePMMLModel kiePMMLModel = getKiePMMLModelWithNested("FAKE");
InternalKnowledgePackage pmmlKnowledgePackage = getKnowledgePackageWithPMMLResourceType(kiePMMLModel);
List<KiePackage> kiePackages = ((HasNestedModels) kiePMMLModel).getNestedModels().stream().map(this::getKnowledgePackageWithPMMLResourceType).collect(Collectors.toList());
InternalKnowledgeBase kieBase = (InternalKnowledgeBase) new KieHelper().build(ExecutableModelProject.class);
kieBase.addPackage(pmmlKnowledgePackage);
kieBase.addPackages(kiePackages);
// Actual test
final List<KiePackage> toPopulate = new ArrayList<>();
PMMLRuntimeFactoryInternal.populateNestedKiePackageList(Collections.singleton(kiePMMLModel), toPopulate, kieBase);
assertFalse(toPopulate.isEmpty());
assertEquals(kiePackages.size(), toPopulate.size());
}
Aggregations