/** * Write the CAS data to a SAX content handler. * * @param cas * The CAS to be serialized. * @param contentHandler * The SAX content handler the data is written to. * * @throws SAXException if there was a SAX exception */ public void serialize(CAS cas, ContentHandler contentHandler) throws SAXException { this.serialize(cas, contentHandler, (ErrorHandler) null); }
/** * Serializes a CAS to an XMI stream. * * @param aCAS * CAS to serialize. * @param aStream * output stream to which to write the XMI document * * @throws SAXException * if a problem occurs during XMI serialization */ public static void serialize(CAS aCAS, OutputStream aStream) throws SAXException { serialize(aCAS, null, aStream, false, null); }
/** * Write the CAS data to a SAX content handler. * * @param cas * The CAS to be serialized. * @param contentHandler * The SAX content handler the data is written to. * @param errorHandler the SAX Error Handler to use * * @throws SAXException if there was a SAX exception */ public void serialize(CAS cas, ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException { serialize(cas, contentHandler, errorHandler, null, null); }
/** * Serializes a CAS in the given format. * * @param jcas * CAS (Common Analysis System) to be serialized. * @param type * type of cTAKES (UIMA) serializer used to write CAS. * @param prettyPrint * {@code true} to do pretty printing of output. * @param stream * {@link OutputStream} object used to print out information * extracted by using cTAKES. * @throws SAXException * if there was a SAX exception. * @throws IOException * if any I/O error occurs. */ public static void serialize(JCas jcas, CTAKESSerializer type, boolean prettyPrint, OutputStream stream) throws SAXException, IOException { if (type == CTAKESSerializer.XCAS) { XCASSerializer.serialize(jcas.getCas(), stream, prettyPrint); } else if (type == CTAKESSerializer.XMI) { XmiCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(), stream, prettyPrint, new XmiSerializationSharedData()); } else { XmlCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(), stream); } }
public void setJCas(JCas jCas) throws IOException { // now convert to XMI ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); try { XmiCasSerializer.serialize(jCas.getCas(), byteOutputStream); } catch (SAXException e) { throw new IOException(e); } // encode to base64 this.base64JCas = new BASE64Encoder().encode(byteOutputStream.toByteArray()); }
private void writeXmi(CAS aCas, String id) throws IOException, SAXException { File outFile = new File(outputDirectory, id ); FileOutputStream out = null; try { out = new FileOutputStream(outFile); XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(out, false); ser.serialize(aCas, xmlSer.getContentHandler()); } finally { if (out != null) { out.close(); } } }
public String serializeCasToXmi(CAS aCAS, XmiSerializationSharedData serSharedData, Marker aMarker) throws Exception { Writer writer = new StringWriter(); try { XMLSerializer xmlSer = new XMLSerializer(writer, false); XmiCasSerializer ser = new XmiCasSerializer(aCAS.getTypeSystem()); ser.serialize(aCAS, xmlSer.getContentHandler(), null, serSharedData, aMarker); return writer.toString(); } catch (SAXException e) { throw e; } finally { writer.close(); } }
/** * Serialize a CAS to a file in XMI format * * @param cas CAS to serialize * @param file output file * @throws IOException - * @throws SAXException - */ static private void writeXmi( final CAS cas, final File file ) throws IOException, SAXException { try ( OutputStream outputStream = new BufferedOutputStream( new FileOutputStream( file ) ) ) { XmiCasSerializer casSerializer = new XmiCasSerializer( cas.getTypeSystem() ); XMISerializer xmiSerializer = new XMISerializer( outputStream ); casSerializer.serialize( cas, xmiSerializer.getContentHandler() ); } }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { try (OutputStream docOS = getOutputStream(aJCas, ".xmi")) { XmiCasSerializer.serialize(aJCas.getCas(), null, docOS, prettyPrint, null); if (!typeSystemWritten || typeSystemFile == null) { writeTypeSystem(aJCas); typeSystemWritten = true; } } catch (Exception e) { throw new AnalysisEngineProcessException(e); } }
private void writeXmi(CAS aCas, String id) throws IOException, SAXException { File outFile = new File(outputDirectory, id ); FileOutputStream out = null; try { out = new FileOutputStream(outFile); XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(out, false); ser.serialize(aCas, xmlSer.getContentHandler()); } finally { if (out != null) { out.close(); } } }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { try (OutputStream docOS = getOutputStream(aJCas, ".xmi")) { XmiCasSerializer.serialize(aJCas.getCas(), null, docOS, prettyPrint, null); if (!typeSystemWritten || typeSystemFile == null) { writeTypeSystem(aJCas); typeSystemWritten = true; } } catch (Exception e) { throw new AnalysisEngineProcessException(e); } }
private static void writeXmi(CAS aCas, File name) throws IOException, SAXException { FileOutputStream out = null; try { // write XMI out = new FileOutputStream(name); XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(out, false); ser.serialize(aCas, xmlSer.getContentHandler()); } finally { if (out != null) { out.close(); } } }
private String serializeCas(CAS aCas) throws RecommendationException { try (StringWriter out = new StringWriter()) { // Passing "null" as the type system to the XmiCasSerializer means that we want // to serialize all types (i.e. no filtering for a specific target type system). XmiCasSerializer xmiCasSerializer = new XmiCasSerializer(null); XMLSerializer sax2xml = new XMLSerializer(out, true); xmiCasSerializer.serialize(aCas, sax2xml.getContentHandler(), null, null, null); return out.toString(); } catch (CASRuntimeException | SAXException | IOException e) { throw new RecommendationException("Error while serializing CAS!", e); } }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { try (OutputStream docOS = getOutputStream(aJCas, filenameSuffix)) { XmiCasSerializer.serialize(aJCas.getCas(), null, docOS, prettyPrint, null); if (!typeSystemWritten) { writeTypeSystem(aJCas); typeSystemWritten = true; } } catch (Exception e) { throw new AnalysisEngineProcessException(e); } }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { try (OutputStream docOS = getOutputStream(aJCas, ".xmi")) { XmiCasSerializer.serialize(aJCas.getCas(), null, docOS, prettyPrint, null); if (!typeSystemWritten || typeSystemFile == null) { writeTypeSystem(aJCas); typeSystemWritten = true; } } catch (Exception e) { throw new AnalysisEngineProcessException(e); } }
private String serializeCas(CAS aCas) throws RecommendationException { try (StringWriter out = new StringWriter()) { // Passing "null" as the type system to the XmiCasSerializer means that we want // to serialize all types (i.e. no filtering for a specific target type system). XmiCasSerializer xmiCasSerializer = new XmiCasSerializer(null); XMLSerializer sax2xml = new XMLSerializer(out, true); xmiCasSerializer.serialize(aCas, sax2xml.getContentHandler(), null, null, null); return out.toString(); } catch (CASRuntimeException | SAXException | IOException e) { throw new RecommendationException("Error while serializing CAS!", e); } }
private static void writeXmi(CAS aCas, File name) throws Exception { FileOutputStream out = null; try { // write XMI out = new FileOutputStream(name); XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(out, false); ser.serialize(aCas, xmlSer.getContentHandler()); } catch (Exception e) { throw e; } finally { if (out != null) { out.close(); } } }
@Override public void write(OutputStream aStream) throws Exception { XmiCasSerializer ser = new XmiCasSerializer(cas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(aStream, false); ser.serialize(cas, xmlSer.getContentHandler()); }
private void writeXmi(CAS aCas, OutputStream out) throws IOException, SAXException { // seems like it is not necessary to buffer outputStream for SAX TransformationHandler // out = new BufferedOutputStream(out); XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(out, xmlFormatted); ser.serialize(aCas, xmlSer.getContentHandler()); } }
@Override public void write(OutputStream aStream) throws Exception { XmiCasSerializer ser = new XmiCasSerializer(cas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(aStream, false); ser.serialize(cas, xmlSer.getContentHandler()); }