Package org.apache.uima.collection

Examples of org.apache.uima.collection.CollectionException


  public void getNext(CAS aCAS) throws IOException, CollectionException {
    JCas jcas;
    try {
      jcas = aCAS.getJCas();
    } catch (CASException e) {
      throw new CollectionException(e);
    }

    // open input stream to file
    File file = (File) mFiles.get(mCurrentIndex++);
    FileInputStream fis = new FileInputStream(file);
    if (!mXCAS) {
      try {
        // if there's a CAS Initializer, call it
        if (getCasInitializer() != null) {
          getCasInitializer().initializeCas(fis, aCAS);
        } else // No CAS Initiliazer, so read file and set document text ourselves
        {
          String text = FileUtils.file2String(file, mEncoding);     
          // put document text in JCas
          jcas.setDocumentText(text);
        }
      } finally {
        if (fis != null)
          fis.close();
      }

      // set language if it was explicitly specified as a configuration parameter
      if (mLanguage != null) {
        ((DocumentAnnotation) jcas.getDocumentAnnotationFs()).setLanguage(mLanguage);
      }

      // Also store location of source document in CAS. This information is critical
      // if CAS Consumers will need to know where the original document contents are located.
      // For example, the Semantic Search CAS Indexer writes this information into the
      // search index that it creates, which allows applications that use the search index to
      // locate the documents that satisfy their semantic queries.
      SourceDocumentInformation srcDocInfo = new SourceDocumentInformation(jcas);
      srcDocInfo.setUri(file.getAbsoluteFile().toURL().toString());
      srcDocInfo.setOffsetInSource(0);
      srcDocInfo.setDocumentSize((int) file.length());
      srcDocInfo.setLastSegment(mCurrentIndex == mFiles.size());
      srcDocInfo.addToIndexes();
    }
    // XCAS input files
    else {
      try {
        XCASDeserializer.deserialize(fis, aCAS);
      } catch (SAXException e) {
        throw new CollectionException(e);
      } finally {
        fis.close();
      }
    }
  }
View Full Code Here


  // This method should not be overwritten. Overwrite getNext(JCas) instead.
  public final void getNext(final CAS cas) throws IOException, CollectionException {
    try {
      getNext(cas.getJCas());
    } catch (CASException e) {
      throw new CollectionException(e);
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.uima.collection.CollectionException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.