Created
July 24, 2020 17:27
-
-
Save EnkrateiaLucca/1c7a6c14fb008ef8d7fe14b23f87fb6a to your computer and use it in GitHub Desktop.
lemmatization
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 | |
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