en_us_normalization.production.verbalize.MoneyFst

class en_us_normalization.production.verbalize.MoneyFst(cardinal: Optional[CardinalFst] = None, decimal: Optional[DecimalFst] = None)[source]

Finite state transducer for verbalizing money. During tokenization, amount is split into integer and fraction part. During verbalization, those are expanded reusing transducers from cardinal verbalizer. The reason not to use decimal transducer, is because fraction part of money behaves slightly differently. For instance:

“integer_part:12|fractional_part:5|” should be “twelve dollars fifty cents”.

The only task is to expand currency symbol appropriately: into major and minor versions. This is done using expansions provided in the data files:

  • data/currency/major.tsv

  • data/currency/minor.tsv - it is not so straightforward to convert plural/singular, so two data files are maintained.

  • data/currency/minor_plural.tsv

For example “$” is expanded to “dollars” and “cents”. Additionally, money verbalizer has to take care of changing form of major/minor currencies to plural or singular depending on the predecessing number.

Examples of input/output strings:

  • money|integer_part:12|currency:$|fractional_part:05|currency:$| -> twelve dollars and five cents

__init__(cardinal: Optional[CardinalFst] = None, decimal: Optional[DecimalFst] = None)[source]

constructor of money verbalizer

Parameters
cardinal: CardinalFst

reusing cardinal transducer to expand integer/fraction parts of money

decimal: DecimalFst

reusing decimal transducer to expand money when there is explicit quantity