Package org.apache.uima.cas.text

Examples of org.apache.uima.cas.text.AnnotationIndex


   * @throws UnsupportedEncodingException
   */
  private void printPosTags(JCas cas) throws UnsupportedEncodingException, IOException {
    Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
        "moby-tag-list.txt"), "utf-8"));
    AnnotationIndex tokenIndex = cas.getAnnotationIndex(TokenAnnotation.type);
    FSIterator tokIt = tokenIndex.iterator();
    TokenAnnotation token = null;
    for (tokIt.moveToFirst(); tokIt.isValid(); tokIt.moveToNext()) {
      token = (TokenAnnotation) tokIt.get();
      writer.write(token.getPosTag());
      writer.write('\n');
View Full Code Here


      ++annotCount;
      this.cas.getIndexRepository().addFS(this.cas.createAnnotation(this.sentenceType, i, i + 10));
    }

    int count;
    AnnotationIndex annotIndex = this.cas.getAnnotationIndex();
    FSIterator it = annotIndex.iterator(true);
    count = 0;
    while (it.isValid()) {
      ++count;
      it.moveToNext();
    }
    assertTrue(annotCount == count);
    // System.out.println("Size of ambiguous iterator: " + count);
    it = annotIndex.iterator(false);
    count = 0;
    while (it.isValid()) {
      ++count;
      it.moveToNext();
    }
    assertTrue(count == 1);
    // System.out.println("Size of unambiguous iterator: " + count);
    AnnotationFS bigAnnot = this.cas.createAnnotation(this.sentenceType, 10, 41);
    it = annotIndex.subiterator(bigAnnot, true, true);
    count = 0;
    while (it.isValid()) {
      ++count;
      // AnnotationFS a = (AnnotationFS) it.get();
      // System.out.println("Annotation from " + a.getBegin() + " to " + a.getEnd());
      it.moveToNext();
    }
    assertTrue(count == 32);
    count = 0;
    for (it.moveToLast(); it.isValid(); it.moveToPrevious()) {
      ++count;
    }
    assertTrue(count == 32);
    // System.out.println("Size of subiterator(true, true): " + count);
    it = annotIndex.subiterator(bigAnnot, false, true);
    count = 0;
    while (it.isValid()) {
      ++count;
      // AnnotationFS a = (AnnotationFS) it.get();
      // System.out.println("Annotation from " + a.getBegin() + " to " + a.getEnd());
      it.moveToNext();
    }
    assertTrue(count == 3);
    // System.out.println("Size of subiterator(false, true): " + count);
    count = 0;
    for (it.moveToLast(); it.isValid(); it.moveToPrevious()) {
      ++count;
    }
    assertTrue(count == 3);
    it = annotIndex.subiterator(bigAnnot, true, false);
    count = 0;
    while (it.isValid()) {
      ++count;
      // AnnotationFS a = (AnnotationFS) it.get();
      // System.out.println("Annotation from " + a.getBegin() + " to " + a.getEnd());
      it.moveToNext();
    }
    assertTrue(count == 39);
    // System.out.println("Size of subiterator(true, false): " + count);
    count = 0;
    for (it.moveToLast(); it.isValid(); it.moveToPrevious()) {
      ++count;
    }
    assertTrue(count == 39);
    it = annotIndex.subiterator(bigAnnot, false, false);
    count = 0;
    while (it.isValid()) {
      ++count;
      // AnnotationFS a = (AnnotationFS) it.get();
      // System.out.println("Annotation from " + a.getBegin() + " to " + a.getEnd());
      it.moveToNext();
    }
    assertTrue(count == 4);
    // System.out.println("Size of subiterator(false, false): " + count);
    count = 0;
    for (it.moveToLast(); it.isValid(); it.moveToPrevious()) {
      ++count;
    }
    assertTrue(count == 4);
    AnnotationFS sent = (AnnotationFS) this.cas.getAnnotationIndex(this.sentenceType).iterator().get();
    it = annotIndex.subiterator(sent, false, true);
    count = 0;
    while (it.isValid()) {
      ++count;
      // AnnotationFS a = (AnnotationFS) it.get();
      // System.out.println("Annotation from " + a.getBegin() + " to " + a.getEnd());
View Full Code Here

     
        iv_logger.info("process(JCas)");

      JFSIndexRepository indexes = jcas.getJFSIndexRepository();
      Iterator<?> sentItr = indexes.getAnnotationIndex(Sentence.type).iterator();
      AnnotationIndex baseTokenIndex = jcas.getJFSIndexRepository().getAnnotationIndex(
          org.apache.ctakes.typesystem.type.syntax.BaseToken.type);
     
      while (sentItr.hasNext()) {
        Sentence sentAnnot = (Sentence) sentItr.next();
        FSIterator btaItr = baseTokenIndex.subiterator(sentAnnot);

        // adapt JCas objects into objects expected by the Finite state
        // machines
        List<BaseToken> baseTokenList = new ArrayList<BaseToken>();
        while (btaItr.hasNext()) {
View Full Code Here

    ArrayList wordList = new ArrayList();
    StringBuffer sentenceBuffer = new StringBuffer();
    offsetMap.clear();

    AnnotationIndex sentenceIndex = aJCas.getAnnotationIndex(Sentence.type);
    AnnotationIndex tokenIndex = aJCas.getAnnotationIndex(Token.type);

    // iterate over Sentences
    FSIterator sentenceIterator = sentenceIndex.iterator();
    while (sentenceIterator.hasNext()) {
      Sentence sentence = (Sentence) sentenceIterator.next();

      wordList.clear();
      sentenceBuffer.setLength(0);

      int mapIdx = 0;

      // iterate over Tokens
      FSIterator tokenIterator = tokenIndex.subiterator(sentence);
      while (tokenIterator.hasNext()) {
        Token token = (Token) tokenIterator.next();

        String word = escapeToken(token.getCoveredText());
View Full Code Here

   *
   * @see JCasAnnotator_ImplBase#process(JCas)
   */
  public void process(JCas aJCas) throws AnalysisEngineProcessException {

    AnnotationIndex sentenceIndex = aJCas.getAnnotationIndex(Sentence.type);

    // iterate over Sentences
    FSIterator sentenceIterator = sentenceIndex.iterator();
    while (sentenceIterator.hasNext()) {
      Sentence sentence = (Sentence) sentenceIterator.next();

      String text = sentence.getCoveredText();
      Span[] tokenSpans = tokenizer.tokenizePos(text);
View Full Code Here

    ArrayList tokenList = new ArrayList();
    ArrayList wordList = new ArrayList();
    List finderTags;

    AnnotationIndex sentenceIndex = aJCas.getAnnotationIndex(Sentence.type);
    AnnotationIndex tokenIndex = aJCas.getAnnotationIndex(Token.type);

    // iterate over Sentences
    FSIterator sentenceIterator = sentenceIndex.iterator();
    while (sentenceIterator.hasNext()) {
      Sentence sentence = (Sentence) sentenceIterator.next();

      tokenList.clear();
      wordList.clear();

      // iterate over Tokens
      FSIterator tokenIterator = tokenIndex.subiterator(sentence);
      while (tokenIterator.hasNext()) {
        Token token = (Token) tokenIterator.next();

        tokenList.add(token);
        wordList.add(token.getCoveredText());
View Full Code Here

  public void process(JCas aJCas) throws AnalysisEngineProcessException {

    ArrayList tokenList = new ArrayList();
    ArrayList wordList = new ArrayList();

    AnnotationIndex sentenceIndex = aJCas.getAnnotationIndex(Sentence.type);
    AnnotationIndex tokenIndex = aJCas.getAnnotationIndex(Token.type);

    // iterate over Sentences
    FSIterator sentenceIterator = sentenceIndex.iterator();
    while (sentenceIterator.hasNext()) {
      Sentence sentence = (Sentence) sentenceIterator.next();

      tokenList.clear();
      wordList.clear();

      // iterate over Tokens
      FSIterator tokenIterator = tokenIndex.subiterator(sentence);
      while (tokenIterator.hasNext()) {
        Token token = (Token) tokenIterator.next();

        tokenList.add(token);
        wordList.add(token.getCoveredText());
View Full Code Here

      assertTrue(false);
    }
    jcas.setDocumentText(text);
    try {
      this.ae.process(jcas);
      AnnotationIndex tokenIndex = jcas.getAnnotationIndex(jcas.getCasType(Token.type));
      AnnotationFS sentence = (AnnotationFS) jcas.getAnnotationIndex(jcas.getCasType(Sentence.type)).iterator().next();
      FSIterator tokenIterator = tokenIndex.subiterator(sentence);
      AnnotationFS token = (AnnotationFS) tokenIndex.iterator().next();
      tokenIterator.moveTo(token); //throws ClassCastException   
    } catch (AnalysisEngineProcessException e) {
      e.printStackTrace();
      assertTrue(false);
    } catch (ClassCastException e) {
View Full Code Here

    logger.info("process(JCas)");

    List<BaseToken> tokens = new ArrayList<BaseToken>();
    List<String> words = new ArrayList<String>();

    AnnotationIndex baseTokenIndex = jCas.getAnnotationIndex(BaseToken.type);

    FSIterator sentences = jCas.getAnnotationIndex(Sentence.type).iterator();

    while (sentences.hasNext()) {
      Sentence sentence = (Sentence) sentences.next();

      tokens.clear();
      words.clear();

      FSIterator tokenIterator = baseTokenIndex.subiterator(sentence);
      while (tokenIterator.hasNext()) {
        BaseToken token = (BaseToken) tokenIterator.next();
        tokens.add(token);
        words.add(token.getCoveredText());
      }
View Full Code Here

      ++annotCount;
      this.cas.getIndexRepository().addFS(this.cas.createAnnotation(this.sentenceType, i, i + 10));
    }

    int count;
    AnnotationIndex annotIndex = this.cas.getAnnotationIndex();
    FSIterator it = annotIndex.iterator(true);
    count = 0;
    while (it.isValid()) {
      ++count;
      it.moveToNext();
    }
    assertTrue(annotCount == count);
    // System.out.println("Size of ambiguous iterator: " + count);
    it = annotIndex.iterator(false);
    count = 0;
    while (it.isValid()) {
      ++count;
      it.moveToNext();
    }
    assertTrue(count == 1);
    // System.out.println("Size of unambiguous iterator: " + count);
    AnnotationFS bigAnnot = this.cas.createAnnotation(this.sentenceType, 10, 41);
    it = annotIndex.subiterator(bigAnnot, true, true);
    count = 0;
    while (it.isValid()) {
      ++count;
      // AnnotationFS a = (AnnotationFS) it.get();
      // System.out.println("Annotation from " + a.getBegin() + " to " + a.getEnd());
      it.moveToNext();
    }
    assertTrue(count == 32);
    count = 0;
    for (it.moveToLast(); it.isValid(); it.moveToPrevious()) {
      ++count;
    }
    assertTrue(count == 32);
    // System.out.println("Size of subiterator(true, true): " + count);
    it = annotIndex.subiterator(bigAnnot, false, true);
    count = 0;
    while (it.isValid()) {
      ++count;
      // AnnotationFS a = (AnnotationFS) it.get();
      // System.out.println("Annotation from " + a.getBegin() + " to " + a.getEnd());
      it.moveToNext();
    }
    assertTrue(count == 3);
    // System.out.println("Size of subiterator(false, true): " + count);
    count = 0;
    for (it.moveToLast(); it.isValid(); it.moveToPrevious()) {
      ++count;
    }
    assertTrue(count == 3);
    it = annotIndex.subiterator(bigAnnot, true, false);
    count = 0;
    while (it.isValid()) {
      ++count;
      // AnnotationFS a = (AnnotationFS) it.get();
      // System.out.println("Annotation from " + a.getBegin() + " to " + a.getEnd());
      it.moveToNext();
    }
    assertTrue(count == 39);
    // System.out.println("Size of subiterator(true, false): " + count);
    count = 0;
    for (it.moveToLast(); it.isValid(); it.moveToPrevious()) {
      ++count;
    }
    assertTrue(count == 39);
    it = annotIndex.subiterator(bigAnnot, false, false);
    count = 0;
    while (it.isValid()) {
      ++count;
      // AnnotationFS a = (AnnotationFS) it.get();
      // System.out.println("Annotation from " + a.getBegin() + " to " + a.getEnd());
      it.moveToNext();
    }
    assertTrue(count == 4);
    // System.out.println("Size of subiterator(false, false): " + count);
    count = 0;
    for (it.moveToLast(); it.isValid(); it.moveToPrevious()) {
      ++count;
    }
    assertTrue(count == 4);
    AnnotationFS sent = (AnnotationFS) this.cas.getAnnotationIndex(this.sentenceType).iterator().get();
    it = annotIndex.subiterator(sent, false, true);
    count = 0;
    while (it.isValid()) {
      ++count;
      // AnnotationFS a = (AnnotationFS) it.get();
      // System.out.println("Annotation from " + a.getBegin() + " to " + a.getEnd());
View Full Code Here

TOP

Related Classes of org.apache.uima.cas.text.AnnotationIndex

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.