Skip to content

Instantly share code, notes, and snippets.

@georgepar
Last active September 3, 2020 08:37
Show Gist options
  • Save georgepar/4cc8793e270c3486bff94993a215fb2c to your computer and use it in GitHub Desktop.
Save georgepar/4cc8793e270c3486bff94993a215fb2c to your computer and use it in GitHub Desktop.
fst_creation_example
#!/usr/bin/env bash
python create_fst.py | fstcompile --isymbols=chars.syms --osymbols=chars.syms - rosebud.bin.fst
EPS = "<epsilon>"
chars = "abcdefghijklmnopqrstuvwxyz"
def format_symbol_table_line(symbol, index):
"""Format a line of the chars.syms file
http://www.openfst.org/twiki/bin/view/FST/FstQuickTour#CreatingShellFsts
"""
pass
print(format_symbol_table_line(EPS, 0))
for i, c in enumerate(chars, 1):
print(format_symbol_table_line(c, i))
EPS = "<epsilon>"
def format_arc(src, dst, ilabel, olabel, weight=0):
"""Create an Arc, aka a line of an openfst text format file
http://www.openfst.org/twiki/bin/view/FST/FstQuickTour#CreatingShellFsts
"""
pass
# Let's create a simple acceptor for the word rosebud
letters = list('rosebud')
# Start input from state 1. State 0 will be the accept state
s = 1
for i in range(0, len(letters)):
# Not finished yet. Create an arc for letter at position i and proceed to next state
print(
format_arc(
s, s + 1, letters[i], letters[i], weight=0
)
)
s += 1
if i == len(letters) - 1:
# Reached end of word. Create epsilon transition to the accept state
print(
format_arc(
s, 0, EPS, EPS, w=0
)
)
# Print acceptor state
print(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment