use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.
the class PMMLAssemblerService method addModels.
protected void addModels(KnowledgeBuilderImpl kbuilderImpl, List<KiePMMLModel> toAdd) {
for (KiePMMLModel kiePMMLModel : toAdd) {
PackageDescr pkgDescr = new PackageDescr(kiePMMLModel.getKModulePackageName());
PackageRegistry pkgReg = kbuilderImpl.getOrCreatePackageRegistry(pkgDescr);
InternalKnowledgePackage kpkgs = pkgReg.getPackage();
ResourceTypePackageRegistry rpkg = kpkgs.getResourceTypePackages();
PMMLPackage pmmlPkg = rpkg.computeIfAbsent(ResourceType.PMML, rtp -> new PMMLPackageImpl());
pmmlPkg.addAll(Collections.singletonList(kiePMMLModel));
if (kiePMMLModel instanceof HasNestedModels) {
addModels(kbuilderImpl, ((HasNestedModels) kiePMMLModel).getNestedModels());
}
}
}
use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.
the class PMMLCompilerServiceTest method addPMMLRuleMapperNoHasSourceMap.
@Test(expected = KiePMMLException.class)
public void addPMMLRuleMapperNoHasSourceMap() {
final KiePMMLModel kiePmmlModel = new KiePMMLTestingModel("name", Collections.emptyList());
PMMLCompilerService.addPMMLRuleMapper(kiePmmlModel, new ArrayList<>(), "source_path");
}
use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.
the class PMMLCompilerServiceTest method populateWithPMMLRuleMappers.
@Test
public void populateWithPMMLRuleMappers() {
final List<KiePMMLModel> toPopulate = new ArrayList<>();
toPopulate.add(new KiePMMLTestingModelWithSources("TEST", "kmodulePackageName", Collections.emptyMap()));
toPopulate.add(new KiePMMLModelHasRule("TEST", Collections.emptyList()));
toPopulate.add(new KiePMMLModelHasNestedModelsHasRule("TEST", Collections.emptyList()));
toPopulate.add(new KiePMMLModelHasNestedModelsHasSourceMap("TEST", Collections.emptyList()));
toPopulate.forEach(kiePMMLModel -> assertTrue(((HasSourcesMap) kiePMMLModel).getSourcesMap().isEmpty()));
final File file = new File("foo.pmml");
final Resource resource = new FileSystemResource(file);
PMMLCompilerService.populateWithPMMLRuleMappers(toPopulate, resource);
toPopulate.forEach(kiePmmlModel -> {
if (kiePmmlModel instanceof HasRule || kiePmmlModel instanceof KiePMMLModelHasNestedModelsHasRule) {
assertFalse(((HasSourcesMap) kiePmmlModel).getSourcesMap().isEmpty());
String expected = kiePmmlModel.getKModulePackageName() + "." + KIE_PMML_RULE_MAPPERS_CLASS_NAME;
assertTrue(((HasSourcesMap) kiePmmlModel).getSourcesMap().containsKey(expected));
if (kiePmmlModel instanceof HasRule) {
expected = kiePmmlModel.getKModulePackageName() + "." + KIE_PMML_RULE_MAPPER_CLASS_NAME;
assertTrue(((HasSourcesMap) kiePmmlModel).getSourcesMap().containsKey(expected));
}
} else {
assertTrue(((HasSourcesMap) kiePmmlModel).getSourcesMap().isEmpty());
}
});
}
use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.
the class PMMLCompilerServiceTest method addPMMLRuleMappersHasSourceMap.
@Test
public void addPMMLRuleMappersHasSourceMap() {
KiePMMLTestingModelWithSources kiePmmlModel = new KiePMMLTestingModelWithSources("TEST", "kmodulePackageName", new HashMap<>());
assertTrue(kiePmmlModel.getSourcesMap().isEmpty());
final List<String> generatedRuleMappers = IntStream.range(0, 3).mapToObj(i -> "apackage" + i + "." + KIE_PMML_RULE_MAPPER_CLASS_NAME).collect(Collectors.toList());
PMMLCompilerService.addPMMLRuleMappers(kiePmmlModel, generatedRuleMappers, "source_path");
assertFalse(kiePmmlModel.getSourcesMap().isEmpty());
String expected = kiePmmlModel.getKModulePackageName() + "." + KIE_PMML_RULE_MAPPERS_CLASS_NAME;
assertTrue(kiePmmlModel.getSourcesMap().containsKey(expected));
}
use of org.kie.pmml.commons.model.KiePMMLModel in project drools by kiegroup.
the class PMMLCompilerServiceTest method addPMMLRuleMappersNotHasSourceMap.
@Test(expected = KiePMMLException.class)
public void addPMMLRuleMappersNotHasSourceMap() {
final KiePMMLModel kiePmmlModel = KiePMMLTestingModel.builder("name", Collections.emptyList(), MINING_FUNCTION.REGRESSION).build();
final List<String> generatedRuleMappers = IntStream.range(0, 3).mapToObj(i -> "apackage" + i + "." + KIE_PMML_RULE_MAPPER_CLASS_NAME).collect(Collectors.toList());
PMMLCompilerService.addPMMLRuleMappers(kiePmmlModel, generatedRuleMappers, "source_path");
}
Aggregations