Welcome to inflect documentation!

methods:

classical inflect plural plural_noun plural_verb plural_adj singular_noun no num a an compare compare_nouns compare_verbs compare_adjs present_participle ordinal number_to_words join defnoun defverb defadj defa defan

INFLECTIONS: classical inflect

plural plural_noun plural_verb plural_adj singular_noun compare no num a an present_participle

PLURALS: classical inflect

plural plural_noun plural_verb plural_adj singular_noun no num compare compare_nouns compare_verbs compare_adjs

COMPARISONS: classical

compare compare_nouns compare_verbs compare_adjs

ARTICLES: classical inflect num a an

NUMERICAL: ordinal number_to_words

USER_DEFINED: defnoun defverb defadj defa defan

Exceptions:

UnknownClassicalModeError BadNumValueError BadChunkingOptionError NumOutOfRangeError BadUserDefinedPatternError BadRcFileError BadGenderError

exception inflect.BadChunkingOptionError

Bases: Exception

exception inflect.BadGenderError

Bases: Exception

exception inflect.BadNumValueError

Bases: Exception

exception inflect.BadRcFileError

Bases: Exception

exception inflect.BadUserDefinedPatternError

Bases: Exception

exception inflect.NumOutOfRangeError

Bases: Exception

exception inflect.UnknownClassicalModeError

Bases: Exception

class inflect.Words(orig)

Bases: str

first: str
last: str
inflect.bysize(words: Iterable[str])Dict[int, set]

take a list of words and return a dict of sets sorted by word length e.g. ret[3]=set([‘ant’, ‘cat’, ‘dog’, ‘pig’]) ret[4]=set([‘frog’, ‘goat’]) ret[5]=set([‘horse’]) ret[8]=set([‘elephant’])

inflect.enclose(s: str)str
class inflect.engine

Bases: object

a(text: str, count: int = 1)str

Return the appropriate indefinite article followed by text.

The indefinite article is either ‘a’ or ‘an’.

If count is not one, then return count followed by text instead of ‘a’ or ‘an’.

Whitespace at the start and end is preserved.

an(text: str, count: int = 1)str

Return the appropriate indefinite article followed by text.

The indefinite article is either ‘a’ or ‘an’.

If count is not one, then return count followed by text instead of ‘a’ or ‘an’.

Whitespace at the start and end is preserved.

checkpat(pattern: Optional[str])

check for errors in a regex pattern

checkpatplural(pattern: str)

check for errors in a regex replace pattern

classical(**kwargs)

turn classical mode on and off for various categories

turn on all classical modes: classical() classical(all=True)

turn on or off specific claassical modes: e.g. classical(herd=True) classical(names=False)

By default all classical modes are off except names.

unknown value in args or key in kwargs rasies exception: UnknownClasicalModeError

compare(word1: str, word2: str)Union[str, bool]

compare word1 and word2 for equality regardless of plurality

return values: eq - the strings are equal p:s - word1 is the plural of word2 s:p - word2 is the plural of word1 p:p - word1 and word2 are two different plural forms of the one word False - otherwise

compare_adjs(word1: str, word2: str)Union[str, bool]

compare word1 and word2 for equality regardless of plurality word1 and word2 are to be treated as adjectives

return values: eq - the strings are equal p:s - word1 is the plural of word2 s:p - word2 is the plural of word1 p:p - word1 and word2 are two different plural forms of the one word False - otherwise

compare_nouns(word1: str, word2: str)Union[str, bool]

compare word1 and word2 for equality regardless of plurality word1 and word2 are to be treated as nouns

return values: eq - the strings are equal p:s - word1 is the plural of word2 s:p - word2 is the plural of word1 p:p - word1 and word2 are two different plural forms of the one word False - otherwise

compare_verbs(word1: str, word2: str)Union[str, bool]

compare word1 and word2 for equality regardless of plurality word1 and word2 are to be treated as verbs

return values: eq - the strings are equal p:s - word1 is the plural of word2 s:p - word2 is the plural of word1 p:p - word1 and word2 are two different plural forms of the one word False - otherwise

defa(pattern: str)int

Define the indefinate article as ‘a’ for words matching pattern.

defadj(singular: str, plural: str)int

Set the adjective plural of singular to plural.

defan(pattern: str)int

Define the indefinate article as ‘an’ for words matching pattern.

defnoun(singular: str, plural: str)int

Set the noun plural of singular to plural.

defverb(s1: str, p1: str, s2: str, p2: str, s3: str, p3: str)int

Set the verb plurals for s1, s2 and s3 to p1, p2 and p3 respectively.

Where 1, 2 and 3 represent the 1st, 2nd and 3rd person forms of the verb.

deprecated_methods = {'numwords': 'number_to_words', 'pl': 'plural', 'pladj': 'plural_adj', 'pladjequal': 'compare_adjs', 'plequal': 'compare', 'plnoun': 'plural_noun', 'plnounequal': 'compare_nouns', 'plverb': 'plural_verb', 'plverbequal': 'compare_verbs', 'prespart': 'present_participle', 'sinoun': 'single_noun', 'wordlist': 'join'}
enword(num: str, group: int)str
gender(gender: str)

set the gender for the singular of plural pronouns

can be one of: ‘neuter’ (‘they’ -> ‘it’) ‘feminine’ (‘they’ -> ‘she’) ‘masculine’ (‘they’ -> ‘he’) ‘gender-neutral’ (‘they’ -> ‘they’) ‘feminine or masculine’ (‘they’ -> ‘she or he’) ‘masculine or feminine’ (‘they’ -> ‘he or she’)

get_count(count: Optional[Union[str, int]] = None)Union[str, int]
group1bsub(mo: Match)str
group1sub(mo: Match)str
group2sub(mo: Match)str
group3sub(mo: Match)str
hundfn(hundreds: int, tens: int, units: int, mindex: int)str
hundsub(mo: Match)str
inflect(text: str)str

Perform inflections in a string.

e.g. inflect(‘The plural of cat is plural(cat)’) returns ‘The plural of cat is cats’

can use plural, plural_noun, plural_verb, plural_adj, singular_noun, a, an, no, ordinal, number_to_words, and prespart

join(words: Optional[List[str]], sep: Optional[str] = None, sep_spaced: bool = True, final_sep: Optional[str] = None, conj: str = 'and', conj_spaced: bool = True)str

Join words into a list.

e.g. join([‘ant’, ‘bee’, ‘fly’]) returns ‘ant, bee, and fly’

options: conj: replacement for ‘and’ sep: separator. default ‘,’, unless ‘,’ is in the list then ‘;’ final_sep: final separator. default ‘,’, unless ‘,’ is in the list then ‘;’ conj_spaced: boolean. Should conj have spaces around it

millfn(ind: int = 0)str
no(text: str, count: Optional[Union[str, int]] = None)str

If count is 0, no, zero or nil, return ‘no’ followed by the plural of text.

If count is one of:

1, a, an, one, each, every, this, that

return count followed by text.

Otherwise return count follow by the plural of text.

In the return value count is always followed by a space.

Whitespace at the start and end is preserved.

num(count: Optional[int] = None, show: Optional[int] = None)str

Set the number to be used in other method calls.

Returns count.

Set show to False to return ‘’ instead.

number_to_words(num: Union[int, str], wantlist: bool = False, group: int = 0, comma: str = ',', andword: str = 'and', zero: str = 'zero', one: str = 'one', decimal: str = 'point', threshold: Optional[int] = None)Union[str, List[str]]

Return a number in words.

group = 1, 2 or 3 to group numbers before turning into words comma: define comma andword: word for ‘and’. Can be set to ‘’.

e.g. “one hundred and one” vs “one hundred one”

zero: word for ‘0’ one: word for ‘1’ decimal: word for decimal point threshold: numbers above threshold not turned into words

parameters not remembered from last call. Departure from Perl version.

ordinal(num: Union[int, str])str

Return the ordinal of num.

num can be an integer or text

e.g. ordinal(1) returns ‘1st’ ordinal(‘one’) returns ‘first’

partition_word(text: str)Tuple[str, str, str]
plural(text: str, count: Optional[Union[str, int]] = None)str

Return the plural of text.

If count supplied, then return text if count is one of:

1, a, an, one, each, every, this, that

otherwise return the plural.

Whitespace at the start and end is preserved.

plural_adj(text: str, count: Optional[str] = None)str

Return the plural of text, where text is an adjective.

If count supplied, then return text if count is one of:

1, a, an, one, each, every, this, that

otherwise return the plural.

Whitespace at the start and end is preserved.

plural_noun(text: str, count: Optional[Union[str, int]] = None)str

Return the plural of text, where text is a noun.

If count supplied, then return text if count is one of:

1, a, an, one, each, every, this, that

otherwise return the plural.

Whitespace at the start and end is preserved.

plural_verb(text: str, count: Optional[Union[str, int]] = None)str

Return the plural of text, where text is a verb.

If count supplied, then return text if count is one of:

1, a, an, one, each, every, this, that

otherwise return the plural.

Whitespace at the start and end is preserved.

postprocess(orig: str, inflected)str
present_participle(word: str)str

Return the present participle for word.

word is the 3rd person singular verb.

singular_noun(text: str, count: Optional[Union[str, int]] = None, gender: Optional[str] = None)Union[str, bool]

Return the singular of text, where text is a plural noun.

If count supplied, then return the singular if count is one of:

1, a, an, one, each, every, this, that or if count is None

otherwise return text unchanged.

Whitespace at the start and end is preserved.

>>> p = engine()
>>> p.singular_noun('horses')
'horse'
>>> p.singular_noun('knights')
'knight'

Returns False when a singular noun is passed.

>>> p.singular_noun('horse')
False
>>> p.singular_noun('knight')
False
>>> p.singular_noun('soldier')
False
tenfn(tens, units, mindex=0)
tensub(mo: Match)str
ud_match(word: str, wordlist: List[str])Optional[str]
unitfn(units: int, mindex: int = 0)str
unitsub(mo: Match)str
inflect.get_si_pron(thecase, word, gender)
inflect.joinstem(cutpoint: Optional[int] = 0, words: Optional[Iterable[str]] = None)str

join stem of each word in words into a string for regex each word is truncated at cutpoint cutpoint is usually negative indicating the number of letters to remove from the end of each word

e.g. joinstem(-2, [“ephemeris”, “iris”, “.*itis”]) returns (?:ephemer|ir|.*it)

inflect.make_pl_si_lists(lst: Iterable[str], plending: str, siendingsize: Optional[int], dojoinstem: bool = True)

given a list of singular words: lst an ending to append to make the plural: plending the number of characters to remove from the singular

before appending plending: siendingsize

a flag whether to create a joinstem: dojoinstem

return: a list of pluralised words: si_list (called si because this is what you need to

look for to make the singular)

the pluralised words as a dict of sets sorted by word length: si_bysize the singular words as a dict of sets sorted by word length: pl_bysize if dojoinstem is True: a regular expression that matches any of the stems: stem

inflect.print3(txt: str)

Indices and tables