public void process(JCas jcas) throws AnalysisEngineProcessException {
JFSIndexRepository indexes = jcas.getJFSIndexRepository();
Iterator senIter = indexes.getAnnotationIndex(Sentence.type).iterator();
while (senIter.hasNext()) {
Sentence sen = (Sentence) senIter.next();
boolean foundDrug = false;
boolean foundPSE = false;
if (setionsToIgnore.contains(sen.getSegmentId()))
continue;
// if drug is not found in the same sentence and the previous
// sentence contains
// drug and they are in the same line, then sentence will be
// previous + current sentence
Iterator neIter = FSUtil
.getAnnotationsInSpanIterator(jcas,
IdentifiedAnnotation.type, sen.getBegin(),
sen.getEnd() + 1);
while (neIter.hasNext()) {
IdentifiedAnnotation n = (IdentifiedAnnotation) neIter.next();
if (n.getTypeID() == 2 || n.getTypeID() == 3)
foundPSE = true;
if (n.getTypeID() == 1)
foundDrug = true;
}
if (!foundPSE)
continue;
if (foundPSE && foundDrug) {
PSESentence ps = new PSESentence(jcas);
ps.setBegin(sen.getBegin());
ps.setEnd(sen.getEnd());
ps.addToIndexes();
} else if (foundPSE && !foundDrug) {
int num = sen.getSentenceNumber();
num = (num > 0) ? num - 1 : num;
int[] previousSenSpan = SEUtil
.getSentenceSpanOfGivenSentenceNum(jcas, num);
// only if they are in the same line
if (SEUtil.isSpanInSameLine(jcas, previousSenSpan[0],
sen.getEnd())) {
neIter = FSUtil.getAnnotationsInSpanIterator(jcas,
IdentifiedAnnotation.type, previousSenSpan[0],
previousSenSpan[1] + 1);
while (neIter.hasNext()) {
IdentifiedAnnotation n = (IdentifiedAnnotation) neIter
.next();
if (n.getTypeID() == 1) {
PSESentence ps = new PSESentence(jcas);
ps.setBegin(previousSenSpan[0]);
ps.setEnd(sen.getEnd());
ps.addToIndexes();
break;
}
}
}