-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upload a syllable dictionary and code that will spit out the number o…
…f syllables in a single word
- Loading branch information
Showing
2 changed files
with
133,884 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
Syllable Counter | ||
file referenced is a version of a dictionary from a CMU pronnunciation guide: | ||
http://www.speech.cs.cmu.edu/cgi-bin/cmudict?in=software+design+is+hard&stress=-s | ||
Madi Wyatt | ||
""" | ||
|
||
import string | ||
|
||
#initialize the dictionary and open the CMU dictionary file | ||
pronnunciation_dict = open("syllable_dict.txt", "r") | ||
words = dict() | ||
|
||
#breakdown CMU dictionary and make a new one that gives us just the syllable count | ||
for word_entry in pronnunciation_dict: | ||
word_list = word_entry.split() | ||
words[word_list[0]] = "".join(word_list[1:]) | ||
count = 0 | ||
for i in range(0, len(words[word_list[0]])): | ||
if words[word_list[0]][i] in string.digits: | ||
count += 1 | ||
words[word_list[0]] = count | ||
|
||
#write a function that allows you to imput a word and the syllable count is output | ||
def syllable_count(word): | ||
return words[word.upper()] | ||
|
||
print(syllable_count("hello")) |
Oops, something went wrong.