term module¶
- inflex.term.list_to_generator(input_list: List[inflex.term.T]) Generator[inflex.term.T, None, None] [source]¶
Yield element from list, repeating the very last element infinitely.
- Parameters
input_list (List[T]) – List of elements.
- Yields
T – Element of input_list
- Return type
Generator[inflex.term.T, None, None]
- class inflex.term.Term[source]¶
Bases:
object
Term is the base class of the Noun, Verb, Adjective subclasses, and holds some default implementations of methods used across these subclasses.
Method docstrings from this class are inherited to the subclasses’ methods.
- __init__(term: str)[source]¶
Creates class instance with detection and conversion methods.
Note
Capitalisation and whitespace will be preserved between input term and generated output.
- Parameters
term (str) – Input word or collocation.
- is_noun() bool [source]¶
Returns True only if this object is instantiated via Noun(term).
- Returns
Returns True only if this object is instantiated via Noun(term).
- Return type
bool
- is_verb() bool [source]¶
Returns True only if this object is instantiated via Verb(term).
- Returns
Returns True only if this object is instantiated via Verb(term).
- Return type
bool
- is_adj() bool [source]¶
Returns True only if this object is instantiated via Adjective(term).
- Returns
Returns True only if this object is instantiated via Adjective(term).
- Return type
bool
- is_singular() bool [source]¶
Detect whether this object is in singular form.
- Returns
True if this object is deemed singular.
- Return type
bool
- is_plural() bool [source]¶
Detect whether this object is in plural form.
- Returns
True if this object is deemed plural.
- Return type
bool
- singular(person: int = 0) str [source]¶
Returns this object’s singular form.
- Parameters
person (Optional[int], optional) – Represents the grammatical “person” (1st, 2nd, 3rd). This option only affects personal and possessive pronouns, possessive adjectives, and verbs. Defaults to 0.
- Returns
This object’s singular form.
- Return type
str
- plural(person: int = 0) str [source]¶
Returns this object’s plural form.
- Parameters
person (Optional[int], optional) – Represents the grammatical “person” (1st, 2nd, 3rd). This option only affects personal and possessive pronouns, possessive adjectives, and verbs. Defaults to 0.
- Returns
This object’s plural form.
- Return type
str
- lemma() str [source]¶
Return this object’s lemma form.
- Returns
This object’s lemma form.
- Return type
str
- classical() inflex.term.Term [source]¶
Returns an object always inflecting in the classical/unassimilated manner.
Examples
>>> Noun('cow').plural() 'cows' >>> Noun('cow').unassimilated().plural() 'kine'
Note
Identical to unassimilated().
- Returns
A Term object, or a subclass thereof.
- Return type
- unassimilated() inflex.term.Term [source]¶
Returns an object always inflecting in the classical/unassimilated manner.
Examples
>>> Noun('cow').plural() 'cows' >>> Noun('cow').unassimilated().plural() 'kine'
Note
Identical to classical().
- Returns
A Term object, or a subclass thereof.
- Return type
- as_regex() Pattern[str] [source]¶
Returns a re.Pattern which case-insensitively matches any inflected form of the word.
- Returns
- Compiled regex object which case-insensitively matches any inflected form
of the word.
- Return type
re.Pattern
Examples
>>> Noun('cherub').as_regex() re.compile('cherubs|cherubim|cherub', re.IGNORECASE) >>> Verb('eat').as_regex() re.compile('eats|eating|eaten|eat|ate', re.IGNORECASE)