开发者

To find the number of syllables in a word

开发者 https://www.devze.com 2023-02-12 14:50 出处:网络
I need to find out the number of syllables in a word from the English language using NLTK. This is the code I have so far:

I need to find out the number of syllables in a word from the English language using NLTK. This is the code I have so far:

import开发者_JAVA百科 curses 
from curses.ascii import isdigit 
import nltk
from nltk.corpus import cmudict 
d = cmudict.dict() 
def nsyl(word): 
   return [len(list(y for y in x if isdigit(y[-1]))) for x in d[word.lower()]] 

>>> nsyl(arithmetic)

After the function call, I get a Name Error saying arithmetic is not defined. Can someone help me figure out the error in the code?


you need to put quotes around the word 'arithmetic'

0

精彩评论

暂无评论...
验证码 换一张
取 消