I'm using WordNetLemmatizer from nltk for the first time.

I see that its not working as expected. Following is what I did -

> from nltk import WordNetLemmatizer
> lem = WordNetLemmatizer()
> lem.lemmatize("worked") # returns "worked", expected "work"
> lem.lemmatize("working") # returns "working", expected "work"
> lem.lemmatize("works") # returns "work" as expected

What I'm doing wrong here?

asked Sep 27 '13 at 02:31

Harsh%20Jha's gravatar image

Harsh Jha
21447


One Answer:

You need to specify the pos tag. By default this is set to noun, independently of what word you input.

>>> from nltk import WordNetLemmatizer
>>> from nltk.corpus import wordnet
>>> lem.lemmatize("worked", wordnet.VERB) 
'work'
>>> lem.lemmatize("working", wordnet.VERB) 
'work'
>>> lem.lemmatize("works", wordnet.VERB) 
'work'

You may use a pos tagger to determine this. See this question. Btw, maybe StackOverflow would have been a better site to ask this question.

answered Sep 28 '13 at 12:14

Maarten's gravatar image

Maarten
1315613

Your answer
toggle preview

powered by OSQA

User submitted content is under Creative Commons: Attribution - Share Alike; Other things copyright (C) 2010, MetaOptimize LLC.