Package org.apache.uima.fit.type

Examples of org.apache.uima.fit.type.Token


  public void testSelectSingleRelative() {
    String text = "one two three";
    tokenBuilder.buildTokens(jCas, text);
    List<Token> token = new ArrayList<Token>(select(jCas, Token.class));

    Token preceding = selectSingleRelative(jCas, Token.class, token.get(1), -1);
    assertEquals(token.get(0).getCoveredText(), preceding.getCoveredText());

    Token following = selectSingleRelative(jCas, Token.class, token.get(1), 1);
    assertEquals(token.get(2).getCoveredText(), following.getCoveredText());
  }
View Full Code Here


   
    for (Token token : tokens) {
      new AnalyzedText(jCas, token.getBegin(), token.getEnd()).addToIndexes();
    }   
   
    Token lastToken = tokens.get(tokens.size()-1);
    Token preLastToken = tokens.get(tokens.size()-2);
    AnalyzedText a = selectSingleRelative(jCas, AnalyzedText.class, lastToken, -1);
    assertEquals(preLastToken.getBegin(), a.getBegin());
    assertEquals(preLastToken.getEnd(), a.getEnd());
  }
View Full Code Here

   
    for (Token token : tokens) {
      new AnalyzedText(jCas, token.getBegin(), token.getEnd()).addToIndexes();
    }   
   
    Token firstToken = tokens.get(0);
    Token secondToken = tokens.get(1);
    AnalyzedText a = selectSingleRelative(jCas, AnalyzedText.class, firstToken, 1);
    assertEquals(secondToken.getBegin(), a.getBegin());
    assertEquals(secondToken.getEnd(), a.getEnd());
  }
View Full Code Here

   
    for (Token token : tokens) {
      new AnalyzedText(jCas, token.getBegin(), token.getEnd()).addToIndexes();
    }   
   
    Token lastToken = tokens.get(tokens.size()-1);
    Token preLastToken = tokens.get(tokens.size()-2);
    AnalyzedText a = selectPreceding(jCas, AnalyzedText.class, lastToken, 1).get(0);
    assertEquals(preLastToken.getBegin(), a.getBegin());
    assertEquals(preLastToken.getEnd(), a.getEnd());
  }
View Full Code Here

   
    for (Token token : tokens) {
      new AnalyzedText(jCas, token.getBegin(), token.getEnd()).addToIndexes();
    }   
   
    Token firstToken = tokens.get(0);
    Token secondToken = tokens.get(1);
    AnalyzedText a = selectFollowing(jCas, AnalyzedText.class, firstToken, 1).get(0);
    assertEquals(secondToken.getBegin(), a.getBegin());
    assertEquals(secondToken.getEnd(), a.getEnd());
  }
View Full Code Here

  }

  @Test
  public void testSelectFollowingPrecedingDifferentTypes() {
    this.jCas.setDocumentText("A B C D E");
    Token a = new Token(this.jCas, 0, 1);
    Token b = new Token(this.jCas, 2, 3);
    Token c = new Token(this.jCas, 4, 5);
    Token d = new Token(this.jCas, 6, 7);
    Token e = new Token(this.jCas, 8, 9);
    for (Token token : Arrays.asList(a, b, c, d, e)) {
      token.addToIndexes();
    }
    Sentence sentence = new Sentence(this.jCas, 2, 5);
    sentence.addToIndexes();
View Full Code Here

  public void testExists() throws UIMAException {
    JCas jcas = CasCreationUtils.createCas(createTypeSystemDescription(), null, null).getJCas();

    assertFalse(exists(jcas, Token.class));

    new Token(jcas, 0, 1).addToIndexes();

    assertTrue(exists(jcas, Token.class));
  }
View Full Code Here

      fail("Found annotation that has not yet been created");
    } catch (IllegalArgumentException e) {
      // OK
    }

    new Token(jcas, 0, 1).addToIndexes();

    selectSingle(jcas, Token.class);

    new Token(jcas, 1, 2).addToIndexes();

    try {
      selectSingle(jcas, Token.class);
      fail("selectSingle must fail if there is more than one annotation of the type");
    } catch (IllegalArgumentException e) {
View Full Code Here

public class AnnotationFactoryTest extends ComponentTestBase {

  @Test
  public void testCreateAnnotation() {
    Token token = AnnotationFactory.createAnnotation(jCas, 0, 10, Token.class);
    assertEquals(0, token.getBegin());
    assertEquals(10, token.getEnd());

    Sentence sentence = AnnotationFactory.createAnnotation(jCas, 0, 10, Sentence.class);
    assertEquals(0, sentence.getBegin());
    assertEquals(10, sentence.getEnd());
  }
View Full Code Here

    sentence = (Sentence) sentences.next();
    assertEquals("We could fly it to the moon for repairs.", sentence.getCoveredText());

    FSIndex<Annotation> tokenIndex = jCas.getAnnotationIndex(Token.type);
    assertEquals(21, tokenIndex.size());
    Token token = JCasUtil.selectByIndex(jCas, Token.class, 0);
    testToken(token, "What", 0, 4, "A", null);
    token = JCasUtil.selectByIndex(jCas, Token.class, 1);
    testToken(token, "if", 5, 7, "B", null);
    token = JCasUtil.selectByIndex(jCas, Token.class, 9);
    testToken(token, "cheese", 39, 45, "J", null);
View Full Code Here

TOP

Related Classes of org.apache.uima.fit.type.Token

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.