SnowballStemmer extends JCasAnnotator_ImplBase { @SuppressWarnings("unchecked") @Override public void process(JCas jCas) throws AnalysisEngineProcessException { if (!typesInitialized) initializeTypes(jCas); FSIterator<Annotation> tokens = jCas.getAnnotationIndex(tokenType).iterator(); while (tokens.hasNext()) { TOKEN_TYPE token = (TOKEN_TYPE) tokens.next(); stemmer.setCurrent(token.getCoveredText().toLowerCase()); stemmer.stem(); String stem = stemmer.getCurrent(); setStem(token, stem); } }  @Override void initialize(UimaContext context); @SuppressWarnings("unchecked") @Override void process(JCas jCas); abstract void setStem(TOKEN_TYPE token, String stem); void setStemmerName(String stemmerName); static final String PARAM_STEMMER_NAME; @ConfigurationParameter(
      name = PARAM_STEMMER_NAME,
      description = STEMMER_NAME_DESCRIPTION,
      mandatory = true)
  public String stemmerName; }
@Test public void testSimple() throws UIMAException { AnalysisEngine engine = AnalysisEngineFactory.createEngine( DefaultSnowballStemmer.class, SnowballStemmer.PARAM_STEMMER_NAME, "English"); String text = "The brown foxes jumped quickly over the lazy dog."; String tokens = "The brown foxes jumped quickly over the lazy dog ."; tokenBuilder.buildTokens(jCas, text, tokens); engine.process(jCas); List<String> actual = new ArrayList<String>(); for (Token token : JCasUtil.select(jCas, Token.class)) { actual.add(token.getStem()); } String expected = "the brown fox jump quick over the lazi dog ."; Assert.assertEquals(Arrays.asList(expected.split(" ")), actual); }
@Test public void testUppercase() throws UIMAException { AnalysisEngine engine = AnalysisEngineFactory.createEngine( DefaultSnowballStemmer.class, SnowballStemmer.PARAM_STEMMER_NAME, "English"); tokenBuilder.buildTokens( jCas, "The brown foxes JumPEd QUICKLy over the lazY dog.", "The brown foxes JumPEd QUICKLy over the lazY dog ."); engine.process(jCas); List<String> expected = Arrays.asList("the brown fox jump quick over the lazi dog .".split(" ")); List<String> actual = new ArrayList<String>(); for (Token token : JCasUtil.select(jCas, Token.class)) { actual.add(token.getStem()); } Assert.assertEquals(expected, actual); }