#NEWLINE# def get_spans( sentence , good_label = 1 , bad_label = 0 ) : #NEWLINE# #INDENT# ( good_spans , bad_spans ) = ( [ ] , [ ] ) #NEWLINE# prev_label = None #NEWLINE# cur_start = 0 #NEWLINE# for ( idx , label ) in enumerate ( sentence ) : #NEWLINE# #INDENT# if ( label == good_label ) : #NEWLINE# #INDENT# if ( label != prev_label ) : #NEWLINE# #INDENT# if ( prev_label is not None ) : #NEWLINE# #INDENT# bad_spans . append ( ( cur_start , idx ) ) #NEWLINE# #UNINDENT# cur_start = idx #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( label == bad_label ) : #NEWLINE# #INDENT# if ( label != prev_label ) : #NEWLINE# #INDENT# if ( prev_label is not None ) : #NEWLINE# #INDENT# good_spans . append ( ( cur_start , idx ) ) #NEWLINE# #UNINDENT# cur_start = idx #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# print ( 'Unknown label' , label ) #NEWLINE# #UNINDENT# #UNINDENT# prev_label = label #NEWLINE# #UNINDENT# if ( prev_label == good_label ) : #NEWLINE# #INDENT# good_spans . append ( ( cur_start , len ( sentence ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# bad_spans . append ( ( cur_start , len ( sentence ) ) ) #NEWLINE# #UNINDENT# return ( good_spans , bad_spans )