Skip to content

Instantly share code, notes, and snippets.

@josephcc
Last active December 24, 2015 13:09
Show Gist options
  • Save josephcc/6802930 to your computer and use it in GitHub Desktop.
Save josephcc/6802930 to your computer and use it in GitHub Desktop.
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