org.apache.uima.cas.impl.XCASSerializer.serialize()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(90)

本文整理了Java中org.apache.uima.cas.impl.XCASSerializer.serialize()方法的一些代码示例,展示了XCASSerializer.serialize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XCASSerializer.serialize()方法的具体详情如下:
包路径:org.apache.uima.cas.impl.XCASSerializer
类名称:XCASSerializer
方法名:serialize

XCASSerializer.serialize介绍

[英]Serializes an XCAS to a stream.
[中]将XCAS序列化为流。

代码示例

代码示例来源:origin: apache/uima-uimaj

/**
 * 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 IOException passed thru
 * @throws SAXException passed thru
 */
public void serialize(CAS cas, ContentHandler contentHandler) throws IOException, SAXException {
 serialize(cas, contentHandler, true);
}

代码示例来源:origin: apache/uima-uimaj

/**
 * Serializes an XCAS to a stream.
 * 
 * @param aCAS
 *          CAS to serialize.
 * @param aStream
 *          output stream to which to write the XCAS XML document
 * 
 * @throws SAXException
 *           if a problem occurs during XCAS serialization
 * @throws IOException
 *           if an I/O failure occurs
 */
public static void serialize(CAS aCAS, OutputStream aStream) throws SAXException, IOException {
 XCASSerializer.serialize(aCAS, aStream, false);
}

代码示例来源:origin: apache/tika

/**
 * 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);
  }
}

代码示例来源:origin: apache/uima-uimaj

/**
 * 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 encodeDoc
 *          If set to false, no uima.tcas.Document structure will be created, and the document
 *          text will not be serialized.
 * @throws IOException passed thru
 * @throws SAXException passed thru
 */
public void serialize(CAS cas, ContentHandler contentHandler, boolean encodeDoc)
    throws IOException, SAXException {
 serialize(cas, contentHandler, encodeDoc, null);
}

代码示例来源:origin: org.apache.uima/uimafit-core

/**
 * 
 * @param aCas
 *          the source CAS
 * @param aFile
 *          the file to write to
 * @throws IOException
 *           if there is a problem writing the file
 * @deprecated Use {@link CasIOUtils#save(CAS, OutputStream, org.apache.uima.cas.SerialFormat)}
 *             with {@link SerialFormat#XCAS} instead.
 */
@Deprecated
public static void writeXCas(CAS aCas, File aFile) throws IOException {
 OutputStream os = null;
 try {
  os = new FileOutputStream(aFile);
  XCASSerializer.serialize(aCas, os);
 } catch (SAXException e) {
  IOException ioe = new IOException(e.getMessage());
  ioe.initCause(e);
  throw ioe; // NOPMD
  // If we were using Java 1.6 and add the wrapped exception to the IOException
  // constructor, we would not get a warning here
 } finally {
  closeQuietly(os);
 }
}

代码示例来源:origin: org.apache.ctakes/ctakes-core

outputFile = new File( iv_outputDir + File.separatorChar + docName );
  out = new FileOutputStream( outputFile );
  XCASSerializer.serialize( view.getCas(), out, true ); // true -> formats the output
} finally {
  iv_procCount++;

代码示例来源:origin: apache/ctakes

outputFile = new File( iv_outputDir + File.separatorChar + docName );
  out = new FileOutputStream( outputFile );
  XCASSerializer.serialize( view.getCas(), out, true ); // true -> formats the output
} finally {
  iv_procCount++;

代码示例来源:origin: org.apache.ctakes/ctakes-assertion

private void writeXCas(CAS aCas, String fileName) throws IOException, SAXException {
  File outFile = new File(outputDirectory, fileName + ".xcas");
  FileOutputStream out = null;
  try {
    out = new FileOutputStream(outFile);
    XCASSerializer ser = new XCASSerializer(aCas.getTypeSystem());
    XMLSerializer xmlSer = new XMLSerializer(out, false);
    ser.serialize(aCas, xmlSer.getContentHandler());
  }
  finally {
    if (out != null) {
      out.close();
    }
  }
}

代码示例来源:origin: apache/ctakes

private void writeXCas(CAS aCas, String fileName) throws IOException, SAXException {
  File outFile = new File(outputDirectory, fileName + ".xcas");
  FileOutputStream out = null;
  try {
    out = new FileOutputStream(outFile);
    XCASSerializer ser = new XCASSerializer(aCas.getTypeSystem());
    XMLSerializer xmlSer = new XMLSerializer(out, false);
    ser.serialize(aCas, xmlSer.getContentHandler());
  }
  finally {
    if (out != null) {
      out.close();
    }
  }
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.bigdata/de.tudarmstadt.ukp.dkpro.bigdata.io.hadoop

/**
 * Returns XML (XCAS) representation of this CAS, stripped of all newlines.
 */
@Override
public String toString()
{
  if (cas == null)
    return "null";
  // Use StringWriter instead of OutputStream for XMLSerializer so that
  // we don't need to worry about string encoding (utf-8 vs. utf-16, etc.)
  StringWriter writer = new StringWriter();
  XMLSerializer xmlSerializer = new XMLSerializer(writer);
  XCASSerializer casSerializer = new XCASSerializer(cas.getTypeSystem());
  try {
    casSerializer.serialize(cas, xmlSerializer.getContentHandler());
  }
  catch (SAXException e) {
    e.printStackTrace();
  }
  catch (IOException e) {
    e.printStackTrace();
  }
  String xml = writer.toString();
  xml = xml.replace("\n", "");
  return xml;
}

代码示例来源:origin: org.apache.uima/uimaj-tools

/**
 * Serialize a CAS to a file in XCAS format
 * 
 * @param aCas
 *          CAS to serialize
 * @param name
 *          output file
 * 
 * @throws IOException
 *           if an I/O failure occurs
 * @throws SAXException
 *           if an error occurs generating the XML text
 */
private void writeXCas(CAS aCas, File name) throws IOException, SAXException {
 FileOutputStream out = null;
 try {
  out = new FileOutputStream(name);
  XCASSerializer ser = new XCASSerializer(aCas.getTypeSystem());
  XMLSerializer sax2xml = new XMLSerializer(out, false);
  ser.serialize(aCas, sax2xml.getContentHandler());
 } finally {
  if (out != null) {
   out.close();
  }
 }
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.bigdata/de.tudarmstadt.ukp.dkpro.bigdata.io.hadoop

XCASSerializer.serialize(aJCas.getCas(), byteArrayOutputStream);
this.writer.append(new Text(relativeDocumentPath),
    new Text(byteArrayOutputStream.toString("UTF-8")));

代码示例来源:origin: org.apache.uima/uimaj-tools

XMLSerializer xmlSerializer = new XMLSerializer(outStream);
 XCASSerializer xcasSerializer = new XCASSerializer(this.main.getCas().getTypeSystem());
 xcasSerializer.serialize(this.main.getCas(), xmlSerializer.getContentHandler());
 outStream.close();
} catch (IOException e) {

代码示例来源:origin: apache/uima-uimaj

/**
 * Serializes an XCAS to a stream.
 * 
 * @param aCAS
 *          CAS to serialize.
 * @param aStream
 *          output stream to which to write the XCAS XML document
 * @param isFormattedOutput
 *          if true the XCAS will be serialized formatted
 * 
 * @throws SAXException
 *           if a problem occurs during XCAS serialization
 * @throws IOException
 *           if an I/O failure occurs
 */
public static void serialize(CAS aCAS, OutputStream aStream, boolean isFormattedOutput)
    throws SAXException, IOException {
 XCASSerializer xcasSerializer = new XCASSerializer(aCAS.getTypeSystem());
 XMLSerializer sax2xml = new XMLSerializer(aStream, isFormattedOutput);
 xcasSerializer.serialize(aCAS, sax2xml.getContentHandler());
}

代码示例来源:origin: org.apache.uima/uimaj-tools

if (mXCAS.equalsIgnoreCase("xcas")) {
 XCASSerializer ser = new XCASSerializer(aCAS.getTypeSystem());
 ser.serialize(aCAS, xmlSer.getContentHandler());

代码示例来源:origin: org.apache.tika/tika-parsers

/**
 * 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);
  }
}

代码示例来源:origin: apache/uima-uimaj

break;
case XCAS:
 XCASSerializer.serialize(aCas, docOS, true); // true = formatted output
 break;
case SERIALIZED:

代码示例来源:origin: com.github.lafa.tikaNoExternal/tika-parsers

/**
 * 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
 *            {@see 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);
  }
}

代码示例来源:origin: org.apache.uima/uimaj-cpe

/**
  * Convert CAS Container (aka CAS Object) to CAS Data
  * 
  * @param aContainer
  *          CAS to convert
  * 
  * @return CasData object containing all information from the CAS
  */
 public CasData casContainerToCasData(CAS aContainer) {
  // generate XCAS events and pipe them to XCasToCasDataSaxHandler
  CasData result = new CasDataImpl();
  XCasToCasDataSaxHandler handler = new XCasToCasDataSaxHandler(result);
  XCASSerializer xcasSer = new XCASSerializer(aContainer.getTypeSystem());
  xcasSer.setDocumentTypeName(this.getDocumentTextTypeName());
  xcasSer.setDocumentTextFeature(this.getDocumentTextFeatureName());
  try {
   xcasSer.serialize(aContainer, handler);
  } catch (IOException e) {
   throw new UIMARuntimeException(e);
  } catch (SAXException e) {
   throw new UIMARuntimeException(e);
  }
  return result;
 }
}

代码示例来源:origin: apache/uima-uimaj

XTalkSerializer s = new XTalkSerializer(os, xcasSerializer);
try {
 xcasSerializer.serialize(myCas, s, includeDocText, outOfTypeSystemData);
} catch (org.xml.sax.SAXException e) {

相关文章