Package org.apache.uima.fit.type

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


    // Index should be added the descriptor and thus end up in the CAS generated from the
    // analysis engine.
    AnalysisEngine desc = createEngine(IndexTestComponent.class);
    JCas jcas = desc.newJCas();

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

    // index1 is a sorted index, so when adding a token twice, both remain in the index
    Token token2 = new Token(jcas, 3, 4);
    token2.addToIndexes();
    token2.addToIndexes();

    Sentence sentence1 = new Sentence(jcas, 1, 2);
    sentence1.addToIndexes();

    // index2 is a set index, so even when adding a sentence twice, only one remains in the index
View Full Code Here


    JCasIterator jCasIterator = new JCasIterator(reader);
    jCas = jCasIterator.next();
    assertNotNull(jCas);
    assertEquals("Me and all my friends are non-conformists.", jCas.getDocumentText());
    Token token = JCasUtil.selectByIndex(jCas, Token.class, 2);
    assertEquals("all", token.getCoveredText());
    assertEquals("A", token.getPos());
    assertEquals("all", token.getStem());

    reader = CollectionReaderFactory.createReader(
            "org.apache.uima.fit.factory.testCrs.SingleFileXReader",
            SingleFileXReader.PARAM_FILE_NAME, "src/test/resources/data/docs/test.xmi",
            SingleFileXReader.PARAM_XML_SCHEME, SingleFileXReader.XMI);

    jCasIterator = new JCasIterator(reader, typeSystemDescription);
    jCas = jCasIterator.next();
    assertNotNull(jCas);
    assertEquals("Me and all my friends are non-conformists.", jCas.getDocumentText());
    token = JCasUtil.selectByIndex(jCas, Token.class, 9);
    assertEquals(".", token.getCoveredText());
    assertEquals(".", token.getPos());
    assertEquals(".", token.getStem());

    reader = CollectionReaderFactory.createReaderFromPath(
            "src/test/resources/org/apache/uima/fit/factory/testCrs/SingleFileXReader.xml",
            SingleFileXReader.PARAM_FILE_NAME, "src/test/resources/data/docs/test.xmi",
            SingleFileXReader.PARAM_XML_SCHEME, SingleFileXReader.XMI);

    jCasIterator = new JCasIterator(reader, typeSystemDescription);
    jCas = jCasIterator.next();
    assertNotNull(jCas);
    assertEquals("Me and all my friends are non-conformists.", jCas.getDocumentText());
    token = JCasUtil.selectByIndex(jCas, Token.class, 4);
    assertEquals("friends", token.getCoveredText());
    assertEquals("F", token.getPos());
    assertEquals("friend", token.getStem());

  }
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

                    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

  public void testSelectSingleRelative() throws UIMAException {
    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

  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

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.