// get stem() method from stemmer
Method stemmerStemMethod;
try {
stemmerStemMethod = stemmer.getClass().getMethod("stem", new Class[0]);
} catch (Exception ex) {
throw new AnnotatorProcessException(ex);
}
// iterate over all token annotations and add stem if available
FSIterator tokenIterator = aJCas.getCas().getAnnotationIndex(this.tokenAnnotation).iterator();
while (tokenIterator.hasNext()) {
// get token content
AnnotationFS annot = (AnnotationFS) tokenIterator.next();
String span = annot.getCoveredText();
// set annotation content and call stemmer
try {
stemmer.setCurrent(span);
stemmerStemMethod.invoke(stemmer, emptyArgs);
} catch (Exception ex) {
throw new AnnotatorProcessException(ex);
}
// get stemmer result and set annotation feature
annot.setStringValue(this.tokenAnnotationStemmFeature, stemmer.getCurrent());
}