【问题标题】:To find the number of syllables in a word查找单词中的音节数
【发布时间】:2011-07-02 12:43:42
【问题描述】:

我需要使用 NLTK 找出英语单词中的音节数。这是我到目前为止的代码:

import 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)

函数调用后,我得到一个名称错误,说算术没有定义。 有人可以帮我找出代码中的错误吗?

【问题讨论】:

    标签: python nltk


    【解决方案1】:

    你需要在“算术”这个词周围加上引号

    【讨论】:

      猜你喜欢
      • 2022-07-03
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-29
      • 1970-01-01
      • 2017-10-13
      相关资源
      最近更新 更多