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 (mTEXT) {
      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) {
        jcas.setDocumentLanguage(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 {
        if (mXCAS.equalsIgnoreCase("xmi")) {
          XmiCasDeserializer.deserialize(fis, aCAS, lenient);
        }
        else {
          XCASDeserializer.deserialize(fis, aCAS, lenient);
        }
      } catch (SAXException e) {
        UIMAFramework.getLogger(FileSystemCollectionReader.class).log(Level.WARNING,
                "Problem with XML input file: " + file.getAbsolutePath());
        throw new CollectionException(e);
      } finally {
        fis.close();
      }
    }
  }
View Full Code Here


  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++);
    String text = FileUtils.file2String(file, mEncoding);
View Full Code Here

  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 (mTEXT) {
      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) {
        jcas.setDocumentLanguage(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 {
        if (mXCAS.equalsIgnoreCase("xmi")) {
          XmiCasDeserializer.deserialize(fis, aCAS, lenient);
        }
        else {
          XCASDeserializer.deserialize(fis, aCAS, lenient);
        }
      } catch (SAXException e) {
        UIMAFramework.getLogger(FileSystemCollectionReader.class).log(Level.WARNING,
                "Problem with XML input file: " + file.getAbsolutePath());
        throw new CollectionException(e);
      } finally {
        fis.close();
      }
    }
  }
View Full Code Here

    }
    generator.setContentHandler(xcasDeser.getXCASHandler(aContainer, ootsd));
    try {
      generator.generateXCas(aData);
    } catch (Exception e) {
      throw new CollectionException(e);
    }
  }
View Full Code Here

      logger.log(LOG_LEVEL, "the function " + functionName
              + " is trying to throw the following exception: " + functionError);
      if (functionError.equals("IOException")) {
        throw new IOException();
      } else if (functionError.equals("CollectionException")) {
        throw new CollectionException();
      } else {
        throwAnException(functionError);
      }
    }
  }
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

        XmiCasDeserializer.deserialize(inputStream, cas);
      } else {
        XCASDeserializer.deserialize(inputStream, cas);
      }
    } catch (SAXException e) {
      throw new CollectionException(e);
    } finally {
      inputStream.close();
    }

    inputStream.close();
View Full Code Here

  public void getNext(JCas jCas) throws IOException, CollectionException {
    FileInputStream inputStream = new FileInputStream(this.filesIter.next());
    try {
      XmiCasDeserializer.deserialize(new BufferedInputStream(inputStream), jCas.getCas());
    } catch (SAXException e) {
      throw new CollectionException(e);
    }
    inputStream.close();
    this.completed += 1;
  }
View Full Code Here

  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++);
    String text = FileUtils.file2String(file, mEncoding);
View Full Code Here

      logger.log(LOG_LEVEL, "the function " + functionName
              + " is trying to throw the following exception: " + functionError);
      if (functionError.equals("IOException")) {
        throw new IOException();
      } else if (functionError.equals("CollectionException")) {
        throw new CollectionException();
      } else {
        throwAnException(functionError);
      }
    }
  }
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.