nltk.stem.wordnet module¶
- class nltk.stem.wordnet.WordNetLemmatizer[source]¶
Bases:
object
WordNet Lemmatizer
Provides 3 lemmatizer modes: _morphy(), morphy() and lemmatize().
lemmatize() is a permissive wrapper around _morphy(). It returns the shortest lemma found in WordNet, or the input string unchanged if nothing is found.
>>> from nltk.stem import WordNetLemmatizer as wnl >>> print(wnl().lemmatize('us', 'n')) u
>>> print(wnl().lemmatize('Anythinggoeszxcv')) Anythinggoeszxcv
- lemmatize(word: str, pos: str = 'n') str [source]¶
Lemmatize word by picking the shortest of the possible lemmas, using the wordnet corpus reader’s built-in _morphy function. Returns the input word unchanged if it cannot be found in WordNet.
>>> from nltk.stem import WordNetLemmatizer as wnl >>> 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
- Parameters:
word (str) – The input word to lemmatize.
pos (str) – 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.
- Returns:
The shortest lemma of word, for the given pos.
- Return type:
str
- morphy(form, pos=None, check_exceptions=True)[source]¶
morphy() is a restrictive wrapper around _morphy(). It returns the first lemma found in WordNet, or None if no lemma is found.
>>> from nltk.stem import WordNetLemmatizer as wnl >>> print(wnl().morphy('us', 'n')) us
>>> print(wnl().morphy('catss')) None