natural language toolkit wordnet stemmer interface c 20012023 nltk project steven bird stevenbird1gmail com edward loper edlopergmail com url https www nltk org for license information see license txt wordnet lemmatizer lemmatize using wordnet s builtin morphy function returns the input word unchanged if it cannot be found in wordnet from nltk stem import wordnetlemmatizer wnl wordnetlemmatizer printwnl lemmatize dogs dog printwnl lemmatize churches church printwnl lemmatize aardwolves aardwolf printwnl lemmatize abaci abacus printwnl lemmatize hardrock hardrock lemmatize word using wordnet s builtin morphy function returns the input word unchanged if it cannot be found in wordnet param word the input word to lemmatize type word str param pos the part of speech tag valid options are n for nouns v for verbs a for adjectives r for adverbs and s for satellite adjectives type pos str return the lemma of word for the given pos natural language toolkit wordnet stemmer interface c 2001 2023 nltk project steven bird stevenbird1 gmail com edward loper edloper gmail com url https www nltk org for license information see license txt wordnet lemmatizer lemmatize using wordnet s built in morphy function returns the input word unchanged if it cannot be found in wordnet from nltk stem import wordnetlemmatizer wnl wordnetlemmatizer print wnl lemmatize dogs dog print wnl lemmatize churches church print wnl lemmatize aardwolves aardwolf print wnl lemmatize abaci abacus print wnl lemmatize hardrock hardrock lemmatize word using wordnet s built in morphy function returns the input word unchanged if it cannot be found in wordnet param word the input word to lemmatize type word str param pos the part of speech tag valid options are n for nouns v for verbs a for adjectives r for adverbs and s for satellite adjectives type pos str return the lemma of word for the given pos
from nltk.corpus import wordnet as wn


class WordNetLemmatizer:
    

    def lemmatize(self, word: str, pos: str = "n") -> str:
        
        lemmas = wn._morphy(word, pos)
        return min(lemmas, key=len) if lemmas else word

    def __repr__(self):
        return "<WordNetLemmatizer>"