noun module

class inflex.noun.Noun[source]

Bases: inflex.term.Term

Class for detecting and converting to noun forms.

__init__(term: str)[source]

Creates a Noun instance with detection and conversion methods.

Examples

>>> noun = Noun("brother")
>>> noun.plural()
'brothers'
>>> noun.classical().plural()
'brethren'
>>> noun.is_singular()
True

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 noun is instantiated via Noun(term).

Returns

Returns True only if this noun is instantiated via Noun(term).

Return type

bool

is_singular() bool[source]

Detect whether this noun is in singular form.

Returns

True if this noun is deemed singular.

Return type

bool

is_plural() bool[source]

Detect whether this noun is in plural form.

Returns

True if this noun is deemed plural.

Return type

bool

singular(person: int = 0) str[source]

Returns this noun’s singular form.

Parameters

person (Optional[int], optional) – Represents the grammatical “person” (1st, 2nd, 3rd). This option only affects personal and possessive pronouns. Defaults to 0.

Returns

This noun’s singular form.

Return type

str

plural(person: int = 0) str[source]

Returns this noun’s plural form.

Parameters

person (Optional[int], optional) – Represents the grammatical “person” (1st, 2nd, 3rd). This option only affects personal and possessive pronouns. Defaults to 0.

Returns

This noun’s plural form.

Return type

str

classical() inflex.noun.ClassicalNoun[source]

Returns an object always inflecting in the classical/unassimilated manner.

Examples

>>> Noun('cow').plural()
'cows'
>>> Noun('cow').classical().plural()
'kine'

Note

Identical to unassimilated().

Returns

A Noun object that pluralises according to classical rules.

Return type

ClassicalNoun

lemma() str[source]

Return this object’s lemma form.

Examples

>>> Noun('books').lemma()
'book'
Returns

This object’s lemma form.

Return type

str

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)
indef_article() str[source]

Return the correct indefinite article (“a” or “an”) for word.

Parameters

word (str) – Input word or collocation.

Returns

Either “a” or “an”.

Return type

str

indefinite(count: Optional[int] = 1) str[source]

Prepend “a” or “an” or the number to the correct form of this Noun.

Examples

>>> noun = Noun("book")
>>> noun.indefinite(count = 1)
'a book'
>>> noun.indefinite(count = 3)
'3 books'

TODO: self.term versus self.singular()

Parameters

count (Optional[int], optional) – The number of objects on which this verb applies. Defaults to 1.

Returns

The singular if count == 1, and the plural otherwise.

Return type

str

is_adj() bool

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_verb() bool

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

unassimilated() inflex.term.Term

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

Term

class inflex.noun.ClassicalNoun[source]

Bases: inflex.noun.Noun

Subclass of noun for detecting and converting to noun forms, with a classical plural.

__init__(term: str, modern: inflex.noun.Noun) None[source]

Creates ClassicalNoun instance with detection and conversion methods.

Note

Capitalisation and whitespace will be preserved between input term and output generated via e.g. singular.

The main difference to Noun is that the plural method is overridden. Another difference is that this class is generally initialized using the singular form of the Noun. as_regex() and __repr__() are also overridden.

Parameters
  • term (str) – Input word or collocation.

  • modern (Noun) – The Noun object from which classical() or unassimilated was called to create this object.

Return type

None

classical() inflex.noun.ClassicalNoun[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

Term

modern() inflex.noun.Noun[source]

Returns the non-classical modern version of this Noun.

Examples

>>> noun = Noun('cow')
>>> noun == noun.classical().modern()
True
Returns

The Noun object that will pluralize according to modern rules.

Return type

Noun

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('brother').classical().as_regex()
re.compile('brother|brethren', re.IGNORECASE)
indef_article() str

Return the correct indefinite article (“a” or “an”) for word.

Parameters

word (str) – Input word or collocation.

Returns

Either “a” or “an”.

Return type

str

indefinite(count: Optional[int] = 1) str

Prepend “a” or “an” or the number to the correct form of this Noun.

Examples

>>> noun = Noun("book")
>>> noun.indefinite(count = 1)
'a book'
>>> noun.indefinite(count = 3)
'3 books'

TODO: self.term versus self.singular()

Parameters

count (Optional[int], optional) – The number of objects on which this verb applies. Defaults to 1.

Returns

The singular if count == 1, and the plural otherwise.

Return type

str

is_adj() bool

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_noun() bool

Returns True only if this noun is instantiated via Noun(term).

Returns

Returns True only if this noun is instantiated via Noun(term).

Return type

bool

is_plural() bool

Detect whether this noun is in plural form.

Returns

True if this noun is deemed plural.

Return type

bool

is_singular() bool

Detect whether this noun is in singular form.

Returns

True if this noun is deemed singular.

Return type

bool

is_verb() bool

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

lemma() str

Return this object’s lemma form.

Examples

>>> Noun('books').lemma()
'book'
Returns

This object’s lemma form.

Return type

str

plural(person: int = 0) str

Returns this noun’s plural form.

Parameters

person (Optional[int], optional) – Represents the grammatical “person” (1st, 2nd, 3rd). This option only affects personal and possessive pronouns. Defaults to 0.

Returns

This noun’s plural form.

Return type

str

singular(person: int = 0) str

Returns this noun’s singular form.

Parameters

person (Optional[int], optional) – Represents the grammatical “person” (1st, 2nd, 3rd). This option only affects personal and possessive pronouns. Defaults to 0.

Returns

This noun’s singular form.

Return type

str

unassimilated() inflex.term.Term

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

Term