Created
January 19, 2012 15:55
-
-
Save dggoldst/1640724 to your computer and use it in GitHub Desktop.
Generate a number for every English word via the digit sound method. See http://www.decisionsciencenews.com/2012/01/17/some-code-to-help-you-remember-numbers/
This file contains hidden or 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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import re | |
fh = open('cmudict-0.4.scm', 'r') | |
adict = {} | |
wl = open('wordlist.txt') | |
line = wl.readline() | |
while line: | |
line = line.strip() | |
adict[line] = 1 | |
line = wl.readline() | |
mapper = { | |
's': '0', | |
'z': '0', | |
't': '1', | |
'd': '1', | |
'dh': '1', | |
'th': '1', | |
'n': '2', | |
'm': '3', | |
'r': '4', | |
'er0': '4', | |
'er1': '4', | |
'l': '5', | |
'jh': '6', | |
'sh': '6', | |
'ch': '6', | |
'zh': '6', | |
'k': '7', | |
'g': '7', | |
'f': '8', | |
'v': '8', | |
'p': '9', | |
'b': '9', | |
'ng': '27', | |
} | |
line = fh.readline() | |
while line: | |
m = re.match(r"\(\"(\w+)\" (\w+) \((.*)\)\)\n", | |
line) | |
if m is not None: | |
word = m.group(1) | |
alist = m.group(3).split(' ') | |
number = ''.join([mapper.get(i, '') for i in | |
alist]) | |
if number and adict.has_key(word): | |
print '%s\t%s' % (word, number) | |
line = fh.readline() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment