numerals

Convert numbers to number words in a number of languages. Each language has its own module. The module name is based on the ISO 639-3 code for that language. Each module contains one or more cardinal and ordinal functions and a struct function. The cardinal functions directly convert cardinal numbers to a string-like representation of their spoken form. The ordinal functions do the same but for ordinal numbers. The struct functions convert numbers to a polymorphic representation of their grammatical structure. See the Text.Numeral module for information on how to use this library.


Keywords
library, natural-language-processing, numerical, text, Propose Tags, Text.Numeral, Skip to Readme, , Index, Text.Numeral.BigNum, Text.Numeral.Entry, Text.Numeral.Exp, Text.Numeral.Grammar, Text.Numeral.Language.AFR, Text.Numeral.Language.AMP, Text.Numeral.Language.BUL, Text.Numeral.Language.CES, Text.Numeral.Language.CHN, Text.Numeral.Language.CHR, Text.Numeral.Language.CLM, Text.Numeral.Language.CRO, Text.Numeral.Language.DEU, Text.Numeral.Language.ENG, Text.Numeral.Language.EPO, Text.Numeral.Language.Entries, Text.Numeral.Language.FIN, Text.Numeral.Language.FRA, Text.Numeral.Language.FUR, Text.Numeral.Language.GLV, Text.Numeral.Language.GSW, Text.Numeral.Language.HEB, Text.Numeral.Language.HOP, Text.Numeral.Language.ITA, Text.Numeral.Language.JPN, Text.Numeral.Language.LAT, Text.Numeral.Language.LLD, Text.Numeral.Language.MLG, Text.Numeral.Language.NEN, Text.Numeral.Language.NLD, Text.Numeral.Language.NOB, Text.Numeral.Language.NQM, Text.Numeral.Language.OJI, Text.Numeral.Language.PDC, Text.Numeral.Language.POL, Text.Numeral.Language.POR, Text.Numeral.Language.RUS, Text.Numeral.Language.SCO, Text.Numeral.Language.SPA, Text.Numeral.Language.SWE, Text.Numeral.Language.TUR, Text.Numeral.Language.WOL, Text.Numeral.Language.YOR, Text.Numeral.Language.ZHO, Text.Numeral.Misc, Text.Numeral.Render, Text.Numeral.Rules, More info, numerals-0.4.1.tar.gz, browse, Package description, Package maintainers, RoelVanDijk, edit package information , 0.4
License
BSD-3-Clause
Install
cabal install numerals-0.4.1

Documentation

Numerals

Convert numbers to number words in a number of languages. Each language has its own module. The module name is based on the ISO 639-3 code for that language. Each module contains one or more functions to convert numerical values to numerals. Several types of numerals are supported. But not every type is supported by every language. Some because they do not occur in that language. Others because they are not yet defined in this package.

  • Cardinal numerals

    Describe quantity - one, two, three, etc.

  • Ordinal numerals

    Describe position in a sequential order - first, second, third, etc.

  • Partitive numerals

    Describe division into fractions - two thirds, three quarters.

  • Multiplicative numerals

    Describe repetition, how many time - once, twice, thrice.

Inflection

In some languages number words are modified based on a number of grammatical categories such as gender or number. For instance, in Spanish, the numeral for the quantity '1' can be one of uno, un or una depending on whether it is of the neuter, masculine or feminine gender. In order to support this process every conversion function takes an inflection parameter which defines the grammatical state.

Inflections are not concrete types, but polymorphic parameters constrained by type classes. Use the reified inflection type provided by the numerals-base package to get a concrete value:

>>> import Text.Numeral.Grammar.Reified ( defaultInflection )

Numeral structure

The struct functions convert numbers to a polymorphic representation of their grammatical structure. They are found in every language module.

Examples

The use of this package is best understood with some examples. First some English number names, both British and US variants:

>>> import qualified Text.Numeral.Language.ENG as ENG
>>> ENG.gb_cardinal defaultInflection 123 :: Maybe Text
Just "one hundred and twenty-three"
>>> ENG.us_cardinal defaultInflection (10^50 + 42) :: Maybe Text
Just "one hundred quindecillion forty-two"

French, which contains some traces of a base 20 system:

>>> import qualified Text.Numeral.Language.FRA as FRA
>>> FRA.cardinal defaultInflection (-99) :: Maybe Text
Just "moins quatre-vingt-dix-neuf"

Conversions can fail. Alamblak, a language spoken by a few people in Papua New Guinea, has no representation for negative numbers:

>>> import qualified Text.Numeral.Language.AMP as AMP
>>> AMP.cardinal defaultInflection (-3) :: Maybe Text
Nothing

Some languages have multiple scripts and methods for writing number names. Take Chinese for example, which can be written using Han characters or transcribed to the Latin script using Pinyin.

Traditional Chinese characters:

>>> import qualified Text.Numeral.Language.ZHO as ZHO
>>> ZHO.trad_cardinal defaultInflection 123456 :: Maybe Text
Just "十二萬三千四百五十六"

Simplified characters for use in financial contexts:

>>> ZHO.finance_simpl_cardinal defaultInflection 123456 :: Maybe Text
Just "拾贰万参仟肆伯伍拾陆"

Transcribed using Pinyin:

>>> ZHO.pinyin_cardinal defaultInflection 123456 :: Maybe Texto
Just "shíèrwàn sānqiān sìbǎi wǔshí liù"

In Spanish the word for the quantity '1' differs based on its gender. We convey the gender via the inflection parameter:

>>> import Text.Numeral.Grammar ( masculine, feminine, neuter )
>>> import Text.Numeral.Grammar ( defaultInflection )
>>> import qualified Text.Numeral.Language.SPA as SPA
>>> SPA.cardinal (masculine defaultInflection) 1 :: Maybe Text
Just "un"
>>> SPA.cardinal (feminine defaultInflection) 1 :: Maybe Text
Just "una"
>>> SPA.cardinal (neuter defaultInflection) 1 :: Maybe Text
Just "uno"

Using the struct functions you can see the grammatical structure of number names. Because the results of these functions are polymorphic you need to specify a specific type.

>>> import qualified Text.Numeral.Language.NLD as NLD
>>> import Text.Numeral.Exp ( Exp, showExp )
>>> showExp (NLD.struct 123 :: Exp
Add (Lit 100) (Add (Lit 3) (Mul (Lit 2) (Lit 10)))

Compare with:

>>> NLD.cardinal defaultInflection 123 :: Maybe Text
Just "honderddrieëntwintig"

100 (honderd) + (3 (drie) + (ën) 2 (twin) * 10 (tig))