Uploaded image for project: 'UIMA'
  1. UIMA
  2. UIMA-3403

selectPreceding() does not return preceding for last annotation

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0uimaFIT
    • Fix Version/s: 2.1.0uimaFIT
    • Component/s: uimaFIT
    • Labels:
      None

      Description

      selectPreceding() does not return the preceding element for the last element in the CAS if one is looking for a different annotation type than the anchor.
      See the test below.
      If the anchor is a token and I want the preceding tokens, everything is fine, but when I use a token anchor to get the preceding lemmas, no lemma is returned for the last token in the CAS.
      Offset are exactly the same so the behaviour is unexpected.

      @Test
          public void test() 
              throws Exception 
          {
              String testDocument = "This is a test document .\nIt is quite short .\n";
      
              AnalysisEngine engine = AnalysisEngineFactory.createEngine(NoOpAnnotator.class);
              JCas jcas = engine.newJCas();
      
              TokenBuilder<Token, Sentence> tb = TokenBuilder.create(Token.class, Sentence.class);
              tb.buildTokens(jcas, testDocument);
              engine.process(jcas);
              
              for (Token token : JCasUtil.select(jcas, Token.class)) {
                  Lemma lemma = new Lemma(jcas, token.getBegin(), token.getEnd());
                  lemma.addToIndexes();          
              }
      
              for (Token token : JCasUtil.select(jcas, Token.class)) {
      //            try {
      //                List<Token> previous = JCasUtil.selectPreceding(Token.class, token, 1);
      //                System.out.println(previous.get(0).getCoveredText());
      //            }
      //            catch (IndexOutOfBoundsException e) {
      //                System.out.println(token);
      //            }
                  try {
                      List<Lemma> previous = JCasUtil.selectPreceding(Lemma.class, token, 1);
                      System.out.println(previous.get(0).getCoveredText());
                  }
                  catch (IndexOutOfBoundsException e) {
                      System.out.println(token);
                  }
              }
          }
      

        Activity

        Hide
        rec Richard Eckart de Castilho added a comment -

        Most likely affects selectFollowing as well, possibly also selectRelative.

        Show
        rec Richard Eckart de Castilho added a comment - Most likely affects selectFollowing as well, possibly also selectRelative.

          People

          • Assignee:
            rec Richard Eckart de Castilho
            Reporter:
            zesch Torsten Zesch
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development