Skip to content

Commit 6a981a8

Browse files
committed
Merge branch 'develop' of https://github.com/nltk/nltk into develop
2 parents aca78cb + 38fe718 commit 6a981a8

File tree

1 file changed

+39
-32
lines changed

1 file changed

+39
-32
lines changed

nltk/stem/wordnet.py

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,64 +7,71 @@
77
# URL: <https://www.nltk.org/>
88
# For license information, see LICENSE.TXT
99

10-
from nltk.corpus import wordnet as wn
11-
1210

1311
class WordNetLemmatizer:
1412
"""
1513
WordNet Lemmatizer
1614
17-
Provides 3 lemmatizer modes:
18-
19-
1. _morphy() is an alias to WordNet's _morphy lemmatizer.
20-
It returns a list of all lemmas found in WordNet.
21-
22-
>>> wnl = WordNetLemmatizer()
23-
>>> print(wnl._morphy('us', 'n'))
24-
['us', 'u']
25-
26-
2. morphy() is a restrictive wrapper around _morphy().
27-
It returns the first lemma found in WordNet,
28-
or None if no lemma is found.
15+
Provides 3 lemmatizer modes: _morphy(), morphy() and lemmatize().
2916
30-
>>> print(wnl.morphy('us', 'n'))
31-
us
32-
33-
>>> print(wnl.morphy('catss'))
34-
None
35-
36-
3. lemmatize() is a permissive wrapper around _morphy().
17+
lemmatize() is a permissive wrapper around _morphy().
3718
It returns the shortest lemma found in WordNet,
3819
or the input string unchanged if nothing is found.
3920
40-
>>> print(wnl.lemmatize('us', 'n'))
21+
>>> from nltk.stem import WordNetLemmatizer as wnl
22+
>>> print(wnl().lemmatize('us', 'n'))
4123
u
4224
43-
>>> print(wnl.lemmatize('Anythinggoeszxcv'))
25+
>>> print(wnl().lemmatize('Anythinggoeszxcv'))
4426
Anythinggoeszxcv
4527
4628
"""
4729

48-
morphy = wn.morphy
30+
def _morphy(self, form, pos, check_exceptions=True):
31+
"""
32+
_morphy() is WordNet's _morphy lemmatizer.
33+
It returns a list of all lemmas found in WordNet.
34+
35+
>>> from nltk.stem import WordNetLemmatizer as wnl
36+
>>> print(wnl()._morphy('us', 'n'))
37+
['us', 'u']
38+
"""
39+
from nltk.corpus import wordnet as wn
40+
41+
return wn._morphy(form, pos, check_exceptions)
42+
43+
def morphy(self, form, pos=None, check_exceptions=True):
44+
"""
45+
morphy() is a restrictive wrapper around _morphy().
46+
It returns the first lemma found in WordNet,
47+
or None if no lemma is found.
48+
49+
>>> from nltk.stem import WordNetLemmatizer as wnl
50+
>>> print(wnl().morphy('us', 'n'))
51+
us
52+
53+
>>> print(wnl().morphy('catss'))
54+
None
55+
"""
56+
from nltk.corpus import wordnet as wn
4957

50-
_morphy = wn._morphy
58+
return wn.morphy(form, pos, check_exceptions)
5159

5260
def lemmatize(self, word: str, pos: str = "n") -> str:
5361
"""Lemmatize `word` by picking the shortest of the possible lemmas,
5462
using the wordnet corpus reader's built-in _morphy function.
5563
Returns the input word unchanged if it cannot be found in WordNet.
5664
57-
>>> from nltk.stem import WordNetLemmatizer
58-
>>> wnl = WordNetLemmatizer()
59-
>>> print(wnl.lemmatize('dogs'))
65+
>>> from nltk.stem import WordNetLemmatizer as wnl
66+
>>> print(wnl().lemmatize('dogs'))
6067
dog
61-
>>> print(wnl.lemmatize('churches'))
68+
>>> print(wnl().lemmatize('churches'))
6269
church
63-
>>> print(wnl.lemmatize('aardwolves'))
70+
>>> print(wnl().lemmatize('aardwolves'))
6471
aardwolf
65-
>>> print(wnl.lemmatize('abaci'))
72+
>>> print(wnl().lemmatize('abaci'))
6673
abacus
67-
>>> print(wnl.lemmatize('hardrock'))
74+
>>> print(wnl().lemmatize('hardrock'))
6875
hardrock
6976
7077
:param word: The input word to lemmatize.

0 commit comments

Comments
 (0)