private static void splitRowsOnIslands ( Row row , final SDocumentGraph graph , STextualDS text , long startTokenIndex , long endTokenIndex ) { BitSet tokenCoverage = new BitSet ( ) ; // get the sorted token List < SToken > sortedTokenList = graph . getSortedTokenByText ( ) ; // add all token belonging to the right text to the bit set ListIterator < SToken > itToken = sortedTokenList . listIterator ( ) ; while ( itToken . hasNext ( ) ) { SToken t = itToken . next ( ) ; if ( text == null || text == CommonHelper . getTextualDSForNode ( t , graph ) ) { RelannisNodeFeature feat = ( RelannisNodeFeature ) t . getFeature ( ANNIS_NS , FEAT_RELANNIS_NODE ) . getValue ( ) ; long tokenIndexRaw = feat . getTokenIndex ( ) ; tokenIndexRaw = clip ( tokenIndexRaw , startTokenIndex , endTokenIndex ) ; int tokenIndex = ( int ) ( tokenIndexRaw - startTokenIndex ) ; tokenCoverage . set ( tokenIndex ) ; } } ListIterator < GridEvent > itEvents = row . getEvents ( ) . listIterator ( ) ; while ( itEvents . hasNext ( ) ) { GridEvent event = itEvents . next ( ) ; BitSet eventBitSet = new BitSet ( ) ; eventBitSet . set ( event . getLeft ( ) , event . getRight ( ) + 1 ) ; // restrict event bitset on the locations where token are present eventBitSet . and ( tokenCoverage ) ; // if there is is any 0 bit before the right border there is a break in the event // and we need to split it if ( eventBitSet . nextClearBit ( event . getLeft ( ) ) <= event . getRight ( ) ) { // remove the original event row . removeEvent ( itEvents ) ; // The event bitset now marks all the locations which the event should // cover. // Make a list of new events for each connected range in the bitset int subElement = 0 ; int offset = eventBitSet . nextSetBit ( 0 ) ; while ( offset >= 0 ) { int end = eventBitSet . nextClearBit ( offset ) - 1 ; if ( offset < end ) { GridEvent newEvent = new GridEvent ( event ) ; newEvent . setId ( event . getId ( ) + "_islandsplit_" + subElement ++ ) ; newEvent . setLeft ( offset ) ; newEvent . setRight ( end ) ; row . addEvent ( itEvents , newEvent ) ; } offset = eventBitSet . nextSetBit ( end + 1 ) ; } } // end if we need to split } }
Splits events of a row if they overlap an island . Islands are areas between the token which are included in the result .