this.logger.log(Level.INFO, "Snowball annotator starts processing");
// get get stemmer for the document language
String language = new Language(aJCas.getDocumentLanguage()).getLanguagePart();
SnowballProgram stemmer = this.stemmers.get(language);
// create stemms if stemmer for the current document language is available
if (stemmer != null) {
// get stem() method from stemmer
Method stemmerStemMethod;
try {
stemmerStemMethod = stemmer.getClass().getMethod("stem", new Class[0]);
} catch (Exception ex) {
throw new AnalysisEngineProcessException(ex);
}
// iterate over all token annotations and add stem if available
FSIterator<Annotation> tokenIterator = aJCas.getAnnotationIndex(TokenAnnotation.type).iterator();
while (tokenIterator.hasNext()) {
// get token content
TokenAnnotation annot = (TokenAnnotation) 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 AnalysisEngineProcessException(ex);
}
// get stemmer result and set annotation feature
annot.setStem(stemmer.getCurrent());
}
} else {
if (language.equals("x")) {
this.logger.log(Level.WARNING, "Language of the CAS is set to 'x', SnowballAnnotator skipped processing.");
}