private AnnotationFS findCoverFS ( CAS aCAS , AnnotationFS annot , Type coverFsType ) { // covering annotation AnnotationFS coverFs = null ; // create a searchFS of the coverFsType with the annot boundaries to // search for it. FeatureStructure searchFs = aCAS . createAnnotation ( coverFsType , annot . getBegin ( ) , aCAS . getDocumentText ( ) . length ( ) ) ; // get the coverFSType iterator from the CAS and move it "near" to the // position of the created searchFS. FSIterator < ? > iterator = aCAS . getAnnotationIndex ( coverFsType ) . iterator ( ) ; iterator . moveTo ( searchFs ) ; // now the iterator can either point directly to the FS we are searching // or it points to the next higher FS in the list. So we either have // already found the correct one, of we maybe have to move the iterator to // the previous position. // check if the iterator at the current position is valid if ( iterator . isValid ( ) ) { // iterator is valid, so we either have the correct annotation of we // have to move to the // previous one, lets check the current FS from the iterator // get current FS coverFs = ( AnnotationFS ) iterator . get ( ) ; // check if the coverFS covers the current match type annotation if ( ( coverFs . getBegin ( ) <= annot . getBegin ( ) ) && ( coverFs . getEnd ( ) >= annot . getEnd ( ) ) ) { // we found the covering annotation return coverFs ; } // current coverFs does not cover the current match type annotation // lets try to move iterator to the previous annotation and check // again iterator . moveToPrevious ( ) ; // check if the iterator is still valid after me move it to the // previous FS if ( iterator . isValid ( ) ) { // get FS coverFs = ( AnnotationFS ) iterator . get ( ) ; // check the found coverFS covers the current match type // annotation if ( ( coverFs . getBegin ( ) <= annot . getBegin ( ) ) && ( coverFs . getEnd ( ) >= annot . getEnd ( ) ) ) { // we found the covering annotation return coverFs ; } } } // iterator is invalid lets try to move the iterator to the last FS and // check the FS iterator . moveToLast ( ) ; // check if the iterator is valid after we move it if ( iterator . isValid ( ) ) { // get FS coverFs = ( AnnotationFS ) iterator . get ( ) ; // check the found coverFS covers the current match type annotation if ( ( coverFs . getBegin ( ) <= annot . getBegin ( ) ) && ( coverFs . getEnd ( ) >= annot . getEnd ( ) ) ) { // we found the covering annotation return coverFs ; } } // no covering annotation found return null ; }
Finds the covering annotation of the specified coverFSType for the given annotation .