Created
January 11, 2012 09:05
-
-
Save AlexDel/1593818 to your computer and use it in GitHub Desktop.
NLTK Ex 2.21 Write a program to guess the number of syllables contained in a text, making use of the CMU Pronouncing Dictionary
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
d = nltk.corpus.cmudict.dict() #получаем объект в виде словаря для удобного доступа | |
def count_syllables(text): #вводим текст как список слов | |
syll_text = [] #исходный массив где будут копиться слоги | |
for word in text: | |
syll_text.extend(d[word][0]) #к исходному массиву добавляем первый элемент (в случае нескольких произношений)с помощью метода extend | |
return len(syll_text)# ву-а-ля |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment