Writing a function that lemmatizes all words in a sentence by considering their POS tags

168 views Asked by At

I am trying to use wordnet lemmatizer in python and i have noticed that the default pos tag is NOUN and that it does not output the correct lemma for a verb, unless the pos tag is explicitly specified as VERB.

How can i create a function

proper_lemmatize_sentence(raw1, True)

so that if its "True" it gives the lemma according to its pos tag or else if its "False" it gives the default lemma for pos=n

i have tried the following

import nltk
from nltk.corpus import wordnet
raw1 = 'Corpus linguistics proposes that reliable language analysis is more feasible with corpora collected in the field, in their natural contexts, and with minimal experimental-interference.'
tokens = nltk.word_tokenize(raw1)
wnl = nltk.WordNetLemmatizer()
lemmatized_tokens = [wnl.lemmatize(tk) for tk in tokens]
print(lemmatized_tokens)
0

There are 0 answers