Пример #1
0
    def _cardinal2word(strNumber):
        """Convert a cardinal number to a written
           word.

           param strNumber: an utf-8 cardinal number
           return a 'written' cardinal number
        """
        return Number.convertNumberIntoLetters(strNumber)
Пример #2
0
    def _cardinal2word(strNumber):
        """Convert a cardinal number to a written
           word.

           param strNumber: an utf-8 cardinal number
           return a 'written' cardinal number
        """
        return Number.convertNumberIntoLetters(strNumber)
Пример #3
0
    def testConvertDecimalNumberIntoLetters(self):
        test = [(u'1,4', u'eins komma vier'),
                (u'134,2', u'hundert vier und dreissig komma zwei'),
                (u'589217,346', u'fünf hundert neun und achtzig tausend zwei hundert siebzehn komma drei hundert sechs und vierzig')]

        for digit, letters in test:
            strLetters = Number.convertDecimalNumberIntoLetters(digit)
            self.assertEquals(letters, strLetters, "Error with: '%s' --> '%s' " %\
            (letters.encode('utf-8'), strLetters.encode('utf-8')))
Пример #4
0
    def _ordinal2word(wordsList, indice):
        """Convert an ordinal number to a written
           word.

           i.e. 1. --> erste

           param strNumber: an utf-8 ordinal number
           return a 'written' ordinal number
        """
        strNumber = NumberFormula._normalizeNumber(wordsList[indice])

        #Update with correct form
        wordsList[indice] = strNumber

        #Check for specific ordinal ending with dates
        ending = NumberFormula._getOrdinalEnding(strNumber, wordsList, indice)
        bOrdinal = len(ending) > 0

        #ending = u""
        strNewNumber = re.sub(u"([.]|er)", "", strNumber)

        if NumberFormula._isCardinalNumber(strNewNumber):
            strNewNumber = Number.convertNumberIntoLetters(strNewNumber,
                                                           ordinal=bOrdinal)
        elif NumberFormula._isRomanNumber(strNewNumber):
            #Roman to cardinal
            strNewNumber = strNewNumber.encode('utf-8')
            cardinalNumber = fromRoman(strNewNumber)
            #Digits to ordinal
            strNewNumber = Number.convertNumberIntoLetters(cardinalNumber,
                                                           ordinal=bOrdinal)
        else:
            #Original word is kept
            strNewNumber = strNumber
            ending = u""

        #Already included in convertNumberIntLetters
        if ending == u"e":
            ending = u""

        return strNewNumber + ending
Пример #5
0
    def _ordinal2word(wordsList, indice):
        """Convert an ordinal number to a written
           word.

           i.e. 1. --> erste

           param strNumber: an utf-8 ordinal number
           return a 'written' ordinal number
        """
        strNumber = NumberFormula._normalizeNumber(wordsList[indice])

        #Update with correct form
        wordsList[indice] = strNumber

        #Check for specific ordinal ending with dates
        ending = NumberFormula._getOrdinalEnding(strNumber, wordsList, indice)
        bOrdinal = len(ending) > 0

        #ending = u""
        strNewNumber = re.sub(u"([.]|er)", "", strNumber)

        if NumberFormula._isCardinalNumber(strNewNumber):
            strNewNumber =  Number.convertNumberIntoLetters(strNewNumber, ordinal=bOrdinal)
        elif NumberFormula._isRomanNumber(strNewNumber):
            #Roman to cardinal
            strNewNumber = strNewNumber.encode('utf-8')
            cardinalNumber = fromRoman(strNewNumber)
            #Digits to ordinal
            strNewNumber =  Number.convertNumberIntoLetters(cardinalNumber, ordinal=bOrdinal)
        else:
            #Original word is kept
            strNewNumber = strNumber
            ending = u""

        #Already included in convertNumberIntLetters        
        if ending == u"e":
          ending = u""

        return strNewNumber + ending
Пример #6
0
    def testConvertDecimalNumberIntoLetters(self):
        test = [
            (u'1,4', u'eins komma vier'),
            (u'134,2', u'hundert vier und dreissig komma zwei'),
            (u'589217,346',
             u'fünf hundert neun und achtzig tausend zwei hundert siebzehn komma drei hundert sechs und vierzig'
             )
        ]

        for digit, letters in test:
            strLetters = Number.convertDecimalNumberIntoLetters(digit)
            self.assertEquals(letters, strLetters, "Error with: '%s' --> '%s' " %\
            (letters.encode('utf-8'), strLetters.encode('utf-8')))
Пример #7
0
    def testCardinalConvertNumberIntoLetters(self):
        test = [
            ('1', 'eins'), ('12', 'zwölf'), ('15', 'fünfzehn'),
            ('51', 'ein und fünfzig'), ('69', 'neun und sechzig'),
            ('76', 'sechs und siebzig'), ('100', 'hundert'),
            ('101', 'hundert eins'), ('134', 'hundert vier und dreissig'),
            ('318', 'drei hundert achtzehn'), ('1000', 'tausend'),
            ('1004', 'tausend vier'), ('1504', 'tausend fünf hundert vier'),
            ('2000', 'zwei tausend'),
            ('589217',
             'fünf hundert neun und achtzig tausend zwei hundert siebzehn'),
            ('1000000', 'ein million'), ('100000000', 'hundert millionen')
        ]

        for digit, letters in test:
            strLetters = Number.convertNumberIntoLetters(digit)
            self.assertEqual(
                letters, strLetters, "Error with: '%s' --> '%s' " %
                (letters.encode('utf-8'), strLetters.encode('utf-8')))
Пример #8
0
    def testOrdinalConvertNumberIntoLetters(self):
        test = [
            (u'1', u'erste'), (u'3', u'dritte'), (u'8', u'achte'),
            (u'12', u'zwölfte'), (u'15', u'fünfzehnte'),
            (u'51', u'ein und fünfzigste'), (u'69', u'neun und sechzigste'),
            (u'76', u'sechs und siebzigste'), (u'100', u'hundertste'),
            (u'101', u'hundert erste'),
            (u'134', u'hundert vier und dreissigste'),
            (u'318', u'drei hundert achtzehnte'), (u'1000', u'tausendste'),
            (u'1004', u'tausend vierte'),
            (u'1504', u'tausend fünf hundert vierte'),
            (u'2000', u'zwei tausendste'),
            (u'134', u'hundert vier und dreissigste'),
            (u'589217',
             u'fünf hundert neun und achtzig tausend zwei hundert siebzehnte')
        ]

        for digit, letters in test:
            strLetters = Number.convertNumberIntoLetters(digit, False, True)
            self.assertEquals(letters, strLetters, "Error with: '%s' --> '%s' " %\
            (letters.encode('utf-8'), strLetters.encode('utf-8')))
Пример #9
0
    def testCardinalConvertNumberIntoLetters(self):
        test = [(u'1', u'eins'),
                (u'12', u'zwölf'),
                (u'15', u'fünfzehn'),
                (u'51', u'ein und fünfzig'),
                (u'69', u'neun und sechzig'),
                (u'76', u'sechs und siebzig'),
                (u'100', u'hundert'),
                (u'101', u'hundert eins'),
                (u'134', u'hundert vier und dreissig'),
                (u'318', u'drei hundert achtzehn'),
                (u'1000', u'tausend'),
                (u'1004', u'tausend vier'),
                (u'1504', u'tausend fünf hundert vier'),
                (u'2000', u'zwei tausend'),
                (u'589217', u'fünf hundert neun und achtzig tausend zwei hundert siebzehn'),
                (u'1000000', u'ein million'),
                (u'100000000', u'hundert millionen')]

        for digit, letters in test:
            strLetters = Number.convertNumberIntoLetters(digit)
            self.assertEquals(letters, strLetters, "Error with: '%s' --> '%s' " %\
            (letters.encode('utf-8'), strLetters.encode('utf-8')))
Пример #10
0
    def testOrdinalConvertNumberIntoLetters(self):
        test = [
            ('1', 'erste'), ('3', 'dritte'), ('8', 'achte'), ('12', 'zwölfte'),
            ('15', 'fünfzehnte'), ('51', 'ein und fünfzigste'),
            ('69', 'neun und sechzigste'), ('76', 'sechs und siebzigste'),
            ('100', 'hundertste'), ('101', 'hundert erste'),
            ('134', 'hundert vier und dreissigste'),
            ('318', 'drei hundert achtzehnte'), ('1000', 'tausendste'),
            ('1004', 'tausend vierte'), ('1504',
                                         'tausend fünf hundert vierte'),
            ('2000', 'zwei tausendste'),
            ('134', 'hundert vier und dreissigste'),
            ('589217',
             'fünf hundert neun und achtzig tausend zwei hundert siebzehnte'),
            ('017688088605',
             'siebzehn billionen sechs hundert acht und achtzig millionen acht und achtzig tausend sechs hundert fünfte'
             )
        ]

        for digit, letters in test:
            strLetters = Number.convertNumberIntoLetters(digit, False, True)
            self.assertEqual(
                letters, strLetters, "Error with: '%s' --> '%s' " %
                (letters.encode('utf-8'), strLetters.encode('utf-8')))