#NEWLINE# def crfsuite_to_crfpp( in_file , tmp_dir , dataset_name , sequence = True , stamp = None ) : #NEWLINE# #INDENT# if ( out_file is None ) : #NEWLINE# #INDENT# stamp = str ( time . time ( ) ) #NEWLINE# #UNINDENT# feature_num = 0 #NEWLINE# out_file_name = os . path . join ( tmp_dir , ( ( ( 'crfpp.' + dataset_name ) + '.' ) + stamp ) ) #NEWLINE# out_file = open ( out_file_name , 'w' ) #NEWLINE# tag_set = [ ] #NEWLINE# for line in open ( in_file ) : #NEWLINE# #INDENT# line = line . strip ( '\n' ) . decode ( 'utf-8' ) #NEWLINE# if ( line == '' ) : #NEWLINE# #INDENT# if sequence : #NEWLINE# #INDENT# out_file . write ( '\n' ) #NEWLINE# #UNINDENT# continue #NEWLINE# #UNINDENT# elements = line . split ( '\t' ) #NEWLINE# cur_tag = elements [ 0 ] #NEWLINE# tag_set . append ( cur_tag ) #NEWLINE# cur_features = [ ] #NEWLINE# for el in elements [ 1 : ] : #NEWLINE# #INDENT# stop = el . find ( ':' ) #NEWLINE# if ( stop == ( - 1 ) ) : #NEWLINE# #INDENT# cur_features . append ( el ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cur_features . append ( ( el [ : ( stop - 1 ) ] + el [ ( stop + 1 ) : ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# feature_num = len ( cur_features ) #NEWLINE# to_pr = '\t' . join ( cur_features ) #NEWLINE# out_file . write ( ( '%s\t%s\n' % ( to_pr . encode ( 'utf-8' ) , cur_tag . encode ( 'utf-8' ) ) ) ) #NEWLINE# if ( not sequence ) : #NEWLINE# #INDENT# out_file . write ( '\n' ) #NEWLINE# #UNINDENT# #UNINDENT# generate_crf_template ( feature_num , template_name = 'template' , tmp_dir = tmp_dir ) #NEWLINE# out_file . close ( ) #NEWLINE# return ( out_file_name , tag_set )