/** * @param in stream to read PMML from * @return {@link PMML} model file from stream * @throws IOException if an error occurs while reading the model from the stream */ public static PMML read(InputStream in) throws IOException { try { return PMMLUtil.unmarshal(in); } catch (JAXBException | SAXException e) { throw new IOException(e); } }
/** * @param pmml {@link PMML} model to write * @param out stream to write the model to * @throws IOException if an error occurs while writing the model to storage */ public static void write(PMML pmml, OutputStream out) throws IOException { try { PMMLUtil.marshal(pmml, out); } catch (JAXBException e) { throw new IOException(e); } }
/** * @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); } }
/** * @see JAXBUtil#unmarshalPMML(Source) */ static public PMML unmarshal(InputStream is) throws SAXException, JAXBException { Source source = SAXUtil.createFilteredSource(is, new ImportFilter()); return JAXBUtil.unmarshalPMML(source); }
static public PMML unmarshal(Class<?> clazz, XMLFilter... filters) throws IOException, SAXException, JAXBException { try(InputStream is = getStream(clazz)){ Source source = SAXUtil.createFilteredSource(is, filters); return JAXBUtil.unmarshalPMML(source); } }
@SuppressWarnings ( value = {"unchecked"} ) static public <S extends Serializable> S clone(S object, int capacity) throws ClassNotFoundException, IOException { DirectByteArrayOutputStream buffer = new DirectByteArrayOutputStream(capacity); serialize(object, buffer); try(InputStream is = buffer.getInputStream()){ return (S)deserialize(is); } } }
/** * @param pmml model * @return model serialized as an XML document as a string */ public static String toString(PMML pmml) { try (StringWriter out = new StringWriter()) { // v JAXBUtil.marshalPMML but need to set compact, non-pretty output Marshaller marshaller = JAXBUtil.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE); marshaller.marshal(pmml, new StreamResult(out)); return out.toString(); } catch (JAXBException | IOException e) { // IOException should not be possible; JAXBException would only happen with XML // config problems. throw new IllegalStateException(e); } }
public CustomPMML(PMML pmml){ super(); ReflectionUtil.copyState(pmml, this); } }
@Test public void transform() throws Exception { byte[] original = ResourceUtil.getByteArray(ApplyTest.class); checkApply(original, "", null); byte[] latest = VersionUtil.upgradeToLatest(original); checkApply(latest, null, ""); byte[] latestToOriginal = VersionUtil.downgrade(latest, Version.PMML_4_1); checkApply(latestToOriginal, "", null); }
@Test public void transform() throws Exception { byte[] original = ResourceUtil.getByteArray(TargetValueTest.class); checkTargetValue(original, "", null); byte[] latest = VersionUtil.upgradeToLatest(original); checkTargetValue(latest, null, ""); byte[] latestToOriginal = VersionUtil.downgrade(latest, Version.PMML_3_1); checkTargetValue(latestToOriginal, "", null); }
protected ToStringHelper toStringHelper(){ return new ToStringHelper(this); } }
@Override public void execute() throws Exception { PMML pmml = unmarshalPMML(this.input); pmml = transform(pmml); marshalPMML(pmml, this.output); } }
static private List<String> parseStringArray(String string){ return ArrayUtil.parse(string, true); } }
/** * <p> * Marshals a {@link PMML} class model object. * </p> * * @see ExportFilter */ static public void marshalPMML(PMML pmml, Result result) throws JAXBException { marshal(pmml, result); }
@Override public void execute() throws Exception { PMML pmml = unmarshalPMML(this.input); consume(pmml); } }
static public byte[] getByteArray(Version version) throws IOException { try(InputStream is = getStream(version)){ return toByteArray(is); } }
@SuppressWarnings ( value = {"unchecked"} ) static public <S extends Serializable> S clone(S object, int capacity) throws ClassNotFoundException, IOException { DirectByteArrayOutputStream buffer = new DirectByteArrayOutputStream(capacity); serialize(object, buffer); try(InputStream is = buffer.getInputStream()){ return (S)deserialize(is); } } }
public CustomSimplePredicate(SimplePredicate simplePredicate){ super(); ReflectionUtil.copyState(simplePredicate, this); } }
/** * <p> * Marshals a {@link PMML} class model object. * </p> * * @see ExportFilter */ static public void marshalPMML(PMML pmml, Result result) throws JAXBException { marshal(pmml, result); }