Package org.apache.uima.jcas

Examples of org.apache.uima.jcas.JCas


  }
 
  public void testIndexTwice() throws Exception {
    try {
      CAS newCas = CasCreationUtils.createCas(new TypeSystemDescription_impl(), null, null);
      JCas newJCas = newCas.getJCas();
      CAS view = newCas.createView("DetaggedView");
      view.getJCas();

      Annotation annot = new Annotation(newJCas);
      annot.addToIndexes();
     
      Iterator<Annotation> annotIter = newJCas.getAnnotationIndex(Annotation.type).iterator();
      Annotation annot2 = annotIter.next();
      assertEquals(annot, annot2);
      assertEquals(annot2.getSofa(), annot2.getCASImpl().getSofa());
     
      annot2.addToIndexes();
View Full Code Here


      TypeSystemDescription typeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription(
              new XMLInputSource(typeSystemFile));
      CAS newCas = CasCreationUtils.createCas(typeSystem, null, null);
      File xcasFile = JUnitExtension.getFile("ExampleCas/multiSofaCas.xml");
      XCASDeserializer.deserialize(new FileInputStream(xcasFile), newCas);
      JCas newJCas = newCas.getJCas();
     
      SofaID sofaId = new SofaID_impl("EnglishDocument");
      JCas view = newJCas.getView(newJCas.getSofa(sofaId));
    }
    catch (Exception e) {
      JUnitExtension.handleException(e);     
    }     
  }
View Full Code Here

      text = FileUtils.file2String(textFile, "utf-8");
    } catch (IOException e) {
      e.printStackTrace();
      assertTrue(false);
    }
    JCas jcas = null;
    try {
      jcas = this.ae.newJCas();
    } catch (ResourceInitializationException e) {
      e.printStackTrace();
      assertTrue(false);
    }
    jcas.setDocumentText(text);
    try {
      this.ae.process(jcas);
      AnnotationIndex<Annotation> tokenIndex = jcas.getAnnotationIndex(jcas.getCasType(Token.type));
      Annotation sentence = jcas.getAnnotationIndex(jcas.getCasType(Sentence.type)).iterator().next();
      FSIterator<Annotation> tokenIterator = tokenIndex.subiterator(sentence);
      Annotation token = tokenIndex.iterator().next();
      tokenIterator.moveTo(token); //throws ClassCastException   
      UnambiguousIteratorImpl<Annotation> it = new UnambiguousIteratorImpl<Annotation>(tokenIndex.iterator());
      it.moveTo(token);
View Full Code Here

    // entire document text. A better implementation might specify a maximum segment size as
    // well as a minimum.
    while (breakAt < mDoc.length() && mDoc.charAt(breakAt - 1) != '\n')
      breakAt++;

    JCas jcas = getEmptyJCas();
    try {
      jcas.setDocumentText(mDoc.substring(mPos, breakAt));
      // if original CAS had SourceDocumentInformation, also add SourceDocumentInformatio
      // to each segment
      if (mDocUri != null) {
        SourceDocumentInformation sdi = new SourceDocumentInformation(jcas);
        sdi.setUri(mDocUri);
        sdi.setOffsetInSource(mPos);
        sdi.setDocumentSize(breakAt - mPos);
        sdi.addToIndexes();

        if (breakAt == mDoc.length()) {
          sdi.setLastSegment(true);
        }
      }

      mPos = breakAt;
      return jcas;
    } catch (Exception e) {
      jcas.release();
      throw new AnalysisEngineProcessException(e);
    }
  }
View Full Code Here

   *           if there is an error in processing the Resource
   *
   * @see org.apache.uima.collection.base_cpm.CasObjectProcessor#processCas(org.apache.uima.cas.CAS)
   */
  public void processCas(CAS aCAS) throws ResourceProcessException {
    JCas jcas;
    try {
      jcas = aCAS.getJCas();
    } catch (CASException e) {
      throw new ResourceProcessException(e);
    }

    // retreive the filename of the input file from the CAS
    FSIterator it = jcas.getAnnotationIndex(SourceDocumentInformation.type).iterator();
    File outFile = null;
    if (it.hasNext()) {
      SourceDocumentInformation fileLoc = (SourceDocumentInformation) it.next();
      File inFile;
      try {
View Full Code Here

   *
   * @see org.apache.uima.analysis_component.AnalysisComponent#next()
   */
  public AbstractCas next() throws AnalysisEngineProcessException {
    // we should already have a JCas ready to return
    JCas toReturn = mJCases[mActiveJCas];
    mJCases[mActiveJCas] = null;
    assert toReturn != null;

    // now go read the next segment into our other JCas
    mActiveJCas ^= 1;
View Full Code Here

  public void testMissingFeatureInCas() throws Exception {
    try {
      // jcasCasMisMatch(CASTestSetup.BAD_MISSING_FEATURE_IN_CAS, CASException.JCAS_INIT_ERROR);
      CAS localCas;
      TypeSystem ts;
      JCas localJcas = null;
      boolean errFound = false;
      try {
        localCas = CASInitializer.initCas(new CASTestSetup(CASTestSetup.BAD_MISSING_FEATURE_IN_CAS));
        ts = this.cas.getTypeSystem();
        try {
View Full Code Here

  public void jcasCasMisMatch(int testId, String expectedErr) throws Exception {
    try {
      CAS localCas;
      TypeSystem ts;
      JCas localJcas;
      boolean errFound = false;
      try {
        localCas = CASInitializer.initCas(new CASTestSetup(testId));
        ts = this.cas.getTypeSystem();
        try {
View Full Code Here

  public void test2CASs() throws Exception {
    try {
      try {
        CAS cas2 = CASInitializer.initCas(new CASTestSetup());
        TypeSystem ts2 = cas2.getTypeSystem();
        JCas jcas2 = cas2.getJCas();
        assertTrue(jcas.getType(Annotation.type) != jcas2.getType(Annotation.type));
      } catch (Exception e) {
        checkOkMissingImport(e);
      }
    } catch (Exception e) {
      JUnitExtension.handleException(e);
View Full Code Here

    }
  }
 
  public void testUndefinedType() throws Exception {
    //create jcas with no type system
    JCas jcas = CasCreationUtils.createCas(new TypeSystemDescription_impl(), null, null).getJCas();
    jcas.setDocumentText("This is a test.");
    try {
      //this should throw an exception
      jcas.getType(Sentence.type);
      fail();
    } catch(CASRuntimeException e) {
    }
    //check that this does not leave JCAS in an inconsistent state
    //(a check for bug UIMA-738)
    Iterator<Annotation> iter = jcas.getAnnotationIndex().iterator();
    assertTrue(iter.hasNext());
    Annotation annot = iter.next();
    assertEquals("This is a test.", annot.getCoveredText());
  }
View Full Code Here

TOP

Related Classes of org.apache.uima.jcas.JCas

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.