Last active
March 26, 2020 19:24
-
-
Save amita-shukla/451f65089e0af5edb36bd0688a0a1033 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nltk | |
nltk.download('wordnet') | |
from nltk.stem import WordNetLemmatizer | |
from nltk import word_tokenize | |
wnl = WordNetLemmatizer() | |
def lemmatize_text(text): | |
tokens = word_tokenize(text) | |
lemmatized_tokens = [wnl.lemmatize(token) for token in tokens if not (isNumber(token) and token!='.' and token!=',')] | |
lemmatized_sentence = ' '.join(lemmatized_tokens) | |
return lemmatized_sentence |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment