Created
March 29, 2014 16:08
-
-
Save uttamg911/9857258 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
# Imports Natual Language Tool Kit | |
import nltk | |
# Imports CMU Pronunciation Dictionary from NLTK Corpus | |
from nltk.corpus import cmudict | |
# Imports Random | |
import random | |
full_dict = cmudict.entries()[:] | |
l = 0 | |
w = 0 | |
wrd = "" | |
s = "" | |
while l < 3: # 3 lines | |
while w < 3: # 3 letters for each word | |
r = full_dict[random.randint(0, len(full_dict)-1)] # randomly picks a word and its pronunciation as a list | |
q = r[1] # gets the word's pronunciation | |
wrd = wrd + " " + r[0] | |
for p in q: | |
if ( len(p) !=1 and q.index(p) != 0 and q.index(p) != len(q)-1 ): # checks for boundary conditions | |
s = s + " " + q[q.index(p)-1] + "-" + p + "-" + q[q.index(p)+1] # constructs the line | |
w += 1 | |
print wrd + ":" + s | |
w = 0 | |
s = "" | |
wrd = "" | |
l += 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment