@SuppressWarnings("unchecked")
@Override
public void execute() throws ExecutionException {
// text doc annotations
AnnotationSet annotations;
if (annotationSetName != null && annotationSetName.length() > 0) {
annotations = document.getAnnotations(annotationSetName);
} else {
annotations = document.getAnnotations();
}
// getdoc.get text
// String text = document.getContent().toString();
// get token and sentence annotations
AnnotationSet sentences = annotations.get("Sentence");
AnnotationSet tokensAS = annotations.get("Token");
if (sentences != null && sentences.size() > 0 && tokensAS != null
&& tokensAS.size() > 0) {
// order them
List<Annotation> sentList = new LinkedList<Annotation>();
for (Iterator iterator = sentences.iterator(); iterator.hasNext();) {
sentList.add((Annotation) iterator.next());
}
java.util.Collections.sort(sentList,
new gate.util.OffsetComparator());
// for each sentence get token annotations
for (Iterator iterator = sentList.iterator(); iterator.hasNext();) {
Annotation annotation = (Annotation) iterator.next();
AnnotationSet sentenceTokens = annotations.get("Token",
annotation.getStartNode().getOffset(), annotation
.getEndNode().getOffset());
// create a list
List<Annotation> annList = new LinkedList<Annotation>();
for (Iterator<Annotation> iterator2 = sentenceTokens.iterator(); iterator2
.hasNext();) {
annList.add(iterator2.next());
}
// order on offset
Collections.sort(annList, new gate.util.OffsetComparator());
// make the array be string[] sentence
String[] tokens = new String[sentenceTokens.size()];
String[] postags = new String[sentenceTokens.size()];
int i = 0;
for (Iterator iterator3 = annList.iterator(); iterator3
.hasNext();) {
Annotation token = (Annotation) iterator3.next();