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

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

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

XCASDeserializer介绍

[英]XCAS Deserializer. Takes an XCAS and reads it into a CAS.
[中]XCAS反序列化程序。获取XCAS并将其读入CAS。

代码示例

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

/**
 * Deserializes an XCAS from a stream. By default this is not lenient, meaning that if the XCAS
 * references Types that are not in the Type System, an Exception will be thrown. Use
 * {@link XCASDeserializer#deserialize(InputStream,CAS,boolean)} to turn on lenient mode and
 * ignore any unknown types.
 * 
 * @param aStream
 *          input stream from which to read the XCAS XML document
 * @param aCAS
 *          CAS into which to deserialize. This CAS must be set up with a type system that is
 *          compatible with that in the XCAS
 * 
 * @throws SAXException
 *           if an XML Parsing error occurs
 * @throws IOException
 *           if an I/O failure occurs
 */
public static void deserialize(InputStream aStream, CAS aCAS) throws SAXException, IOException {
 XCASDeserializer.deserialize(aStream, aCAS, false);
}

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

/**
 * Deserializes an XCAS from a stream.
 * 
 * @param aStream
 *          input stream from which to read the XCAS XML document
 * @param aCAS
 *          CAS into which to deserialize. This CAS must be set up with a type system that is
 *          compatible with that in the XCAS.
 * @param aLenient
 *          if true, unknown Types will be ignored. If false, unknown Types will cause an
 *          exception. The default is false.
 * 
 * @throws SAXException
 *           if an XML Parsing error occurs
 * @throws IOException
 *           if an I/O failure occurs
 */
public static void deserialize(InputStream aStream, CAS aCAS, boolean aLenient)
    throws SAXException, IOException {
 XMLReader xmlReader = XMLUtils.createXMLReader();
 XCASDeserializer deser = new XCASDeserializer(aCAS.getTypeSystem());
 ContentHandler handler;
 if (aLenient) {
  handler = deser.getXCASHandler(aCAS, new OutOfTypeSystemData());
 } else {
  handler = deser.getXCASHandler(aCAS);
 }
 xmlReader.setContentHandler(handler);
 xmlReader.parse(new InputSource(aStream));
}

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

XCASDeserializer deser = new XCASDeserializer(myCas.getTypeSystem(), this.uimaContext);
deser.setDocumentTypeName("Detag:DetagContent");
if (!ignoreResponse) {
 handler = deser.getXCASHandler(myCas, outOfTypeSystemData);
} else {
 handler = new DefaultHandler();

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

/**
 * Create a default handler for deserializing an XCAS into the <code>cas</code> parameter.
 * <p>
 * Warning: for efficiency reasons, the deserializer does not do much type checking for features
 * and their values. It is expected that the incoming XCAS conforms to the type system provided.
 * If it doesn't, the results are undefined.
 * 
 * @param cas
 *          This CAS will be used to hold the data of the serialized XCAS.
 * @return The <code>DefaultHandler</code> to pass to the SAX parser.
 */
public DefaultHandler getXCASHandler(CAS cas) {
 return getXCASHandler(cas, null);
}

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

if (qualifiedName.equals(getDocumentTypeName())) {
 readDocument(attrs);
} else {

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

public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException {
 if (mDelegateHandler == null) {
  // try to find out whether we should use the XCAS or XMI deserializers
  // if there's an xmi:version attribute, always use XMI
  String xmiVer = attributes.getValue("xmi:version");
  if (xmiVer != null && xmiVer.length() > 0) {
   XmiCasDeserializer deser = new XmiCasDeserializer(mCAS.getTypeSystem());
   mDelegateHandler = deser.getXmiCasHandler(mCAS, mLenient);
  } else if ("CAS".equals(localName)) // use XCAS
  {
   XCASDeserializer deser = new XCASDeserializer(mCAS.getTypeSystem());
   mDelegateHandler = deser
       .getXCASHandler(mCAS, mLenient ? new OutOfTypeSystemData() : null);
  } else // default to XMI
  {
   XmiCasDeserializer deser = new XmiCasDeserializer(mCAS.getTypeSystem());
   mDelegateHandler = deser.getXmiCasHandler(mCAS, mLenient);
  }
  mDelegateHandler.startDocument();
 }
 mDelegateHandler.startElement(uri, localName, qName, attributes);
}

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

@Override
public void readFields(DataInput in)
  throws IOException
{
  int dataLength = in.readInt();
  byte[] data = new byte[dataLength];
  in.readFully(data);
  String serializedCAS = new String(data, "UTF-8");
  try {
    XCASDeserializer.deserialize(new ByteArrayInputStream(serializedCAS.getBytes("UTF-8")),
        cas);
  }
  catch (SAXException e) {
    e.printStackTrace();
  }
}

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

generator.setDocumentTextTypeName(this.getDocumentTextTypeName());
generator.setDocumentTextFeatureName(this.getDocumentTextFeatureName());
XCASDeserializer xcasDeser = new XCASDeserializer(aContainer.getTypeSystem());
xcasDeser.setDocumentTypeName(this.getDocumentTextTypeName());
 ootsd = new OutOfTypeSystemData();
generator.setContentHandler(xcasDeser.getXCASHandler(aContainer, ootsd));
try {
 generator.generateXCas(aData);

代码示例来源:origin: org.apache.uima/uimaj-component-test-util

/**
* create a CAS object from the given XCAS and typesystem files.
*
* @param tsFile -
*           a typesystem file
* @param xcasFile -
*           a xcas file
* @return CAS - CAS object created from the given input data
* @throws Exception passthru
*/
public static CAS getCASfromXCAS(File tsFile, File xcasFile)
   throws Exception {
 try {
   Object tsDescriptor = UIMAFramework.getXMLParser().parse(
      new XMLInputSource(tsFile));
   TypeSystemDescription tsDesc = (TypeSystemDescription) tsDescriptor;
   CAS cas = CasCreationUtils.createCas(tsDesc, null,
      new FsIndexDescription[0]);
   SAXParser parser = XMLUtils.createSAXParserFactory().newSAXParser();
   XCASDeserializer xcasDeserializer = new XCASDeserializer(cas
      .getTypeSystem());
   parser.parse(xcasFile, xcasDeserializer.getXCASHandler(cas));
   return cas;
 } catch (Exception ex) {
   JUnitExtension.handleException(ex);
 }
 return null;
}

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

/**
 * @param aCas
 *          the target CAS
 * @param aFile
 *          the file to read from
 * @throws IOException
 *           if there is a problem reading the file
 * @deprecated Use {@link CasIOUtils#load(java.net.URL, CAS)} instead.
 */
@Deprecated
public static void readXCas(CAS aCas, File aFile) throws IOException {
 InputStream is = null;
 try {
  is = new FileInputStream(aFile);
  XCASDeserializer.deserialize(is, aCas);
 } 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(is);
 }
}

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

/**
* create a CAS object from the given XCAS and typesystem files
* 
* @param tsFile -
*           a typesystem file
* @param xcasFile -
*           a xcas file
* 
* @return CAS - CAS object created from the given input data
* @throws Exception passthru
*/
public static CAS getCASfromXCAS(File tsFile, File xcasFile)
   throws Exception {
 try {
   Object tsDescriptor = UIMAFramework.getXMLParser().parse(
      new XMLInputSource(tsFile));
   TypeSystemDescription tsDesc = (TypeSystemDescription) tsDescriptor;
   CAS cas = CasCreationUtils.createCas(tsDesc, null,
      new FsIndexDescription[0]);
   SAXParser parser = XMLUtils.createSAXParserFactory().newSAXParser();
   XCASDeserializer xcasDeserializer = new XCASDeserializer(cas
      .getTypeSystem());
   parser.parse(xcasFile, xcasDeserializer.getXCASHandler(cas));
   return cas;
 } catch (Exception ex) {
   JUnitExtension.handleException(ex);
 }
 return null;
}

代码示例来源:origin: ClearTK/cleartk

@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
 URI uri = ViewUriUtil.getURI(jCas);
 InputStream inputStream = null;
 try {
  inputStream = uri.toURL().openStream();
  switch (this.xmlScheme) {
   case XMI:
    XmiCasDeserializer.deserialize(inputStream, jCas.getCas());
    break;
   case XCAS:
    XCASDeserializer.deserialize(inputStream, jCas.getCas());
    break;
  }
  inputStream.close();
 } catch (Exception e) {
  throw new AnalysisEngineProcessException(e);
 }
}

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

SAXParserFactory saxParserFactory = XMLUtils.createSAXParserFactory();
SAXParser parser = saxParserFactory.newSAXParser();
XCASDeserializer xcasDeserializer = new XCASDeserializer(this.main.getCas()
  .getTypeSystem());
this.main.getCas().reset();
parser.parse(xcasFile, xcasDeserializer.getXCASHandler(this.main.getCas()));
time.stop();
this.main.handleSofas();

代码示例来源:origin: org.cleartk/cleartk-util

@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
 URI uri = ViewUriUtil.getURI(jCas);
 InputStream inputStream = null;
 try {
  inputStream = uri.toURL().openStream();
  switch (this.xmlScheme) {
   case XMI:
    XmiCasDeserializer.deserialize(inputStream, jCas.getCas());
    break;
   case XCAS:
    XCASDeserializer.deserialize(inputStream, jCas.getCas());
    break;
  }
  inputStream.close();
 } catch (Exception e) {
  throw new AnalysisEngineProcessException(e);
 }
}

代码示例来源:origin: ClearTK/cleartk

public void getNext(JCas jCas) throws IOException, CollectionException {
 if (!hasNext()) {
  throw new RuntimeException("getNext(jCas) was called but hasNext() returns false");
 }
 FileInputStream inputStream = new FileInputStream(currentFile);
 try {
  if (xmlScheme.equals(XMI))
   XmiCasDeserializer.deserialize(inputStream, jCas.getCas());
  else
   XCASDeserializer.deserialize(inputStream, jCas.getCas());
 } catch (SAXException e) {
  throw new CollectionException(e);
 } finally {
  inputStream.close();
 }
 completed++;
 currentFile = null;
}

代码示例来源:origin: org.cleartk/cleartk-util

public void getNext(JCas jCas) throws IOException, CollectionException {
 if (!hasNext()) {
  throw new RuntimeException("getNext(jCas) was called but hasNext() returns false");
 }
 FileInputStream inputStream = new FileInputStream(currentFile);
 try {
  if (xmlScheme.equals(XMI))
   XmiCasDeserializer.deserialize(inputStream, jCas.getCas());
  else
   XCASDeserializer.deserialize(inputStream, jCas.getCas());
 } catch (SAXException e) {
  throw new CollectionException(e);
 } finally {
  inputStream.close();
 }
 completed++;
 currentFile = null;
}

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

XCASDeserializer.deserialize(xCasStream, cas);
System.out.println("XCAS deserialized");

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

XCASDeserializer.deserialize(xCasStream, cas);
System.out.println("XCAS deserialized");

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

@Override
public void map(Text key, Text value, OutputCollector<Text, CASWritable> output,
    Reporter reporter)
  throws IOException
{
  try {
    CAS cas = CasCreationUtils.createCas(createTypeSystemDescription(), null, null);
    XCASDeserializer.deserialize(new StringInputStream(value.toString()), cas);
    // XCASDeserializer.deserialize(IOUtils.toInputStream(value.toString(), "utf8"), cas);
    CASWritable casWritable = new BinCasWithTypeSystemWritable();
    casWritable.setCAS(cas);
    output.collect(key, casWritable);
    reporter.incrCounter("hpz", "processed cas", 1);
    if (cas.getDocumentText() == null)
      reporter.incrCounter("hpz", "document text null", 1);
    else
      reporter.incrCounter("hpz", "doc size", cas.getDocumentText().length());
  }
  catch (Exception e) {
    reporter.incrCounter("hpz", "exception " + e.getMessage(), 1);
    e.printStackTrace(System.err);
  }
}

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

XCASDeserializer.deserialize(fis, aCAS, lenient);

相关文章