public String compile(String resource, ClassLoader classLoader) { String theory = null; Resource cpr = new ClassPathResource(resource); try { theory = compile(cpr.getInputStream(), classLoader); } catch (IOException e) { results.add(new PMMLError(e.toString())); e.printStackTrace(); } return theory; }
public Resource[] transform(Resource resource, ClassLoader classLoader) { String theory = null; try { theory = compile(resource.getInputStream(), classLoader); } catch (IOException e) { results.add(new PMMLError(e.toString())); e.printStackTrace(); return new Resource[0]; } return new Resource[]{buildOutputResource(resource, theory)}; }
/** * Imports a PMML source file, returning a Java descriptor * @param model the PMML package name (classes derived from a specific schema) * @param source the name of the PMML resource storing the predictive model * @return the Java Descriptor of the PMML resource */ public PMML loadModel(String model, InputStream source) { try { if (schema == null) { visitorBuildResults.add(new PMMLWarning(ResourceFactory.newInputStreamResource(source), "Could not validate PMML document, schema not available")); } final JAXBContext jc; final ClassLoader ccl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(PMML4Compiler.class.getClassLoader()); jc = JAXBContext.newInstance(model, PMML4Compiler.class.getClassLoader()); } finally { Thread.currentThread().setContextClassLoader(ccl); } Unmarshaller unmarshaller = jc.createUnmarshaller(); if (schema != null) { unmarshaller.setSchema(schema); } return (PMML) unmarshaller.unmarshal(source); } catch (JAXBException e) { this.results.add(new PMMLError(e.toString())); return null; } }
private InputStream getInputStreamByFileName(String fileName) { InputStream is = null; Resource res = ResourceFactory.newClassPathResource(fileName); try { is = res.getInputStream(); } catch (Exception e) { } if (is == null) { res = ResourceFactory.newFileResource(fileName); } try { is = res.getInputStream(); } catch (Exception e) { this.results.add(new PMMLError("Unable to retrieve file based resource: " + fileName)); } return is; }
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; }