org.apache.uima.cas.impl.XCASSerializer类的使用及代码示例

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

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

XCASSerializer介绍

[英]XCAS serializer. Create a serializer from a type system, then encode individual CASes by writing to a SAX content handler. This class is thread safe.
[中]XCAS序列化程序。从类型系统中创建一个序列化程序,然后通过写入SAX内容处理程序对单个案例进行编码。这个类是线程安全的。

代码示例

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

  1. private void writeXCas(CAS aCas, String fileName) throws IOException, SAXException {
  2. File outFile = new File(outputDirectory, fileName + ".xcas");
  3. FileOutputStream out = null;
  4. try {
  5. out = new FileOutputStream(outFile);
  6. XCASSerializer ser = new XCASSerializer(aCas.getTypeSystem());
  7. XMLSerializer xmlSer = new XMLSerializer(out, false);
  8. ser.serialize(aCas, xmlSer.getContentHandler());
  9. }
  10. finally {
  11. if (out != null) {
  12. out.close();
  13. }
  14. }
  15. }

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

  1. /**
  2. * Write the CAS data to a SAX content handler.
  3. *
  4. * @param cas
  5. * The CAS to be serialized.
  6. * @param contentHandler
  7. * The SAX content handler the data is written to.
  8. * @throws IOException passed thru
  9. * @throws SAXException passed thru
  10. */
  11. public void serialize(CAS cas, ContentHandler contentHandler) throws IOException, SAXException {
  12. serialize(cas, contentHandler, true);
  13. }

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

  1. /**
  2. * Convert CAS Container (aka CAS Object) to CAS Data
  3. *
  4. * @param aContainer
  5. * CAS to convert
  6. *
  7. * @return CasData object containing all information from the CAS
  8. */
  9. public CasData casContainerToCasData(CAS aContainer) {
  10. // generate XCAS events and pipe them to XCasToCasDataSaxHandler
  11. CasData result = new CasDataImpl();
  12. XCasToCasDataSaxHandler handler = new XCasToCasDataSaxHandler(result);
  13. XCASSerializer xcasSer = new XCASSerializer(aContainer.getTypeSystem());
  14. xcasSer.setDocumentTypeName(this.getDocumentTextTypeName());
  15. xcasSer.setDocumentTextFeature(this.getDocumentTextFeatureName());
  16. try {
  17. xcasSer.serialize(aContainer, handler);
  18. } catch (IOException e) {
  19. throw new UIMARuntimeException(e);
  20. } catch (SAXException e) {
  21. throw new UIMARuntimeException(e);
  22. }
  23. return result;
  24. }
  25. }

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

  1. /**
  2. * Serializes an XCAS to a stream.
  3. *
  4. * @param aCAS
  5. * CAS to serialize.
  6. * @param aStream
  7. * output stream to which to write the XCAS XML document
  8. *
  9. * @throws SAXException
  10. * if a problem occurs during XCAS serialization
  11. * @throws IOException
  12. * if an I/O failure occurs
  13. */
  14. public static void serialize(CAS aCAS, OutputStream aStream) throws SAXException, IOException {
  15. XCASSerializer.serialize(aCAS, aStream, false);
  16. }

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

  1. try {
  2. UIMAFramework.getLogger().log(Level.FINEST, "Serializing CAS.");
  3. XCASSerializer xcasSerializer = new XCASSerializer(myCas.getTypeSystem(), this.uimaContext);
  4. xcasSerializer.setDocumentTypeName(Constants.VINCI_DETAG);
  5. xcasSerializer.setDocumentTextFeature(null);
  6. XTalkSerializer s = new XTalkSerializer(os, xcasSerializer);
  7. try {
  8. xcasSerializer.serialize(myCas, s, includeDocText, outOfTypeSystemData);
  9. } catch (org.xml.sax.SAXException e) {

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

  1. private void writeXCas(CAS aCas, String fileName) throws IOException, SAXException {
  2. File outFile = new File(outputDirectory, fileName + ".xcas");
  3. FileOutputStream out = null;
  4. try {
  5. out = new FileOutputStream(outFile);
  6. XCASSerializer ser = new XCASSerializer(aCas.getTypeSystem());
  7. XMLSerializer xmlSer = new XMLSerializer(out, false);
  8. ser.serialize(aCas, xmlSer.getContentHandler());
  9. }
  10. finally {
  11. if (out != null) {
  12. out.close();
  13. }
  14. }
  15. }

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

  1. /**
  2. * Serializes a CAS in the given format.
  3. *
  4. * @param jcas
  5. * CAS (Common Analysis System) to be serialized.
  6. * @param type
  7. * type of cTAKES (UIMA) serializer used to write CAS.
  8. * @param prettyPrint
  9. * {@code true} to do pretty printing of output.
  10. * @param stream
  11. * {@link OutputStream} object used to print out information
  12. * extracted by using cTAKES.
  13. * @throws SAXException
  14. * if there was a SAX exception.
  15. * @throws IOException
  16. * if any I/O error occurs.
  17. */
  18. public static void serialize(JCas jcas, CTAKESSerializer type, boolean prettyPrint,
  19. OutputStream stream) throws SAXException, IOException {
  20. if (type == CTAKESSerializer.XCAS) {
  21. XCASSerializer.serialize(jcas.getCas(), stream, prettyPrint);
  22. } else if (type == CTAKESSerializer.XMI) {
  23. XmiCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(),
  24. stream, prettyPrint, new XmiSerializationSharedData());
  25. } else {
  26. XmlCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(),
  27. stream);
  28. }
  29. }

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

  1. /**
  2. * Returns XML (XCAS) representation of this CAS, stripped of all newlines.
  3. */
  4. @Override
  5. public String toString()
  6. {
  7. if (cas == null)
  8. return "null";
  9. // Use StringWriter instead of OutputStream for XMLSerializer so that
  10. // we don't need to worry about string encoding (utf-8 vs. utf-16, etc.)
  11. StringWriter writer = new StringWriter();
  12. XMLSerializer xmlSerializer = new XMLSerializer(writer);
  13. XCASSerializer casSerializer = new XCASSerializer(cas.getTypeSystem());
  14. try {
  15. casSerializer.serialize(cas, xmlSerializer.getContentHandler());
  16. }
  17. catch (SAXException e) {
  18. e.printStackTrace();
  19. }
  20. catch (IOException e) {
  21. e.printStackTrace();
  22. }
  23. String xml = writer.toString();
  24. xml = xml.replace("\n", "");
  25. return xml;
  26. }

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

  1. /**
  2. * Write the CAS data to a SAX content handler.
  3. *
  4. * @param cas
  5. * The CAS to be serialized.
  6. * @param contentHandler
  7. * The SAX content handler the data is written to.
  8. * @param encodeDoc
  9. * If set to false, no uima.tcas.Document structure will be created, and the document
  10. * text will not be serialized.
  11. * @throws IOException passed thru
  12. * @throws SAXException passed thru
  13. */
  14. public void serialize(CAS cas, ContentHandler contentHandler, boolean encodeDoc)
  15. throws IOException, SAXException {
  16. serialize(cas, contentHandler, encodeDoc, null);
  17. }

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

  1. /**
  2. * Serialize a CAS to a file in XCAS format
  3. *
  4. * @param aCas
  5. * CAS to serialize
  6. * @param name
  7. * output file
  8. *
  9. * @throws IOException
  10. * if an I/O failure occurs
  11. * @throws SAXException
  12. * if an error occurs generating the XML text
  13. */
  14. private void writeXCas(CAS aCas, File name) throws IOException, SAXException {
  15. FileOutputStream out = null;
  16. try {
  17. out = new FileOutputStream(name);
  18. XCASSerializer ser = new XCASSerializer(aCas.getTypeSystem());
  19. XMLSerializer sax2xml = new XMLSerializer(out, false);
  20. ser.serialize(aCas, sax2xml.getContentHandler());
  21. } finally {
  22. if (out != null) {
  23. out.close();
  24. }
  25. }
  26. }

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

  1. /**
  2. *
  3. * @param aCas
  4. * the source CAS
  5. * @param aFile
  6. * the file to write to
  7. * @throws IOException
  8. * if there is a problem writing the file
  9. * @deprecated Use {@link CasIOUtils#save(CAS, OutputStream, org.apache.uima.cas.SerialFormat)}
  10. * with {@link SerialFormat#XCAS} instead.
  11. */
  12. @Deprecated
  13. public static void writeXCas(CAS aCas, File aFile) throws IOException {
  14. OutputStream os = null;
  15. try {
  16. os = new FileOutputStream(aFile);
  17. XCASSerializer.serialize(aCas, os);
  18. } catch (SAXException e) {
  19. IOException ioe = new IOException(e.getMessage());
  20. ioe.initCause(e);
  21. throw ioe; // NOPMD
  22. // If we were using Java 1.6 and add the wrapped exception to the IOException
  23. // constructor, we would not get a warning here
  24. } finally {
  25. closeQuietly(os);
  26. }
  27. }

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

  1. /**
  2. * Serializes an XCAS to a stream.
  3. *
  4. * @param aCAS
  5. * CAS to serialize.
  6. * @param aStream
  7. * output stream to which to write the XCAS XML document
  8. * @param isFormattedOutput
  9. * if true the XCAS will be serialized formatted
  10. *
  11. * @throws SAXException
  12. * if a problem occurs during XCAS serialization
  13. * @throws IOException
  14. * if an I/O failure occurs
  15. */
  16. public static void serialize(CAS aCAS, OutputStream aStream, boolean isFormattedOutput)
  17. throws SAXException, IOException {
  18. XCASSerializer xcasSerializer = new XCASSerializer(aCAS.getTypeSystem());
  19. XMLSerializer sax2xml = new XMLSerializer(aStream, isFormattedOutput);
  20. xcasSerializer.serialize(aCAS, sax2xml.getContentHandler());
  21. }

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

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

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

  1. OutputStream outStream = new BufferedOutputStream(new FileOutputStream(xcasFile));
  2. XMLSerializer xmlSerializer = new XMLSerializer(outStream);
  3. XCASSerializer xcasSerializer = new XCASSerializer(this.main.getCas().getTypeSystem());
  4. xcasSerializer.serialize(this.main.getCas(), xmlSerializer.getContentHandler());
  5. outStream.close();
  6. } catch (IOException e) {

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

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

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

  1. XMLSerializer xmlSer = new XMLSerializer(outStream, false);
  2. if (mXCAS.equalsIgnoreCase("xcas")) {
  3. XCASSerializer ser = new XCASSerializer(aCAS.getTypeSystem());
  4. ser.serialize(aCAS, xmlSer.getContentHandler());

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

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

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

  1. /**
  2. * Serializes a CAS in the given format.
  3. *
  4. * @param jcas
  5. * CAS (Common Analysis System) to be serialized.
  6. * @param type
  7. * type of cTAKES (UIMA) serializer used to write CAS.
  8. * @param prettyPrint
  9. * {@code true} to do pretty printing of output.
  10. * @param stream
  11. * {@link OutputStream} object used to print out information
  12. * extracted by using cTAKES.
  13. * @throws SAXException
  14. * if there was a SAX exception.
  15. * @throws IOException
  16. * if any I/O error occurs.
  17. */
  18. public static void serialize(JCas jcas, CTAKESSerializer type, boolean prettyPrint,
  19. OutputStream stream) throws SAXException, IOException {
  20. if (type == CTAKESSerializer.XCAS) {
  21. XCASSerializer.serialize(jcas.getCas(), stream, prettyPrint);
  22. } else if (type == CTAKESSerializer.XMI) {
  23. XmiCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(),
  24. stream, prettyPrint, new XmiSerializationSharedData());
  25. } else {
  26. XmlCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(),
  27. stream);
  28. }
  29. }

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

  1. break;
  2. case XCAS:
  3. XCASSerializer.serialize(aCas, docOS, true); // true = formatted output
  4. break;
  5. case SERIALIZED:

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

  1. /**
  2. * Serializes a CAS in the given format.
  3. *
  4. * @param jcas
  5. * CAS (Common Analysis System) to be serialized.
  6. * @param type
  7. * type of cTAKES (UIMA) serializer used to write CAS.
  8. * @param prettyPrint
  9. * {@code true} to do pretty printing of output.
  10. * @param stream
  11. * {@see OutputStream} object used to print out information
  12. * extracted by using cTAKES.
  13. * @throws SAXException
  14. * if there was a SAX exception.
  15. * @throws IOException
  16. * if any I/O error occurs.
  17. */
  18. public static void serialize(JCas jcas, CTAKESSerializer type, boolean prettyPrint,
  19. OutputStream stream) throws SAXException, IOException {
  20. if (type == CTAKESSerializer.XCAS) {
  21. XCASSerializer.serialize(jcas.getCas(), stream, prettyPrint);
  22. } else if (type == CTAKESSerializer.XMI) {
  23. XmiCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(),
  24. stream, prettyPrint, new XmiSerializationSharedData());
  25. } else {
  26. XmlCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(),
  27. stream);
  28. }
  29. }

相关文章