.getStartOffset()) {
correctOrder = true;
}
}
SubSection subsectionAnnotation = new SubSection(jcas,
subsectionThis.getStartOffset(),
subsectionThis.getEndOffset());
// Always set the beginning of the subsection at the next position
// of the subsectionAnnotation
subsectionAnnotation.setSubSectionBodyBegin(subsectionAnnotation
.getEnd() + 1);
boolean foundEnd = false;
Set segmentSet = new HashSet();
Iterator<?> segmentItr = indexes.getAnnotationIndex(Segment.type)
.iterator();
while (segmentItr.hasNext()) {
segmentSet.add(segmentItr.next());
}
Iterator<?> segItr = segmentSet.iterator();
// While there are segments
while (segItr.hasNext()) {
Segment segmentAnnotation = (Segment) segItr.next();
if (segmentAnnotation.getBegin() <= subsectionThis
.getStartOffset()
&& segmentAnnotation.getEnd() >= subsectionThis
.getStartOffset()) {
// Look at each sentence within the current segment
Iterator<?> sentenceItr = FSUtil
.getAnnotationsInSpanIterator(jcas, Sentence.type,
segmentAnnotation.getBegin(),
segmentAnnotation.getEnd());
Sentence sentenceAnnotation = null;
// while there are still sentences and current subsection
// end isn't found
while (sentenceItr.hasNext() && !foundEnd) {
sentenceAnnotation = (Sentence) sentenceItr.next();
if (!foundEnd && (subsectionNext != null)) {
// correct order?
if (subsectionNext.getStartOffset() > subsectionThis
.getStartOffset()) {
// If the starting offset of the next subsection
// is
// greater than or equal to the end of the
// current sentence
// (and the end of this sentence is greater than
// the end of
// the current subsectionAnnotation) and the
// beginning of the
// current sentence is not equal to the current
// subsection end.
if (subsectionNext.getStartOffset() >= sentenceAnnotation
.getEnd()
&& (sentenceAnnotation.getEnd() > subsectionAnnotation
.getEnd())
&& (sentenceAnnotation.getBegin() != subsectionThis
.getStartOffset())) {
int newLineCount = 0;
Iterator<?> baseItr = FSUtil
.getAnnotationsInSpanIterator(
jcas,
org.apache.ctakes.typesystem.type.syntax.BaseToken.type,
sentenceAnnotation.getEnd(),
subsectionNext
.getStartOffset() - 1);
while (baseItr.hasNext()) {
org.apache.ctakes.typesystem.type.syntax.BaseToken checkToken = (org.apache.ctakes.typesystem.type.syntax.BaseToken) baseItr
.next();
if ((checkToken instanceof NewlineToken)
|| (checkToken instanceof SymbolToken))
newLineCount++;
} // After taking in account the symbols and
// new line characters see
// if the ending of this sentence is
// adjacent to the next subsection
// then we found section end
if ((sentenceAnnotation.getEnd() + 1 + newLineCount) == subsectionNext
.getStartOffset()
|| sentenceAnnotation.getEnd()
+ newLineCount == subsectionNext
.getStartOffset()) {
foundEnd = true;
// set the end of the current subsection
// to sentence end and status
subsectionAnnotation
.setSubSectionBodyEnd(sentenceAnnotation
.getEnd());
subsectionAnnotation
.setStatus(subsectionThis
.getStatus());
// test new window code
subsectionAnnotation
.setSubSectionHeaderBegin(subsectionAnnotation
.getBegin());
subsectionAnnotation
.setSubSectionHeaderEnd(subsectionAnnotation
.getEnd());
subsectionAnnotation
.setEnd(subsectionAnnotation
.getSubSectionBodyEnd());
subsectionAnnotation
.setParentSectionId(segmentAnnotation
.getId());
}
// The next subsection end (or the next
// subsection plus one) is equal to the
// current
// sentence end then we found section end
} else if (subsectionNext.getEndOffset() == sentenceAnnotation
.getEnd()
|| subsectionNext.getEndOffset() < sentenceAnnotation
.getEnd()) {
foundEnd = true;
subsectionAnnotation
.setSubSectionBodyEnd(subsectionNext
.getStartOffset());
subsectionAnnotation
.setStatus(subsectionThis
.getStatus());
// test new window code
subsectionAnnotation
.setSubSectionHeaderBegin(subsectionAnnotation
.getBegin());
subsectionAnnotation
.setSubSectionHeaderEnd(subsectionAnnotation
.getEnd());
subsectionAnnotation
.setEnd(subsectionAnnotation
.getSubSectionBodyEnd());
subsectionAnnotation
.setParentSectionId(segmentAnnotation
.getId());
}
// if the current sentence ends at or before the
// start of the current subsection
// and the current sentence ends after the next
// subsection ends (incorrect order?)
} else if (subsectionThis.getStartOffset() <= sentenceAnnotation
.getEnd()
&& (sentenceAnnotation.getEnd() > subsectionNext
.getEndOffset()))
if ((sentenceAnnotation.getEnd() + 1) == subsectionThis
.getStartOffset()
|| sentenceAnnotation.getEnd() == subsectionThis
.getStartOffset()) {
foundEnd = true;
subsectionAnnotation
.setSubSectionBodyEnd(sentenceAnnotation
.getEnd());
subsectionAnnotation
.setStatus(subsectionThis
.getStatus());
// test new window code
subsectionAnnotation
.setSubSectionHeaderBegin(subsectionAnnotation
.getBegin());
subsectionAnnotation
.setSubSectionHeaderEnd(subsectionAnnotation
.getEnd());
subsectionAnnotation
.setEnd(subsectionAnnotation
.getSubSectionBodyEnd());
subsectionAnnotation
.setParentSectionId(segmentAnnotation
.getId());
}
// No next subsection then
// if there is a current subsection and end hasn't
// been found and the subsection begin
// is before the beginning of the current sentence,
// but at or after the section beginning
// and before the section ending then found end
} else if ((subsectionThis != null)
&& (!foundEnd)
&& (subsectionThis.getStartOffset() < sentenceAnnotation
.getBegin())
&& (subsectionThis.getStartOffset() >= segmentAnnotation
.getBegin())
&& subsectionThis.getStartOffset() <= segmentAnnotation
.getEnd()) {
foundEnd = true;
subsectionAnnotation
.setSubSectionBodyEnd(sentenceAnnotation
.getEnd());
subsectionAnnotation.setStatus(subsectionThis
.getStatus());
// test new window code
subsectionAnnotation
.setSubSectionHeaderBegin(subsectionAnnotation
.getBegin());
subsectionAnnotation
.setSubSectionHeaderEnd(subsectionAnnotation
.getEnd());
subsectionAnnotation.setEnd(subsectionAnnotation
.getSubSectionBodyEnd());
subsectionAnnotation
.setParentSectionId(segmentAnnotation
.getId());
// No next subsection then
// if there is a current subsection and end hasn't
// been found and
// the end of the subsection heading is equal to the
// end of the sentence (weird case)
} else if ((subsectionThis != null)
&& (!foundEnd)
&& (subsectionThis.getEndOffset() == sentenceAnnotation
.getEnd())) {
foundEnd = true;
subsectionAnnotation
.setSubSectionBodyEnd(sentenceAnnotation
.getEnd());
subsectionAnnotation.setStatus(subsectionThis
.getStatus());
// test new window code
subsectionAnnotation
.setSubSectionHeaderBegin(subsectionAnnotation
.getBegin());
subsectionAnnotation
.setSubSectionHeaderEnd(subsectionAnnotation
.getEnd());
subsectionAnnotation.setEnd(subsectionAnnotation
.getSubSectionBodyEnd());
subsectionAnnotation
.setParentSectionId(segmentAnnotation
.getId());
}
}
}
if (foundEnd)
subsectionAnnotation.addToIndexes();
}
}
Iterator<?> segmentItrAgain = indexes.getAnnotationIndex(Segment.type)
.iterator();
while (segmentItrAgain.hasNext()) {
Segment segmentScope = (Segment) segmentItrAgain.next();
Iterator<?> subSectionItr = FSUtil.getAnnotationsInSpanIterator(
jcas, SubSection.type, segmentScope.getBegin(),
segmentScope.getEnd());
while (subSectionItr.hasNext()) {
SubSection checkSubsection = (SubSection) subSectionItr.next();
// if the current segment is not one of the medical sections of
// interest then only capture one sentence as the span of the
// subsection when the sentence end
// is greater then the subsection annotation end and only if the
// subsection and sentence are w/in the section
// boundaries
if (/*
* !iv_medicalSections.contains(segmentScope.getId()) &&
*/(segmentScope.getEnd() < checkSubsection
.getSubSectionBodyEnd() || checkSubsection.getBegin() < segmentScope
.getBegin())) {
Iterator<?> sentenceSubSection = FSUtil
.getAnnotationsInSpanIterator(jcas, Sentence.type,
segmentScope.getBegin(),
segmentScope.getEnd());
boolean foundModifiedEnd = false;
while (sentenceSubSection.hasNext() && !foundModifiedEnd) {
Sentence checkSentence = (Sentence) sentenceSubSection
.next();
if (checkSentence.getBegin() >= checkSubsection
.getBegin()
&& checkSentence.getEnd() >= checkSubsection
.getEnd()) {
checkSubsection.setSubSectionBodyEnd(checkSentence
.getEnd());
foundModifiedEnd = true;
}
}
} else if (!subSectionItr.hasNext()) {
checkSubsection
.setSubSectionBodyEnd(segmentScope.getEnd() - 1);
checkSubsection.setEnd(segmentScope.getEnd() - 1);
}
}
}
}