#NEWLINE# def read_block( self , stream ) : #NEWLINE# #INDENT# block = stream . readlines ( self . _pagesize ) #NEWLINE# block = concat ( block ) #NEWLINE# while ( ( block . count ( '<text id' ) > block . count ( '</text>' ) ) or ( block . count ( '<text id' ) == 0 ) ) : #NEWLINE# #INDENT# tmp = stream . readline ( ) #NEWLINE# if ( len ( tmp ) <= 0 ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# block += tmp #NEWLINE# #UNINDENT# block = block . replace ( '\n' , '' ) #NEWLINE# textids = TEXTID . findall ( block ) #NEWLINE# if self . _textids : #NEWLINE# #INDENT# for tid in textids : #NEWLINE# #INDENT# if ( tid not in self . _textids ) : #NEWLINE# #INDENT# beg = ( block . find ( tid ) - 1 ) #NEWLINE# end = ( block [ beg : ] . find ( '</text>' ) + len ( '</text>' ) ) #NEWLINE# block = ( block [ : beg ] + block [ ( block + end ) : ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# output = [ ] #NEWLINE# for para_str in PARA . findall ( block ) : #NEWLINE# #INDENT# para = [ ] #NEWLINE# for sent_str in SENT . findall ( para_str ) : #NEWLINE# #INDENT# if ( not self . _tagged ) : #NEWLINE# #INDENT# sent = WORD . findall ( sent_str ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sent = list ( map ( self . _parse_tag , TAGGEDWORD . findall ( sent_str ) ) ) #NEWLINE# #UNINDENT# if self . _group_by_sent : #NEWLINE# #INDENT# para . append ( sent ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# para . extend ( sent ) #NEWLINE# #UNINDENT# #UNINDENT# if self . _group_by_para : #NEWLINE# #INDENT# output . append ( para ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# output . extend ( para ) #NEWLINE# #UNINDENT# #UNINDENT# return output