Skip to content

Instantly share code, notes, and snippets.

@EnkrateiaLucca
Created July 24, 2020 17:27
Show Gist options
  • Save EnkrateiaLucca/1c7a6c14fb008ef8d7fe14b23f87fb6a to your computer and use it in GitHub Desktop.
Save EnkrateiaLucca/1c7a6c14fb008ef8d7fe14b23f87fb6a to your computer and use it in GitHub Desktop.
lemmatization
import nltk
from nltk.stem import WordNetLemmatizer
# Instantiating the lemmatizer class from nltk
wordnet_lemmatizer = WordNetLemmatizer()
# List of verbs and adjectives to feed to the lemmatizer
verbs = ["thinking", "wondering", "reflecting"]
adjectives = ["better", "brighter", "smarter"]
# Making a nice print for both
print("Verbs")
print("{0:20}{1:20}".format("Word","Lemma"))
for verb in verbs:
print ("{0:20}{1:20}".format(verb,wordnet_lemmatizer.lemmatize(verb, pos="v")))
print("\n")
print("Adjectives")
print("{0:20}{1:20}".format("Word","Lemma"))
for adj in adjectives:
print ("{0:20}{1:20}".format(adj,wordnet_lemmatizer.lemmatize(adj, pos="a")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment