Skip to content

Commit

Permalink
Further simplify morphy()
Browse files Browse the repository at this point in the history
  • Loading branch information
ekaf committed Jan 14, 2024
1 parent 2fa4924 commit b553ace
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions nltk/corpus/reader/wordnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ def _next_token():
# map lemmas and parts of speech to synsets
self._lemma_pos_offset_map[lemma][pos] = synset_offsets
if pos == ADJ:
# Duplicate all adjectives indiscriminately?:
self._lemma_pos_offset_map[lemma][ADJ_SAT] = synset_offsets

def _load_exception_map(self):
Expand Down Expand Up @@ -2018,7 +2019,8 @@ def morphy(self, form, pos=None, check_exceptions=True):
"""
Find a possible base form for the given form, with the given
part of speech, by checking WordNet's list of exceptional
forms, or by substituting affixes for this part of speech.
forms, or by substituting suffixes for this part of speech.
If pos=None, try every part of speech until finding lemmas.
Return the first form found in WordNet, or eventually None.
>>> from nltk.corpus import wordnet as wn
Expand All @@ -2035,19 +2037,11 @@ def morphy(self, form, pos=None, check_exceptions=True):
book
>>> wn.morphy('book', wn.ADJ)
"""

if pos is None:
posl = POS_LIST
else:
posl = [pos]
analyses = []
for pos in posl:
for pos in [pos] if pos else POS_LIST:
analyses = self._morphy(form, pos, check_exceptions)
if analyses:
# Stop (don't try more parts of speech):
return analyses[0]
else:
continue
return None

MORPHOLOGICAL_SUBSTITUTIONS = {
NOUN: [
Expand Down

0 comments on commit b553ace

Please sign in to comment.