def create_tagged_file(emission_params,filename,freq_words): read_file = open(filename,'rU') write_file_path = get_write_file_path(filename,'.tagged.classes') write_file = open(write_file_path, 'w') for line in read_file: if line.strip() == '': write_file.write('\n') continue word = line.strip() tag = get_tag(word,emission_params,freq_words) write_file.write(word + ' ' + tag + '\n') read_file.close() write_file.close()
def create_viterbi(emission_params,filename,freq_words): read_file = open(filename,'rU') write_file_path = get_write_file_path(filename,'.viterbi.classes') write_file = open(write_file_path, 'w') sentence = [] for line in read_file: if line.strip() == '': sentence.append('STOP') viterbi_tags = viterbi(emission_params,freq_words,sentence) write_viterbi_tags(sentence,viterbi_tags,write_file) sentence = [] else: word = line.strip() sentence.append(word) read_file.close() write_file.close()