#NEWLINE# def _build_annotations( self ) : #NEWLINE# #INDENT# '\n        Helper method to parse the input file and store intermediate information\n        in attributes.\n\n        ' #NEWLINE# elements = dict ( ) #NEWLINE# ids = dict ( ) #NEWLINE# current_record_id = 0 #NEWLINE# current_utterance_id = 0 #NEWLINE# current_id = 0 #NEWLINE# first_marker_found = False #NEWLINE# tier_marker = None #NEWLINE# current_utterance = None #NEWLINE# for ( line_number , line ) in enumerate ( self . input_stream ) : #NEWLINE# #INDENT# if ( line_number == 0 ) : #NEWLINE# #INDENT# if line . startswith ( codecs . BOM_UTF8 ) : #NEWLINE# #INDENT# line = line [ BOMLEN : ] #NEWLINE# #UNINDENT# #UNINDENT# line = line . decode ( 'utf-8' , 'ignore' ) #NEWLINE# line = line . strip ( ) #NEWLINE# if ( '\name' in line ) : #NEWLINE# #INDENT# self . meta_information = line . split ( None , 2 ) [ 2 ] #NEWLINE# #UNINDENT# if ( line == '' ) : #NEWLINE# #INDENT# if ( len ( elements ) > 0 ) : #NEWLINE# #INDENT# self . _process_record ( elements , ids , current_utterance_id ) #NEWLINE# elements = dict ( ) #NEWLINE# ids = dict ( ) #NEWLINE# #UNINDENT# continue #NEWLINE# #UNINDENT# last_tier_marker = tier_marker #NEWLINE# tier_marker = None #NEWLINE# line_content = None #NEWLINE# match_tier_marker = re_tier_marker . search ( line ) #NEWLINE# if match_tier_marker : #NEWLINE# #INDENT# tier_marker = match_tier_marker . group ( 1 ) #NEWLINE# line_content = re_tier_marker . sub ( '' , line ) #NEWLINE# line_content = line_content . lstrip ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if first_marker_found : #NEWLINE# #INDENT# id_to_add = current_record_id #NEWLINE# if ( last_tier_marker in self . utterance_level_markers ) : #NEWLINE# #INDENT# id_to_add = current_utterance_id #NEWLINE# #UNINDENT# if self . _tier_labels . tier_label_exists ( last_tier_marker ) : #NEWLINE# #INDENT# self . _annotations_for_parent [ ( 'a{0}' . format ( id_to_add ) , last_tier_marker ) ] [ ( - 1 ) ] . value += ( ' ' + line ) #NEWLINE# #UNINDENT# tier_marker = last_tier_marker #NEWLINE# continue #NEWLINE# #UNINDENT# #UNINDENT# if ( not first_marker_found ) : #NEWLINE# #INDENT# if ( tier_marker != self . record_marker ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# first_marker_found = True #NEWLINE# #UNINDENT# #UNINDENT# if ( tier_marker in self . word_level_markers ) : #NEWLINE# #INDENT# if ( current_utterance is None ) : #NEWLINE# #INDENT# current_utterance = '' #NEWLINE# #UNINDENT# if ( current_utterance == '' ) : #NEWLINE# #INDENT# current_utterance_id = current_id #NEWLINE# current_id += 1 #NEWLINE# #UNINDENT# current_utterance += ( re . sub ( '\\s+' , ' ' , line_content ) + ' ' ) #NEWLINE# #UNINDENT# if ( ( tier_marker in self . word_level_markers ) or ( tier_marker in self . morpheme_level_markers ) or ( tier_marker in self . tag_level_markers ) ) : #NEWLINE# #INDENT# if ( tier_marker not in elements ) : #NEWLINE# #INDENT# elements [ tier_marker ] = dict ( ) #NEWLINE# #UNINDENT# if ( tier_marker not in ids ) : #NEWLINE# #INDENT# ids [ tier_marker ] = dict ( ) #NEWLINE# #UNINDENT# for ( j , match ) in enumerate ( re_word . finditer ( line ) ) : #NEWLINE# #INDENT# pos = char_len ( line [ : match . start ( 1 ) ] ) #NEWLINE# elements [ tier_marker ] [ pos ] = match . group ( 1 ) #NEWLINE# ids [ tier_marker ] [ pos ] = 'a{0}' . format ( current_id ) #NEWLINE# current_id += 1 #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( tier_marker in self . utterance_level_markers ) : #NEWLINE# #INDENT# if ( ( current_utterance is not None ) and ( current_utterance != '' ) ) : #NEWLINE# #INDENT# current_utterance = current_utterance . rstrip ( ) #NEWLINE# self . _annotate_utterance ( current_record_id , current_utterance_id , current_utterance ) #NEWLINE# current_utterance = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( current_utterance is None ) : #NEWLINE# #INDENT# current_utterance_id = current_id #NEWLINE# current_id += 1 #NEWLINE# self . _annotate_utterance ( current_record_id , current_utterance_id , '' ) #NEWLINE# current_utterance = '' #NEWLINE# #UNINDENT# #UNINDENT# self . _annotations_for_parent [ ( 'a{0}' . format ( current_utterance_id ) , tier_marker ) ] . append ( poioapi . io . graf . Annotation ( 'a{0}' . format ( current_id ) , line_content ) ) #NEWLINE# current_id += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( tier_marker in self . record_level_markers ) : #NEWLINE# #INDENT# if ( tier_marker == self . record_marker ) : #NEWLINE# #INDENT# if ( ( current_utterance is not None ) and ( current_utterance != '' ) ) : #NEWLINE# #INDENT# self . _annotate_utterance ( current_record_id , current_utterance_id , current_utterance ) #NEWLINE# #UNINDENT# self . _annotations_for_parent [ ( None , tier_marker ) ] . append ( poioapi . io . graf . Annotation ( 'a{0}' . format ( current_id ) , line_content ) ) #NEWLINE# current_record_id = current_id #NEWLINE# current_id += 1 #NEWLINE# current_utterance = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( current_utterance is not None ) and ( current_utterance != '' ) ) : #NEWLINE# #INDENT# self . _annotate_utterance ( current_record_id , current_utterance_id , current_utterance ) #NEWLINE# #UNINDENT# self . _annotations_for_parent [ ( 'a{0}' . format ( current_record_id ) , tier_marker ) ] . append ( poioapi . io . graf . Annotation ( 'a{0}' . format ( current_id ) , line_content ) ) #NEWLINE# current_id += 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# self . input_stream . seek ( 0 )