Package org.apache.uima.fit.type

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


                    jCas,
                    text,
                    "What if we built a rocket ship made of cheese ? \n We could fly it to the moon for repairs .",
                    "A B C D E F G H I J K L M N O P Q R S T U");

    Token token = JCasUtil.selectByIndex(jCas, Token.class, 10);
    testToken(token, "?", 45, 46, "K", null);
    token = JCasUtil.selectByIndex(jCas, Token.class, 11);
    testToken(token, "We", 48, 50, "L", null);

    jCas.reset();
View Full Code Here


    String text = "If you like line writer, then you should really check out line rider.";
    tokenBuilder.buildTokens(jCas, text);

    FSIndex<Annotation> tokenIndex = jCas.getAnnotationIndex(Token.type);
    assertEquals(13, tokenIndex.size());
    Token token = JCasUtil.selectByIndex(jCas, Token.class, 0);
    testToken(token, "If", 0, 2, null, null);
    token = JCasUtil.selectByIndex(jCas, Token.class, 12);
    testToken(token, "rider.", 63, 69, null, null);
    FSIndex<Annotation> sentenceIndex = jCas.getAnnotationIndex(Sentence.type);
    assertEquals(1, sentenceIndex.size());
View Full Code Here

    String text = "Me and all my friends are non-conformists.";
    tokenBuilder.buildTokens(jCas, text, "Me and all my friends are non - conformists .",
            "M A A M F A N - C .", "me and all my friend are non - conformist .");

    assertEquals("Me and all my friends are non-conformists.", jCas.getDocumentText());
    Token friendToken = JCasUtil.selectByIndex(jCas, Token.class, 4);
    assertEquals("friends", friendToken.getCoveredText());
    assertEquals("F", friendToken.getPos());
    assertEquals("friend", friendToken.getStem());
  }
View Full Code Here

  public void test5() throws Exception {
    JCas myView = jCas.createView("MyView");

    tokenBuilder.buildTokens(myView, "red and blue cars and tipsy motorcycles");

    Token token = JCasUtil.selectByIndex(myView, Token.class, 6);
    assertEquals("motorcycles", token.getCoveredText());

  }
View Full Code Here

    new Sentence(jCas, 48, 77).addToIndexes();
    new Sentence(jCas, 65, 82).addToIndexes();
    new Sentence(jCas, 68, 80).addToIndexes();
    new Sentence(jCas, 72, 65).addToIndexes();

    new Token(jCas, 73, 96).addToIndexes();

    for (Token t : select(jCas, Token.class)) {
      // The naive approach is assumed to be correct
      List<Sentence> stem1 = selectCovered(jCas, Sentence.class, t.getBegin(), t.getEnd());
      List<Sentence> stem2 = selectCovered(jCas, Sentence.class, t);
View Full Code Here

  /**
   * Test what happens if there is actually nothing overlapping with the Token.
   */
  @Test
  public void testSelectBetweenInclusion() {
    Token t1 = new Token(jCas, 45, 57);
    t1.addToIndexes();
    Token t2 = new Token(jCas, 52, 52);
    t2.addToIndexes();

    new Sentence(jCas, 52, 52).addToIndexes();

    List<Sentence> stem1 = selectBetween(jCas, Sentence.class, t1, t2);
    assertTrue(stem1.isEmpty());
View Full Code Here

      List<Token> tokens = new ArrayList<Token>(select(jcas, Token.class));

      long timeNaive = 0;
      long timeOptimized = 0;
      for (int j = 0; j < ITERATIONS; j++) {
        Token t1 = tokens.get(rnd.nextInt(tokens.size()));
        Token t2 = tokens.get(rnd.nextInt(tokens.size()));

        int left = Math.min(t1.getEnd(), t2.getEnd());
        int right = Math.max(t1.getBegin(), t2.getBegin());

        long ti;
        List<Sentence> reference;
        if ((t1.getBegin() < t2.getBegin() && t2.getBegin() < t1.getEnd())
                || (t1.getBegin() < t2.getEnd() && t2.getEnd() < t1.getEnd())
                || (t2.getBegin() < t1.getBegin() && t1.getBegin() < t2.getEnd())
                || (t2.getBegin() < t1.getEnd() && t1.getEnd() < t2.getEnd())) {
          // If the boundary annotations overlap, the result must be empty
          ti = System.currentTimeMillis();
          reference = new ArrayList<Sentence>();
          timeNaive += System.currentTimeMillis() - ti;
        } else {
View Full Code Here

      System.out.println(a.getClass().getSimpleName() + " " + a.getBegin() + " " + a.getEnd());
    }
  }

  private Token add(JCas jcas, int begin, int end) {
    Token t = new Token(jcas, begin, end);
    t.addToIndexes();
    new Sentence(jcas, begin, end).addToIndexes();
    return t;
  }
View Full Code Here

  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

  }

  @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

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.