use of org.kie.pmml.pmml_4_2.model.PMML4UnitImpl in project drools by kiegroup.
the class PMML4Compiler method getJavaClasses.
@Override
public Map<String, String> getJavaClasses(InputStream stream) {
Map<String, String> javaClasses = new HashMap<>();
PMML pmml = loadModel(PMML, stream);
if (pmml != null) {
PMML4Unit unit = new PMML4UnitImpl(pmml);
if (unit != null) {
List<PMML4Model> models = unit.getModels();
models.forEach(model -> {
Map.Entry<String, String> inputPojo = model.getMappedMiningPojo();
Map.Entry<String, String> ruleUnit = model.getMappedRuleUnit();
if (inputPojo != null)
javaClasses.put(inputPojo.getKey(), inputPojo.getValue());
if (ruleUnit != null)
javaClasses.put(ruleUnit.getKey(), ruleUnit.getValue());
});
}
}
return javaClasses;
}
use of org.kie.pmml.pmml_4_2.model.PMML4UnitImpl in project drools by kiegroup.
the class PMML4Compiler method precompile.
public List<PMMLResource> precompile(InputStream stream, ClassLoader classLoader, KieBaseModel rootKieBaseModel) {
List<PMMLResource> resources = new ArrayList<>();
KieServices services = KieServices.Factory.get();
KieModuleModel module = services.newKieModuleModel();
this.results = new ArrayList<KnowledgeBuilderResult>();
PMML pmml = loadModel(PMML, stream);
helper.setResolver(classLoader);
PMML4Unit unit = new PMML4UnitImpl(pmml);
if (unit.containsMiningModel()) {
Miningmodel rootModel = unit.getRootMiningModel();
resources = buildResourcesFromModel(pmml, rootModel, null, classLoader, module);
} else {
PMML4Model rootModel = unit.getRootModel();
if (rootModel != null) {
helper.setPack(rootModel.getModelPackageName());
KieBaseModel kbm = module.newKieBaseModel(rootModel.getModelId());
kbm.addPackage(helper.getPack()).setDefault(true).setEventProcessingMode(EventProcessingOption.CLOUD);
PMMLResource resource = new PMMLResource(helper.getPack());
resource.setKieBaseModel(kbm);
resource.addRules(rootModel.getModelId(), this.compile(pmml, classLoader));
resources.add(resource);
}
}
return resources;
}
use of org.kie.pmml.pmml_4_2.model.PMML4UnitImpl in project drools by kiegroup.
the class PMML4Compiler method generateTheory.
public String generateTheory(PMML pmml) {
StringBuilder sb = new StringBuilder();
PMML4Unit unit = new PMML4UnitImpl(pmml);
KieBase visitor;
try {
visitor = checkBuildingResources(pmml);
} catch (IOException e) {
this.results.add(new PMMLError(e.getMessage()));
return null;
}
KieSession visitorSession = visitor.newKieSession();
helper.reset();
visitorSession.setGlobal("registry", registry);
visitorSession.setGlobal("fld2var", new HashMap());
visitorSession.setGlobal("utils", helper);
visitorSession.setGlobal("unitPackageName", helper.getPack());
visitorSession.setGlobal("ruleUnitClassName", getRuleUnitClass(unit));
visitorSession.setGlobal("theory", sb);
visitorSession.insert(pmml);
visitorSession.fireAllRules();
String modelEvaluatingRules = sb.toString();
visitorSession.dispose();
return modelEvaluatingRules;
}
Aggregations