### Question:
BioLemmatizerNormalizerAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jCas) throws AnalysisEngineProcessException { for (Keep k : select(jCas, Keep.class)) { Annotation a = k.getEnclosedAnnot(); String normalized = null; if (a instanceof Token) { normalized = ((Token) a).getLemmaStr(); if (!caseSensitive){ normalized = normalized.toLowerCase(); } k.setNormalizedText(normalized); } else if(!onlyTokens) { try { normalized = BlueBioLemmatizer.lemmatize(a.getCoveredText(), ""); } catch (Exception e) { LOG.warn("Failed to lemmatize '{}'", a.getCoveredText()); normalized = a.getCoveredText().trim(); } finally{ if (!caseSensitive){ normalized = normalized.toLowerCase(); } k.setNormalizedText(normalized); } } } }  @Override void initialize(UimaContext context); @Override void process(JCas jCas);  }### Answer:
@Test public void test() throws Exception { JCas jCas = UimaTests.getTokenizedTestCas("AMPAR is Regulated by GABA"); PipelineBuilder builder = new JcasPipelineBuilder(jCas); builder.add(BlueBioLemmatizer.class); builder.add(Tokens2KeepAnnotator.class); builder.add(BioLemmatizerNormalizerAnnotator.class); builder.process(); Collection<Keep> keeps = select(jCas, Keep.class); assertEquals(5, keeps.size()); Iterator<Keep> it = keeps.iterator(); it.next(); assertEquals("be", it.next().getNormalizedText()); assertEquals("regulate", it.next().getNormalizedText()); }
@Test public void testNonTokensIncluded() throws Exception{ JCas jCas = UimaTests.getTestCas("is regulated"); Measure m = createAnnot(jCas, Measure.class, 0, 1); Keep k = createAnnot(jCas, Keep.class, 0, 1); k.setEnclosedAnnot(m); k.setNormalizedText("is"); Token t = createAnnot(jCas,Token.class, 3, 11); createAnnot(jCas, Keep.class, 3, 11).setEnclosedAnnot(t); PipelineBuilder builder = new JcasPipelineBuilder(jCas); builder.add(BlueBioLemmatizer.class); builder.add(BioLemmatizerNormalizerAnnotator.class); builder.process(); Collection<Keep> keeps = select(jCas, Keep.class); assertEquals(2, keeps.size()); Iterator<Keep> it = keeps.iterator(); assertEquals("i", it.next().getNormalizedText()); assertEquals("regulate", it.next().getNormalizedText()); }
@Test public void testOnlyTokens() throws Exception{ JCas jCas = UimaTests.getTestCas("is regulated"); Measure m = createAnnot(jCas, Measure.class, 0, 1); m.setUnit("%"); m.setValue(20f); Keep k = createAnnot(jCas, Keep.class, 0, 1); k.setEnclosedAnnot(m); k.setNormalizedText("is"); Token t = createAnnot(jCas,Token.class, 3, 11); createAnnot(jCas, Keep.class, 3, 11).setEnclosedAnnot(t); PipelineBuilder builder = new JcasPipelineBuilder(jCas); builder.add(BlueBioLemmatizer.class); builder.add(AnalysisEngineFactory.createEngineDescription(BioLemmatizerNormalizerAnnotator.class, "onlyTokens", true)); builder.process(); Collection<Keep> keeps = select(jCas, Keep.class); assertEquals(2, keeps.size()); Iterator<Keep> it = keeps.iterator(); assertEquals("is", it.next().getNormalizedText()); assertEquals("regulate", it.next().getNormalizedText()); }