langtest.utils.number_to_word.ConvertNumberToWord#

class ConvertNumberToWord#

Bases: object

Converts a number to its corresponding word representation.

__init__() None#

Constructor method

Methods

__init__()

Constructor method

enword(num, group)

Converts a numeric string to its word representation based on the specified grouping.

group1bsub(mo)

Substitutes a matched pattern from group 1b with its word representation.

group1sub(mo)

Substitutes a matched pattern from group 1 with its word representation.

group2sub(mo)

Substitutes a matched pattern from group 2 with its word representation.

group3sub(mo)

Substitutes a matched pattern from group 3 with its word representation.

hundfn(hundreds, tens, units, mindex)

Constructs the word representation of a three-digit number.

hundsub(mo)

Substitution function for matching and converting a three-digit numeric group.

millfn([ind])

Retrieves the word representation of a given mill index.

number_to_words(num[, wantlist, group, ...])

Converts a number or word to its corresponding word representation.

tenfn(tens, units[, mindex])

Converts a two-digit number to its word representation.

tensub(mo)

Substitution function for matching and converting a two-digit numeric group.

unitfn(units[, mindex])

Prettify string

unitsub(mo)

Substitution function for matching and converting a one-digit numeric group.

enword(num: str, group: int) str#

Converts a numeric string to its word representation based on the specified grouping.

Parameters:
  • num (str) – The numeric string to convert.

  • group (int) – The grouping of the numeric string.

Returns:

The word representation of the numeric string.

Return type:

str

Raises:

NumOutOfRangeError – If the numeric string is out of range.

group1bsub(mo: Match) str#

Substitutes a matched pattern from group 1b with its word representation.

Parameters:

mo (Match) – The matched pattern object.

Returns:

The word representation of the matched pattern.

Return type:

str

group1sub(mo: Match) str#

Substitutes a matched pattern from group 1 with its word representation.

Parameters:

mo (Match) – The matched pattern object.

Returns:

The word representation of the matched pattern.

Return type:

str

group2sub(mo: Match) str#

Substitutes a matched pattern from group 2 with its word representation.

Parameters:

mo (Match) – The matched pattern object.

Returns:

The word representation of the matched pattern.

Return type:

str

group3sub(mo: Match) str#

Substitutes a matched pattern from group 3 with its word representation.

Parameters:

mo (Match) – The matched pattern object.

Returns:

The word representation of the matched pattern.

Return type:

str

hundfn(hundreds: int, tens: int, units: int, mindex: int) str#

Constructs the word representation of a three-digit number.

Parameters:
  • hundreds (int) – The hundreds digit.

  • tens (int) – The tens digit.

  • units (int) – The units digit.

  • mindex (int) – The mill index.

Returns:

The word representation of the three-digit number.

Return type:

str

hundsub(mo: Match) str#

Substitution function for matching and converting a three-digit numeric group.

Parameters:

mo (Match) – The matched object containing the captured groups.

Returns:

The word representation of the matched three-digit numeric group.

Return type:

str

millfn(ind: int = 0) str#

Retrieves the word representation of a given mill index.

Parameters:

ind (int) – The index of the mill.

Returns:

The word representation of the mill.

Return type:

str

Raises:

NumOutOfRangeError – If the index is out of range.

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

Converts a number or word to its corresponding word representation.

Parameters:
  • num (Union[Number, Word]) – The number or word to be converted.

  • wantlist (bool, optional) – Flag to indicate whether to return the result as a list of words. Defaults to False.

  • group (int, optional) – The group number indicating the pattern to be matched. Defaults to 0.

  • comma (Union[Falsish, str], optional) – The string to be used as a comma separator. Defaults to “,”.

  • andword (str, optional) – The word to be used as a connector between numbers. Defaults to “and”.

  • zero (str, optional) – The word representation of zero. Defaults to “zero”.

  • one (str, optional) – The word representation of one. Defaults to “one”.

  • decimal (Union[Falsish, str], optional) – The string to be used as a decimal point. Defaults to “point”.

  • threshold (Optional[int], optional) – The threshold value for stylistic conversions. Defaults to None.

Returns:

The word representation of the given number or word.

Return type:

Union[str, List[str]]

Raises:

BadChunkingOptionError – If the given group is invalid.

tenfn(tens: int, units: int, mindex: int = 0) str#

Converts a two-digit number to its word representation.

Parameters:
  • tens (int) – The tens digit.

  • units (int) – The units digit.

  • mindex (int) – The index of the mill.

Returns:

The word representation of the number.

Return type:

str

tensub(mo: Match) str#

Substitution function for matching and converting a two-digit numeric group.

Parameters:

mo (Match) – The matched object containing the captured groups.

Returns:

The word representation of the matched two-digit numeric group.

Return type:

str

unitfn(units: int, mindex: int = 0) str#

Prettify string

unitsub(mo: Match) str#

Substitution function for matching and converting a one-digit numeric group.

Parameters:

mo (Match) – The matched object containing the captured groups.

Returns:

The word representation of the matched one-digit numeric group.

Return type:

str