Skip to content

Instantly share code, notes, and snippets.

@tbpalsulich
Created May 15, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbpalsulich/cbbdf3468654051f7493 to your computer and use it in GitHub Desktop.
Save tbpalsulich/cbbdf3468654051f7493 to your computer and use it in GitHub Desktop.
Python script to create an edit transistor
# ε = lowercase epsilon
alphabet = "abc"
weight = {
"delete": 1.0,
"insert": 1.0,
"sub": 1.0
}
# No edit
for l in alphabet:
print "0 0 %s %s %.3f" % (l, l, 0)
# Deletes: input character, output epsilon
for l in alphabet:
print "0 0 %s ε %.3f" % (l, weight["delete"])
# Insertions: input epsilon, output character
for l in alphabet:
print "0 0 ε %s %.3f" % (l, weight["insert"])
# Substitutions: input one character, output another
for l in alphabet:
for r in alphabet:
if l is not r:
print "0 0 %s %s %.3f" % (l, r, weight["sub"])
# Final state
print 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment