glazing.wordnet.morphy¶
Morphological processing utilities.
morphy
¶
WordNet morphological processing (morphy).
This module implements WordNet's morphological processing algorithm for finding base forms (lemmas) of inflected words. It handles both regular inflections through suffix substitution rules and irregular forms through exception lists. It also supports collocations and multi-word expressions.
| CLASS | DESCRIPTION |
|---|---|
Morphy |
Morphological processor for finding word base forms. |
| FUNCTION | DESCRIPTION |
|---|---|
morphy |
Find base forms of a word given its POS. |
Examples:
>>> from glazing.wordnet import Morphy
>>> morphy = Morphy(loader)
>>> lemmas = morphy.morphy("running", "v")
>>> print(lemmas) # ['run']
Classes¶
Morphy(loader: WordNetLoader)
¶
Morphological processor for finding word base forms.
This class implements WordNet's morphological processing algorithm, which attempts to find the base form (lemma) of inflected words through a combination of exception list lookup and suffix substitution rules. It also handles collocations and multi-word expressions.
| PARAMETER | DESCRIPTION |
|---|---|
loader
|
WordNet loader with exception lists and lemma index.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
loader |
The WordNet loader instance.
TYPE:
|
suffix_rules |
Suffix substitution rules by POS.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
morphy |
Find base forms of a word for given POS. |
apply_rules |
Apply morphological rules to generate candidates. |
check_exceptions |
Check exception lists for irregular forms. |
Notes
The algorithm follows WordNet's morphy implementation: 1. Check if the word itself exists in WordNet 2. Check exception lists for irregular forms 3. Apply suffix substitution rules 4. For each candidate, verify it exists in WordNet
Special cases handled: - Multi-word expressions (collocations) - Nouns ending with "ful" - Verb-preposition collocations - Abbreviations with periods - Hyphenated words
Examples:
>>> morphy = Morphy(loader)
>>> morphy.morphy("children", "n")
['child']
>>> morphy.morphy("ran", "v")
['run']
>>> morphy.morphy("better", "a")
['good', 'well']
>>> morphy.morphy("attorneys general", "n")
['attorney general']
Initialize morphy with a WordNet loader.
| PARAMETER | DESCRIPTION |
|---|---|
loader
|
WordNet loader with exception lists and lemma index.
TYPE:
|
Source code in src/glazing/wordnet/morphy.py
Functions¶
apply_rules(word: str, pos: WordNetPOS) -> list[str]
¶
Apply morphological rules to generate candidates.
| PARAMETER | DESCRIPTION |
|---|---|
word
|
The word to process (lowercase).
TYPE:
|
pos
|
The part of speech.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of candidate base forms. |
Examples:
Source code in src/glazing/wordnet/morphy.py
check_exceptions(word: str, pos: WordNetPOS) -> list[str]
¶
Check exception lists for irregular forms.
| PARAMETER | DESCRIPTION |
|---|---|
word
|
The word to check (lowercase).
TYPE:
|
pos
|
The part of speech.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of base forms from exception list. |
Examples:
Source code in src/glazing/wordnet/morphy.py
get_base_forms(word: str, pos: WordNetPOS | None = None) -> list[str]
¶
Get all possible base forms of a word.
This method returns all candidates without checking if they exist in WordNet. Useful for debugging or when you want all morphological variants.
| PARAMETER | DESCRIPTION |
|---|---|
word
|
The word to process.
TYPE:
|
pos
|
Part of speech. If None, tries all POS.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of all candidate base forms. |
Examples:
>>> forms = morphy.get_base_forms("running", "v")
>>> print(forms)
['running', 'run', 'runn', 'runne']
Source code in src/glazing/wordnet/morphy.py
morphy(word: str, pos: WordNetPOS | None = None) -> list[str]
¶
Find base forms of a word for given POS.
This is the main entry point for morphological processing. It returns all possible base forms found through exception lists and suffix rules. Handles collocations and special cases.
| PARAMETER | DESCRIPTION |
|---|---|
word
|
The inflected word or collocation to process.
TYPE:
|
pos
|
Part of speech. If None, tries all POS.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of base forms found. Empty if none found. |
Examples:
Source code in src/glazing/wordnet/morphy.py
Functions¶
morphy(word: str, pos: WordNetPOS | None = None, loader: WordNetLoader | None = None) -> list[str]
¶
Find base forms of a word.
Convenience function for morphological processing.
| PARAMETER | DESCRIPTION |
|---|---|
word
|
The word to process.
TYPE:
|
pos
|
Part of speech. If None, tries all POS.
TYPE:
|
loader
|
WordNet loader. If None, uses default instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of base forms. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If loader is None and no default is available. |
Examples: