Ejemplo n.º 1
0
 def test_infinity(self):
     self.assertEqual(pronounce_number(sys.float_info.max * 2,
                                       lang="it"), "infinito")
     self.assertEqual(pronounce_number(float("inf"),
                                       lang="it"), "infinito")
     self.assertEqual(pronounce_number(float("-inf"),
                                       lang="it"), "meno infinito")
Ejemplo n.º 2
0
 def test_convert_decimals(self):
     self.assertEqual(pronounce_number(0.05, lang="es"),
                      "zero coma zero cinc")
     self.assertEqual(pronounce_number(-0.05, lang="es"),
                      "menys zero coma zero cinc")
     self.assertEqual(pronounce_number(1.234, lang="es"),
                      "un coma dos tres")
Ejemplo n.º 3
0
 def test_convert_hundreds(self):
     self.assertEqual(pronounce_number(100, lang="it"), "cento")
     self.assertEqual(pronounce_number(121, lang="it"), "cento ventuno")
     self.assertEqual(pronounce_number(121000, lang="it"),
                      "cento ventunomila")
     self.assertEqual(pronounce_number(666, lang="it"),
                      "seicento sessantasei")
     self.assertEqual(pronounce_number(1456, lang="it"),
                      "mille, quattrocento cinquantasei")
     self.assertEqual(pronounce_number(103254654, lang="it"),
                      "cento tremilioni, duecento "
                      "cinquantaquattromila, seicento "
                      "cinquantaquattro")
     self.assertEqual(pronounce_number(1512457, lang="it"),
                      "un milione, cinquecento dodicimila, "
                      "quattrocento cinquantasette")
     self.assertEqual(pronounce_number(209996, lang="it"),
                      "duecento novemila, novecento novantasei")
     self.assertEqual(pronounce_number(95505896639631893, lang="it"),
                      "novantacinquebiliardi, cinquecento cinquebilioni, "
                      "ottocento novantaseimiliardi, "
                      "seicento trentanovemilioni, seicento "
                      "trentunomila, ottocento novantatre")
     self.assertEqual(pronounce_number(95505896639631893,
                                       short_scale=False, lang="it"),
                      "novantacinquemila cinquecento cinque miliardi, "
                      "ottocento novantaseimila seicento trentanove"
                      " milioni, seicento trentunomila, ottocento"
                      " novantatre")
Ejemplo n.º 4
0
    def test_large_numbers(self):
        self.assertEqual(
            pronounce_number(299792458),
            "dwieście dziewięćdziesiąt dziewięć milionów, siedemset "
            "dziewięćdziesiąt dwa tysiące, czterysta pięćdziesiąt osiem")
        self.assertEqual(
            pronounce_number(100034000000299792458),
            "sto trylionów, trzydzieści cztery biliardy, "
            "dwieście dziewięćdziesiąt dziewięć milionów, siedemset "
            "dziewięćdziesiąt dwa tysiące, czterysta pięćdziesiąt osiem")
        self.assertEqual(pronounce_number(10000000000), "dziesięć miliardów")
        self.assertEqual(pronounce_number(1000001), "jeden milion, jeden")
        self.assertEqual(
            pronounce_number(95505896639631893),
            "dziewięćdziesiąt pięć biliardów, pięćset pięć "
            "bilionów, osiemset dziewięćdziesiąt sześć miliardów, "
            "sześćset trzydzieści dziewięć milionów, sześćset "
            "trzydzieści jeden tysiące, osiemset dziewięćdziesiąt trzy")
        self.assertEqual(pronounce_number(10e80, places=1), "tredecyliard")
        self.assertEqual(
            pronounce_number(1.9874522571e80, places=9),
            "sto dziewięćdziesiąt osiem tredecylionów, "
            "siedemset czterdzieści pięć duodecyliardów, "
            "dwieście dwadzieścia pięć duodecylionów, "
            "siedemset dziewięć undecyliardów, "
            "dziewięćset dziewięćdziesiąt dziewięć undecylionów, "
            "dziewięćset osiemdziesiąt dziewięć decyliardów, "
            "siedemset trzydzieści decylionów, dziewięćset "
            "dziewiętnaście noniliardów, dziewięćset "
            "dziewięćdziesiąt dziewięć nonilionów, dziewięćset "
            "pięćdziesiąt pięć oktyliardów, czterysta "
            "dziewięćdziesiąt osiem oktylionów, dwieście "
            "czternaście septyliardy, osiemset "
            "czterdzieści pięć septylionów, czterysta "
            "dwadzieścia dziewięć sekstyliardów, czterysta "
            "czterdzieści cztery sekstyliony, trzysta "
            "trzydzieści sześć kwintyliardów, siedemset dwadzieścia "
            "cztery kwintyliony, pięćset sześćdziesiąt dziewięć "
            "kwadryliardów, trzysta siedemdziesiąt pięć "
            "kwadrylionów, dwieście trzydzieści dziewięć sekstilionów,"
            " sześćset siedemdziesiąt trylionów, pięćset "
            "siedemdziesiąt cztery biliardy, siedemset "
            "trzydzieści dziewięć bilionów, siedemset czterdzieści "
            "osiem miliardów, czterysta siedemdziesiąt milionów, "
            "dziewięćset piętnaście tysięcy, siedemdziesiąt dwa")

        # infinity
        self.assertEqual(pronounce_number(sys.float_info.max * 2),
                         "nieskończoność")
        self.assertEqual(pronounce_number(float("inf")), "nieskończoność")
        self.assertEqual(pronounce_number(float("-inf")),
                         "minus nieskończoność")
Ejemplo n.º 5
0
 def test_convert_scientific_notation(self):
     self.assertEqual(pronounce_number(0, scientific=True), "nula")
     self.assertEqual(pronounce_number(33, scientific=True),
                      "tři tečka tři krát deset na mocninu jedna")
     self.assertEqual(pronounce_number(299792458, scientific=True),
                      "dva tečka devět devět krát deset na mocninu osm")
     self.assertEqual(pronounce_number(299792458, places=6,
                                       scientific=True),
                      "dva tečka devět devět sedm devět dva pět krát "
                      "deset na mocninu osm")
     self.assertEqual(pronounce_number(1.672e-27, places=3,
                                       scientific=True),
                      "jedna tečka šest sedm dva krát deset na mocninu "
                      "záp**né dvacet sedm")
Ejemplo n.º 6
0
 def test_convert_scientific_notation(self):
     self.assertEqual(pronounce_number(0, scientific=True), "zero")
     self.assertEqual(pronounce_number(33, scientific=True),
                      "three point three times ten to the power of one")
     self.assertEqual(pronounce_number(299792458, scientific=True),
                      "two point nine nine times ten to the power of eight")
     self.assertEqual(pronounce_number(299792458, places=6,
                                       scientific=True),
                      "two point nine nine seven nine two five times "
                      "ten to the power of eight")
     self.assertEqual(pronounce_number(1.672e-27, places=3,
                                       scientific=True),
                      "one point six seven two times ten to the power of "
                      "negative twenty seven")
Ejemplo n.º 7
0
 def test_convert_hundreds(self):
     self.assertEqual(pronounce_number(100), "one hundred")
     self.assertEqual(pronounce_number(666), "six hundred and sixty six")
     self.assertEqual(pronounce_number(1456), "fourteen fifty six")
     self.assertEqual(
         pronounce_number(103254654), "one hundred and three "
         "million, two hundred "
         "and fifty four "
         "thousand, six hundred "
         "and fifty four")
     self.assertEqual(
         pronounce_number(1512457), "one million, five hundred"
         " and twelve thousand, "
         "four hundred and fifty "
         "seven")
     self.assertEqual(
         pronounce_number(209996), "two hundred and nine "
         "thousand, nine hundred "
         "and ninety six")
     self.assertEqual(
         pronounce_number(95505896639631893),
         "ninety five quadrillion, five hundred and five "
         "trillion, eight hundred and ninety six billion, six "
         "hundred and thirty nine million, six hundred and "
         "thirty one thousand, eight hundred and ninety three")
     self.assertEqual(
         pronounce_number(95505896639631893, short_scale=False),
         "ninety five thousand five hundred and five billion, "
         "eight hundred and ninety six thousand six hundred "
         "and thirty nine million, six hundred and thirty one "
         "thousand, eight hundred and ninety three")
Ejemplo n.º 8
0
 def test_convert_scientific_notation(self):
     self.assertEqual(pronounce_number(0, scientific=True), "nič")
     self.assertEqual(pronounce_number(33, scientific=True),
                      "tri cele tri krat deset na ena")
     self.assertEqual(pronounce_number(299792458, scientific=True),
                      "dve celi devet devet krat deset na osem")
     self.assertEqual(
         pronounce_number(299792458, places=6, scientific=True),
         "dve celi devet devet sedem devet dve pet "
         "krat deset na osem")
     self.assertEqual(
         pronounce_number(1.672e-27, places=3, scientific=True),
         "ena cela šest sedem dve krat deset na "
         "minus sedemindvajset")
Ejemplo n.º 9
0
    def test_convert_scientific_notation(self):
        """
        Test cases for italian text to scientific_notatio

        """
        self.assertEqual(pronounce_number(0, scientific=True,
                                          lang="it"), "zero")
        self.assertEqual(pronounce_number(33, scientific=True,
                                          lang="it"),
                         "tre virgola tre per dieci elevato alla uno")
        self.assertEqual(pronounce_number(299792458, scientific=True,
                                          lang="it"),
                         "due virgola nove nove per dieci elevato alla otto")
        self.assertEqual(pronounce_number(299792458, places=6,
                                          scientific=True, lang="it"),
                         "due virgola nove nove sette nove due cinque "
                         "per dieci elevato alla otto")
        self.assertEqual(pronounce_number(1.672e-27, places=3,
                                          scientific=True, lang="it"),
                         "uno virgola sei sette due per dieci elevato alla "
                         "meno ventisette")
        self.assertEqual(pronounce_number(-33, scientific=True,
                                          lang="it"),
                         "meno tre virgola tre per dieci elevato alla uno")
        self.assertEqual(pronounce_number(-299792458, scientific=True,
                                          lang="it"),
                         "meno due virgola nove nove per dieci elevato"
                         " alla otto")
        self.assertEqual(pronounce_number(-1.672e-27, places=3,
                                          scientific=True, lang="it"),
                         "meno uno virgola sei sette due per dieci elevato"
                         " alla meno ventisette")
Ejemplo n.º 10
0
 def test_convert_scientific_notation(self):
     self.assertEqual(pronounce_number(0, scientific=True), "zero")
     self.assertEqual(pronounce_number(33, scientific=True),
                      "trzy przecinek trzy razy dziesięć do potęgi jeden")
     self.assertEqual(
         pronounce_number(299792458, scientific=True),
         "dwa przecinek dziewięć dziewięć razy dziesięć do potęgi osiem")
     self.assertEqual(
         pronounce_number(299792458, places=6, scientific=True),
         "dwa przecinek dziewięć dziewięć siedem dziewięć dwa pięć razy "
         "dziesięć do potęgi osiem")
     self.assertEqual(
         pronounce_number(1.672e-27, places=3, scientific=True),
         "jeden przecinek sześć siedem dwa razy dziesięć do potęgi "
         "minus dwadzieścia siedem")
Ejemplo n.º 11
0
 def num_worker(self, line, lang, args):
     if args.disable_num_worker is "False":
         num = ""
         number = ""
         # print("line bevor"+"\n"+line)
         try:
             num = extract_numbers(line,
                                   short_scale=False,
                                   ordinals=False,
                                   lang="en-us")
         except:
             pass
         num = re.sub(r'(\.0)', '', str(num))
         num = re.findall(r'\d+', num)
         if not num is False:
             for item in num:
                 print("item #" + item)
                 try:
                     number = pronounce_number(int(item),
                                               lang=lang,
                                               places=2,
                                               short_scale=False,
                                               scientific=False)
                 except:
                     number = ""
                 line = line.replace(str(item), number)
         # print("line after"+"\n"+line)
     return line
Ejemplo n.º 12
0
 def test_convert_int(self):
     self.assertEqual(pronounce_number(0), "zero")
     self.assertEqual(pronounce_number(1), "jeden")
     self.assertEqual(pronounce_number(10), "dziesięć")
     self.assertEqual(pronounce_number(15), "piętnaście")
     self.assertEqual(pronounce_number(20), "dwadzieścia")
     self.assertEqual(pronounce_number(27), "dwadzieścia siedem")
     self.assertEqual(pronounce_number(30), "trzydzieści")
     self.assertEqual(pronounce_number(33), "trzydzieści trzy")
Ejemplo n.º 13
0
 def test_convert_int(self):
     self.assertEqual(pronounce_number(0), "nič")
     self.assertEqual(pronounce_number(1), "ena")
     self.assertEqual(pronounce_number(10), "deset")
     self.assertEqual(pronounce_number(15), "petnajst")
     self.assertEqual(pronounce_number(20), "dvajset")
     self.assertEqual(pronounce_number(27), "sedemindvajset")
     self.assertEqual(pronounce_number(30), "trideset")
     self.assertEqual(pronounce_number(33), "triintrideset")
Ejemplo n.º 14
0
 def test_convert_int(self):
     self.assertEqual(pronounce_number(0, lang="it"), "zero")
     self.assertEqual(pronounce_number(1, lang="it"), "uno")
     self.assertEqual(pronounce_number(10, lang="it"), "dieci")
     self.assertEqual(pronounce_number(15, lang="it"), "quindici")
     self.assertEqual(pronounce_number(21, lang="it"), "ventuno")
     self.assertEqual(pronounce_number(27, lang="it"), "ventisette")
     self.assertEqual(pronounce_number(30, lang="it"), "trenta")
     self.assertEqual(pronounce_number(83, lang="it"), "ottantatre")
Ejemplo n.º 15
0
 def test_convert_int(self):
     self.assertEqual(pronounce_number(0), "zero")
     self.assertEqual(pronounce_number(1), "one")
     self.assertEqual(pronounce_number(10), "ten")
     self.assertEqual(pronounce_number(15), "fifteen")
     self.assertEqual(pronounce_number(20), "twenty")
     self.assertEqual(pronounce_number(27), "twenty seven")
     self.assertEqual(pronounce_number(30), "thirty")
     self.assertEqual(pronounce_number(33), "thirty three")
Ejemplo n.º 16
0
 def test_convert_int(self):
     self.assertEqual(pronounce_number(0), "nula")
     self.assertEqual(pronounce_number(1), "jedna")
     self.assertEqual(pronounce_number(10), "deset")
     self.assertEqual(pronounce_number(15), "patnáct")
     self.assertEqual(pronounce_number(20), "dvacet")
     self.assertEqual(pronounce_number(27), "dvacet sedm")
     self.assertEqual(pronounce_number(30), "třicet")
     self.assertEqual(pronounce_number(33), "třicet tři")
Ejemplo n.º 17
0
 def test_large_numbers(self):
     self.assertEqual(
         pronounce_number(299792458, short_scale=True),
         "two hundred and ninety nine million, seven hundred "
         "and ninety two thousand, four hundred and fifty eight")
     self.assertEqual(
         pronounce_number(299792458, short_scale=False),
         "two hundred and ninety nine million, seven hundred "
         "and ninety two thousand, four hundred and fifty eight")
     self.assertEqual(
         pronounce_number(100034000000299792458, short_scale=True),
         "one hundred quintillion, thirty four quadrillion, "
         "two hundred and ninety nine million, seven hundred "
         "and ninety two thousand, four hundred and fifty eight")
     self.assertEqual(
         pronounce_number(100034000000299792458, short_scale=False),
         "one hundred trillion, thirty four thousand billion, "
         "two hundred and ninety nine million, seven hundred "
         "and ninety two thousand, four hundred and fifty eight")
     self.assertEqual(pronounce_number(10000000000, short_scale=True),
                      "ten billion")
     self.assertEqual(pronounce_number(1000000000000, short_scale=True),
                      "one trillion")
     # TODO maybe beautify this
     self.assertEqual(pronounce_number(1000001, short_scale=True),
                      "one million, one")
Ejemplo n.º 18
0
 def test_convert_negative_int(self):
     self.assertEqual(pronounce_number(-1, lang="it"), "meno uno")
     self.assertEqual(pronounce_number(-10, lang="it"), "meno dieci")
     self.assertEqual(pronounce_number(-15, lang="it"), "meno quindici")
     self.assertEqual(pronounce_number(-21, lang="it"), "meno ventuno")
     self.assertEqual(pronounce_number(-27, lang="it"), "meno ventisette")
     self.assertEqual(pronounce_number(-30, lang="it"), "meno trenta")
     self.assertEqual(pronounce_number(-83, lang="it"), "meno ottantatre")
Ejemplo n.º 19
0
 def test_convert_negative_int(self):
     self.assertEqual(pronounce_number(-1), "minus ena")
     self.assertEqual(pronounce_number(-10), "minus deset")
     self.assertEqual(pronounce_number(-15), "minus petnajst")
     self.assertEqual(pronounce_number(-20), "minus dvajset")
     self.assertEqual(pronounce_number(-27), "minus sedemindvajset")
     self.assertEqual(pronounce_number(-30), "minus trideset")
     self.assertEqual(pronounce_number(-33), "minus triintrideset")
Ejemplo n.º 20
0
 def test_convert_negative_int(self):
     self.assertEqual(pronounce_number(-1), "mínus jedna")
     self.assertEqual(pronounce_number(-10), "mínus deset")
     self.assertEqual(pronounce_number(-15), "mínus patnáct")
     self.assertEqual(pronounce_number(-20), "mínus dvacet")
     self.assertEqual(pronounce_number(-27), "mínus dvacet sedm")
     self.assertEqual(pronounce_number(-30), "mínus třicet")
     self.assertEqual(pronounce_number(-33), "mínus třicet tři")
Ejemplo n.º 21
0
 def test_convert_negative_int_de(self):
     self.assertEqual(pronounce_number(-1), "minus eins")
     self.assertEqual(pronounce_number(-10), "minus zehn")
     self.assertEqual(pronounce_number(-15), u"minus fünfzehn")
     self.assertEqual(pronounce_number(-20), "minus zwanzig")
     self.assertEqual(pronounce_number(-27), "minus siebenundzwanzig")
     self.assertEqual(pronounce_number(-30), u"minus dreißig")
     self.assertEqual(pronounce_number(-33), u"minus dreiunddreißig")
Ejemplo n.º 22
0
 def test_convert_negative_int(self):
     self.assertEqual(pronounce_number(-1), "minus jeden")
     self.assertEqual(pronounce_number(-10), "minus dziesięć")
     self.assertEqual(pronounce_number(-15), "minus piętnaście")
     self.assertEqual(pronounce_number(-20), "minus dwadzieścia")
     self.assertEqual(pronounce_number(-27), "minus dwadzieścia siedem")
     self.assertEqual(pronounce_number(-30), "minus trzydzieści")
     self.assertEqual(pronounce_number(-33), "minus trzydzieści trzy")
Ejemplo n.º 23
0
 def test_convert_negative_int(self):
     self.assertEqual(pronounce_number(-1), "minus one")
     self.assertEqual(pronounce_number(-10), "minus ten")
     self.assertEqual(pronounce_number(-15), "minus fifteen")
     self.assertEqual(pronounce_number(-20), "minus twenty")
     self.assertEqual(pronounce_number(-27), "minus twenty seven")
     self.assertEqual(pronounce_number(-30), "minus thirty")
     self.assertEqual(pronounce_number(-33), "minus thirty three")
Ejemplo n.º 24
0
 def test_convert_negative_int_sv(self):
     self.assertEqual(pronounce_number(-1, lang="sv-se"), "minus en")
     self.assertEqual(pronounce_number(-10, lang="sv-se"), "minus tio")
     self.assertEqual(pronounce_number(-15, lang="sv-se"), "minus femton")
     self.assertEqual(pronounce_number(-20, lang="sv-se"), "minus tjugo")
     self.assertEqual(pronounce_number(-27, lang="sv-se"), "minus tjugosju")
     self.assertEqual(pronounce_number(-30, lang="sv-se"), "minus trettio")
     self.assertEqual(pronounce_number(-33, lang="sv-se"),
                      "minus trettiotre")
Ejemplo n.º 25
0
 def handle_country_population(self, data):
     country = data["country"]
     if country in self.countries_data.keys():
         population = self.countries_data[country]["population"]
         area = pronounce_number(int(population), lang=self.lang)
         return self.dialog_renderer.render("population", {
             "country": country,
             "number": area
         })
     else:
         return self.dialog_renderer.render("bad_country")
Ejemplo n.º 26
0
 def test_convert_negative_int_nl(self):
     self.assertEqual(pronounce_number(-1, lang="nl-nl"), u"min één")
     self.assertEqual(pronounce_number(-10, lang="nl-nl"), "min tien")
     self.assertEqual(pronounce_number(-15, lang="nl-nl"), "min vijftien")
     self.assertEqual(pronounce_number(-20, lang="nl-nl"), "min twintig")
     self.assertEqual(pronounce_number(-27, lang="nl-nl"),
                      "min zevenentwintig")
     self.assertEqual(pronounce_number(-30, lang="nl-nl"), u"min dertig")
     self.assertEqual(pronounce_number(-33, lang="nl-nl"),
                      u"min drieendertig")
Ejemplo n.º 27
0
 def test_convert_negative_int_fr(self):
     self.assertEqual(pronounce_number(-1, lang="fr-fr"), "moins un")
     self.assertEqual(pronounce_number(-10, lang="fr-fr"), "moins dix")
     self.assertEqual(pronounce_number(-15, lang="fr-fr"), "moins quinze")
     self.assertEqual(pronounce_number(-20, lang="fr-fr"), "moins vingt")
     self.assertEqual(pronounce_number(-27, lang="fr-fr"),
                      "moins vingt-sept")
     self.assertEqual(pronounce_number(-30, lang="fr-fr"), "moins trente")
     self.assertEqual(pronounce_number(-33, lang="fr-fr"),
                      "moins trente-trois")
Ejemplo n.º 28
0
 def test_convert_negative_int_da(self):
     self.assertEqual(pronounce_number(-1, lang="da-dk"), "minus en")
     self.assertEqual(pronounce_number(-10, lang="da-dk"), "minus ti")
     self.assertEqual(pronounce_number(-15, lang="da-dk"), "minus femten")
     self.assertEqual(pronounce_number(-20, lang="da-dk"), "minus tyve")
     self.assertEqual(pronounce_number(-27, lang="da-dk"),
                      "minus syvogtyve")
     self.assertEqual(pronounce_number(-30, lang="da-dk"), "minus tredive")
     self.assertEqual(pronounce_number(-33, lang="da-dk"),
                      "minus treogtredive")
Ejemplo n.º 29
0
 def handle_country_area(self, data):
     country = data["country"]
     if country in self.countries_data.keys():
         area = self.countries_data[country]["area"]
         # TODO convert units
         area = pronounce_number(float(area), lang=self.lang)
         return self.dialog_renderer.render("area", {
             "country": country,
             "number": area
         })
     else:
         return self.dialog_renderer.render("bad_country")
Ejemplo n.º 30
0
 def test_convert_negative_int_hu(self):
     self.assertEqual(pronounce_number(-1, lang="hu-hu"), "mínusz egy")
     self.assertEqual(pronounce_number(-10, lang="hu-hu"), "mínusz tíz")
     self.assertEqual(pronounce_number(-15, lang="hu-hu"), "mínusz tizenöt")
     self.assertEqual(pronounce_number(-20, lang="hu-hu"), "mínusz húsz")
     self.assertEqual(pronounce_number(-27, lang="hu-hu"),
                      "mínusz huszonhét")
     self.assertEqual(pronounce_number(-30, lang="hu-hu"), "mínusz harminc")
     self.assertEqual(pronounce_number(-33, lang="hu-hu"),
                      "mínusz harminchárom")