@Test public void testBioLemmatizerWithoutPOS() { try { JCas jCas = JCasFactory.createJCas("de.julielab.jcore.types.jcore-all-types"); jCas.setDocumentText("Three horses were going contemplatively around bushy bushes."); BioLemmatizer biolemm = new BioLemmatizer(); AnalysisEngine bioLemmatizer = AnalysisEngineFactory.createEngine(biolemm.getClass()); Token t; t = new Token(jCas, 0, 5); t.addToIndexes(); t = new Token(jCas, 6, 12); t.addToIndexes(); t = new Token(jCas, 13, 17); t.addToIndexes(); t = new Token(jCas, 18, 23); t.addToIndexes(); t = new Token(jCas, 24, 39); t.addToIndexes(); t = new Token(jCas, 40, 46); t.addToIndexes(); t = new Token(jCas, 47, 52); t.addToIndexes(); t = new Token(jCas, 53, 59); t.addToIndexes(); t = new Token(jCas, 59, 60); t.addToIndexes(); bioLemmatizer.process(jCas); FSIterator<Annotation> iterator = jCas.getAnnotationIndex(Token.type).iterator(); while (iterator.hasNext()) { Token token = (Token) iterator.next(); assertNotNull(token.getLemma()); assertNotNull(token.getLemma().getValue()); assertEquals(token.getBegin(), token.getLemma().getBegin()); assertEquals(token.getEnd(), token.getLemma().getEnd()); String expectedLemma; switch (token.getCoveredText()) { case "Three": expectedLemma = "three"; break; case "horses": expectedLemma = "horse"; break; case "were": expectedLemma = "be"; break; case "going": expectedLemma = "go"; break; case "contemplatively": expectedLemma = "contemplative"; break; case "around": expectedLemma = "around"; break; case "bushy": expectedLemma = "bushy"; break; case "bushes": expectedLemma = "bush"; break; case ".": expectedLemma = "."; break; default: throw new IllegalStateException( "Coding error in the test, all words should be covered or we could miss errors."); } assertEquals(token.getLemma().getValue(), expectedLemma); } } catch (Exception e) { e.printStackTrace(); } }
@Override public void process(final JCas aJCas) throws AnalysisEngineProcessException { String tokenString = null; String tag = null; try { AnnotationIndex<Annotation> jcoreTokenIndex = aJCas.getAnnotationIndex(Token.type); FSIterator<Annotation> tokenIterator = jcoreTokenIndex.iterator(); while (tokenIterator.hasNext()) { Token token = (Token) tokenIterator.get(); tokenString = token.getCoveredText(); LemmataEntry lemmaEntry = null; try { if (token.getPosTag() != null) { POSTag posTag = token.getPosTag(0); tag = posTag.getValue(); lemmaEntry = bioLemm.lemmatizeByLexiconAndRules(tokenString, tag); } else { lemmaEntry = bioLemm.lemmatizeByLexiconAndRules(tokenString, ""); } } catch (java.lang.IllegalStateException | java.lang.IndexOutOfBoundsException e) { log.debug("BioLemmatizer-internal exception: ", e); } if (lemmaEntry != null) { Collection<LemmataEntry.Lemma> lemmaCollection = lemmaEntry.getLemmas(); LemmataEntry.Lemma lemma = lemmaCollection.iterator().next(); String lem = lemma.getLemma(); Lemma jcoreLemma = new Lemma(aJCas, token.getBegin(), token.getEnd()); jcoreLemma.setValue(lem); token.setLemma(jcoreLemma); } else { Lemma jcoreLemma = new Lemma(aJCas, token.getBegin(), token.getEnd()); jcoreLemma.setValue(tokenString); token.setLemma(jcoreLemma); } tokenIterator.next(); } } catch (Exception e) { log.error("Exception occurred:", e); } }
BioLemmatizer extends JCasAnnotator_ImplBase { @Override public void process(final JCas aJCas) throws AnalysisEngineProcessException { String tokenString = null; String tag = null; try { AnnotationIndex<Annotation> jcoreTokenIndex = aJCas.getAnnotationIndex(Token.type); FSIterator<Annotation> tokenIterator = jcoreTokenIndex.iterator(); while (tokenIterator.hasNext()) { Token token = (Token) tokenIterator.get(); tokenString = token.getCoveredText(); LemmataEntry lemmaEntry = null; try { if (token.getPosTag() != null) { POSTag posTag = token.getPosTag(0); tag = posTag.getValue(); lemmaEntry = bioLemm.lemmatizeByLexiconAndRules(tokenString, tag); } else { lemmaEntry = bioLemm.lemmatizeByLexiconAndRules(tokenString, ""); } } catch (java.lang.IllegalStateException | java.lang.IndexOutOfBoundsException e) { log.debug("BioLemmatizer-internal exception: ", e); } if (lemmaEntry != null) { Collection<LemmataEntry.Lemma> lemmaCollection = lemmaEntry.getLemmas(); LemmataEntry.Lemma lemma = lemmaCollection.iterator().next(); String lem = lemma.getLemma(); Lemma jcoreLemma = new Lemma(aJCas, token.getBegin(), token.getEnd()); jcoreLemma.setValue(lem); token.setLemma(jcoreLemma); } else { Lemma jcoreLemma = new Lemma(aJCas, token.getBegin(), token.getEnd()); jcoreLemma.setValue(tokenString); token.setLemma(jcoreLemma); } tokenIterator.next(); } } catch (Exception e) { log.error("Exception occurred:", e); } } }
BioLemmatizer extends JCasAnnotator_ImplBase { @Override public void process(final JCas aJCas) throws AnalysisEngineProcessException { String tokenString = null; String tag = null; try { AnnotationIndex<Annotation> jcoreTokenIndex = aJCas.getAnnotationIndex(Token.type); FSIterator<Annotation> tokenIterator = jcoreTokenIndex.iterator(); while (tokenIterator.hasNext()) { Token token = (Token) tokenIterator.get(); tokenString = token.getCoveredText(); LemmataEntry lemmaEntry = null; try { if (token.getPosTag() != null) { POSTag posTag = token.getPosTag(0); tag = posTag.getValue(); lemmaEntry = bioLemm.lemmatizeByLexiconAndRules(tokenString, tag); } else { lemmaEntry = bioLemm.lemmatizeByLexiconAndRules(tokenString, ""); } } catch (java.lang.IllegalStateException | java.lang.IndexOutOfBoundsException e) { log.debug("BioLemmatizer-internal exception: ", e); } if (lemmaEntry != null) { Collection<LemmataEntry.Lemma> lemmaCollection = lemmaEntry.getLemmas(); LemmataEntry.Lemma lemma = lemmaCollection.iterator().next(); String lem = lemma.getLemma(); Lemma jcoreLemma = new Lemma(aJCas, token.getBegin(), token.getEnd()); jcoreLemma.setValue(lem); token.setLemma(jcoreLemma); } else { Lemma jcoreLemma = new Lemma(aJCas, token.getBegin(), token.getEnd()); jcoreLemma.setValue(tokenString); token.setLemma(jcoreLemma); } tokenIterator.next(); } } catch (Exception e) { log.error("Exception occurred:", e); } }  }
BioLemmatizer extends JCasAnnotator_ImplBase { @Override public void process(final JCas aJCas) throws AnalysisEngineProcessException { String tokenString = null; String tag = null; try { AnnotationIndex<Annotation> jcoreTokenIndex = aJCas.getAnnotationIndex(Token.type); FSIterator<Annotation> tokenIterator = jcoreTokenIndex.iterator(); while (tokenIterator.hasNext()) { Token token = (Token) tokenIterator.get(); tokenString = token.getCoveredText(); LemmataEntry lemmaEntry = null; try { if (token.getPosTag() != null) { POSTag posTag = token.getPosTag(0); tag = posTag.getValue(); lemmaEntry = bioLemm.lemmatizeByLexiconAndRules(tokenString, tag); } else { lemmaEntry = bioLemm.lemmatizeByLexiconAndRules(tokenString, ""); } } catch (java.lang.IllegalStateException | java.lang.IndexOutOfBoundsException e) { log.debug("BioLemmatizer-internal exception: ", e); } if (lemmaEntry != null) { Collection<LemmataEntry.Lemma> lemmaCollection = lemmaEntry.getLemmas(); LemmataEntry.Lemma lemma = lemmaCollection.iterator().next(); String lem = lemma.getLemma(); Lemma jcoreLemma = new Lemma(aJCas, token.getBegin(), token.getEnd()); jcoreLemma.setValue(lem); token.setLemma(jcoreLemma); } else { Lemma jcoreLemma = new Lemma(aJCas, token.getBegin(), token.getEnd()); jcoreLemma.setValue(tokenString); token.setLemma(jcoreLemma); } tokenIterator.next(); } } catch (Exception e) { log.error("Exception occurred:", e); } }  @Override void initialize(final UimaContext aContext); @Override void process(final JCas aJCas); }
BioLemmatizer extends JCasAnnotator_ImplBase { @Override public void process(final JCas aJCas) throws AnalysisEngineProcessException { String tokenString = null; String tag = null; try { AnnotationIndex<Annotation> jcoreTokenIndex = aJCas.getAnnotationIndex(Token.type); FSIterator<Annotation> tokenIterator = jcoreTokenIndex.iterator(); while (tokenIterator.hasNext()) { Token token = (Token) tokenIterator.get(); tokenString = token.getCoveredText(); LemmataEntry lemmaEntry = null; try { if (token.getPosTag() != null) { POSTag posTag = token.getPosTag(0); tag = posTag.getValue(); lemmaEntry = bioLemm.lemmatizeByLexiconAndRules(tokenString, tag); } else { lemmaEntry = bioLemm.lemmatizeByLexiconAndRules(tokenString, ""); } } catch (java.lang.IllegalStateException | java.lang.IndexOutOfBoundsException e) { log.debug("BioLemmatizer-internal exception: ", e); } if (lemmaEntry != null) { Collection<LemmataEntry.Lemma> lemmaCollection = lemmaEntry.getLemmas(); LemmataEntry.Lemma lemma = lemmaCollection.iterator().next(); String lem = lemma.getLemma(); Lemma jcoreLemma = new Lemma(aJCas, token.getBegin(), token.getEnd()); jcoreLemma.setValue(lem); token.setLemma(jcoreLemma); } else { Lemma jcoreLemma = new Lemma(aJCas, token.getBegin(), token.getEnd()); jcoreLemma.setValue(tokenString); token.setLemma(jcoreLemma); } tokenIterator.next(); } } catch (Exception e) { log.error("Exception occurred:", e); } }  @Override void initialize(final UimaContext aContext); @Override void process(final JCas aJCas); static edu.ucdenver.ccp.nlp.biolemmatizer.BioLemmatizer bioLemm; }