def save(self, txt_fst_file_name):
"""
Save the machine in the openFST format in the file denoted by
txt_fst_file_name.
Args:
txt_fst_file_name (str): The output file
Returns:
None
"""
output_filename = open(txt_fst_file_name, 'w+')
states = sorted(self.states, key=attrgetter('initial'), reverse=True)
for state in states:
for arc in state.arcs:
itext = self.isyms.find(arc.ilabel)
otext = self.osyms.find(arc.ilabel)
output_filename.write(
'{}\t{}\t{}\t{}\n'.format(
state.stateid,
arc.nextstate,
itext.encode('hex'),
otext.encode('hex')))
if state.final:
output_filename.write('{}\n'.format(state.stateid))
output_filename.close()
评论列表
文章目录