Last active
December 24, 2015 13:09
-
-
Save josephcc/6802930 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from operator import attrgetter | |
# Don't save the symbol tables, use the provided table ascii.syms! | |
#def SaveFST(t, txtFstFileName, isymFile, osymFile): | |
def SaveFST(t, txtFstFileName): | |
#SaveSym(t.isyms, isymFile) | |
#SaveSym(t.osyms, osymFile) | |
f = open(txtFstFileName, 'w+'); | |
states = sorted(t.states, key=attrgetter('initial'), reverse=True) | |
for state in states: | |
for arc in state.arcs: | |
itext = ReplaceEps(t.isyms.find(arc.ilabel)) | |
otext = ReplaceEps(t.osyms.find(arc.olabel)) | |
f.write('{}\t{}\t{}\t{}\n'.format(state.stateid, arc.nextstate, itext, otext)) | |
if state.final: | |
f.write('{}\n'.format(state.stateid)) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment