fstdfa.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:symautomata 作者: GeorgeArgyros 项目源码 文件源码
def save(self, txt_fst_filename):
        """
        Save the machine in the openFST format in the file denoted by
        txt_fst_filename.
        Args:
            txt_fst_filename (str): The name of the file
        Returns:
            None
        """
        txt_fst = open(txt_fst_filename, '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)
                txt_fst.write(
                    '{}\t{}\t{}\t{}\n'.format(
                        state.stateid,
                        arc.nextstate,
                        itext.encode('hex'),
                        otext.encode('hex')))
            if state.final:
                txt_fst.write('{}\n'.format(state.stateid))
        txt_fst.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号