Num2Word

This tutorial is available as an IPython notebook at Malaya/example/num2word.

[3]:
import malaya
/Users/huseinzolkepli/Documents/Malaya/malaya/preprocessing.py:259: FutureWarning: Possible nested set at position 2289
  self.tok = re.compile(r'({})'.format('|'.join(pipeline)))

To cardinal

def to_cardinal(number):
    """
    Translate from number input to cardinal text representation

    Parameters
    ----------
    number: real number

    Returns
    -------
    result: str
        cardinal representation
    """
[4]:
malaya.num2word.to_cardinal(123456789)
[4]:
'seratus dua puluh tiga juta empat ratus lima puluh enam ribu tujuh ratus lapan puluh sembilan'
[5]:
malaya.num2word.to_cardinal(10)
[5]:
'sepuluh'
[6]:
malaya.num2word.to_cardinal(12)
[6]:
'dua belas'
[7]:
malaya.num2word.to_cardinal(-1234567.89)
[7]:
'negatif satu juta dua ratus tiga puluh empat ribu lima ratus enam puluh tujuh perpuluhan lapan sembilan'

To ordinal

def to_ordinal(number):
    """
    Translate from number input to ordinal text representation

    Parameters
    ----------
    number: real number

    Returns
    -------
    result: str
        ordinal representation
    """
[8]:
malaya.num2word.to_ordinal(1)
[8]:
'pertama'
[9]:
malaya.num2word.to_cardinal(1)
[9]:
'satu'
[10]:
malaya.num2word.to_ordinal(10)
[10]:
'kesepuluh'
[11]:
malaya.num2word.to_ordinal(12)
[11]:
'kedua belas'
[12]:
malaya.num2word.to_cardinal(-123456789)
[12]:
'negatif seratus dua puluh tiga juta empat ratus lima puluh enam ribu tujuh ratus lapan puluh sembilan'