Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
2.0.0uimaFIT
-
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); } } }