AnnotationIndex sentenceIndex = aJCas.getAnnotationIndex(Sentence.type);
// iterate over Sentences
FSIterator sentenceIterator = sentenceIndex.iterator();
while (sentenceIterator.hasNext()) {
Sentence sentence = (Sentence) sentenceIterator.next();
String text = sentence.getCoveredText();
Span[] tokenSpans = tokenizer.tokenizePos(text);
for (int i = 0; i < tokenSpans.length; i++) {
Span span = tokenSpans[i];
Token token = new Token(aJCas);
token.setBegin(sentence.getBegin() + span.getStart());
token.setEnd(sentence.getBegin() + span.getEnd());
token.setComponentId(COMPONENT_ID);
token.addToIndexes();
}
}