/** * @param pmmlString PMML model encoded as an XML doc in a string * @return {@link PMML} object representing the model * @throws IOException if XML can't be unserialized */ public static PMML fromString(String pmmlString) throws IOException { // Emulate PMMLUtil.unmarshal here, but need to accept a Reader InputSource source = new InputSource(new StringReader(pmmlString)); try { return JAXBUtil.unmarshalPMML(ImportFilter.apply(source)); } catch (JAXBException | SAXException e) { throw new IOException(e); } }
public static PMML loadPMML(String path) throws Exception { InputStream is = null; try { is = new FileInputStream(path); InputSource source = new InputSource(is); SAXSource transformedSource = ImportFilter.apply(source); return JAXBUtil.unmarshalPMML(transformedSource); } catch (Exception e) { e.printStackTrace(); throw e; } }
public static PMML loadPMML(String path) throws Exception { InputStream is = null; try { is = new FileInputStream(path); InputSource source = new InputSource(is); SAXSource transformedSource = ImportFilter.apply(source); return JAXBUtil.unmarshalPMML(transformedSource); } catch (Exception e) { e.printStackTrace(); throw e; } finally { IOUtils.closeQuietly(is); } }
/** * @param pmmlString PMML model encoded as an XML doc in a string * @return {@link PMML} object representing the model * @throws IOException if XML can't be unserialized */ public static PMML fromString(String pmmlString) throws IOException { // Emulate PMMLUtil.unmarshal here, but need to accept a Reader InputSource source = new InputSource(new StringReader(pmmlString)); try { return JAXBUtil.unmarshalPMML(ImportFilter.apply(source)); } catch (JAXBException | SAXException e) { throw new IOException(e); } }
@PostConstruct public void setUp() throws IOException, SAXException, JAXBException { try (InputStream is = properties.getModelLocation().getInputStream()) { Source transformedSource = ImportFilter.apply(new InputSource(is)); pmml = JAXBUtil.unmarshalPMML(transformedSource); Assert.state(!pmml.getModels().isEmpty(), "The provided PMML file at " + properties.getModelLocation() + " does not contain any model"); } }
/** * Quite manually parse our fake model representation in PMML. */ private static ALSModelDescription read(InputStream in) throws JAXBException, SAXException { PMML pmml = JAXBUtil.unmarshalPMML(ImportFilter.apply(new InputSource(in))); List<Extension> extensions = pmml.getExtensions(); Preconditions.checkNotNull(extensions); Preconditions.checkArgument(!extensions.isEmpty()); ALSModelDescription model = new ALSModelDescription(); for (Extension extension : extensions) { String name = extension.getName(); String value = extension.getValue(); Preconditions.checkNotNull(name); Preconditions.checkNotNull(value); model.getPathByKey().put(name, value); } return model; }