Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To find the number of syllables in a word

Tags:

python

nltk

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 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?

like image 998
aks Avatar asked Feb 23 '11 05:02

aks


People also ask

What is the number of syllables in Example?

Wondering why example is 3 syllables?


1 Answers

you need to put quotes around the word 'arithmetic'

like image 147
Thomas Dignan Avatar answered Oct 03 '22 15:10

Thomas Dignan