Ejemplo n.º 1
0
 def handle_eit(self, message):
     camera = random.choice(["eit304", "eit171", "eit195", "eit284"])
     n = extract_number(message.data["utterance"], ordinals=True)
     if n is not False:
         if n in [284, 304, 195, 171]:
             camera = "eit" + str(n)
         elif message.data.get("temperature"):
             if n >= 2000000:
                 camera = "eit284"
             elif n >= 1500000:
                 camera = "eit195"
             elif n >= 1000000:
                 camera = "eit171"
             else:
                 camera = "eit304"
     # the hotter the temperature,
     # the higher you look in the solar atmosphere.
     elif message.data.get("high"):
         camera = "eit284"  # 2 million degrees
     elif message.data.get("low"):
         #  304 Angstrom the bright material is at 60,000 to 80,000 degrees Kelvin.
         camera = "eit304"
     self.current_camera = camera
     date = extract_datetime(message.data["utterance"], lang=self.lang)
     if date is not None:
         date, remainder = date
     self._display(date)
     self.set_context("EIT" + self.current_camera[3:])
Ejemplo n.º 2
0
 def handle_zoom_in(self, message):
     n = extract_number(message.data["utterance"], ordinals=True)
     if n is False:
         n = self.settings["zoom"] + 1
     if n > 8:
         self.speak_dialog("max.zoom")
         return
     self.change_zoom(n)
Ejemplo n.º 3
0
 def handle_futurism_comic_intent(self, message):
     number = extract_number(message.data["utterance"],
                             lang=self.lang,
                             ordinals=True)
     total = self.total_comics()
     if number > total:
         self.speak_dialog("num_error", {"total": total})
         self.gui.show_text(str(total) + " comics")
         return
     self.current_comic = number
     self.display_comic(number)
Ejemplo n.º 4
0
 def get_numerical_response(self, dialog):
     while True:
         val = self.get_response(dialog)
         val = extract_number(val)
         try:
             val = int(val)
             return val
         except ValueError:
             self.speak_dialog("invalid.input")
         except:
             self.speak_dialog("input.error")
Ejemplo n.º 5
0
    def handle_creator_password(self, message):
        number_of_words = message.data.get("NumberOfWords")
        number_of_words = extract_number(
            number_of_words) if number_of_words else 6

        acrostic = message.data.get("Acrostic")
        acrostic = acrostic if acrostic else False

        wordfile = xp.locate_wordfile()
        words = xp.generate_wordlist(wordfile=wordfile)  # Can modify
        password = xp.generate_xkcdpassword(words,
                                            number_of_words,
                                            acrostic=acrostic)  # Can modify

        self.speak_dialog('creator.password', data={'password': password})
Ejemplo n.º 6
0
 def handle_set_zoom(self, message):
     if self.voc_match(message.data["utterance"], "max"):
         n = 8
         if self.settings["zoom"] == 8:
             self.speak_dialog("max.zoom")
             return
     elif self.voc_match(message.data["utterance"], "min"):
         n = 0
         if self.settings["zoom"] == 0:
             self.speak_dialog("min.zoom")
             return
     else:
         n = extract_number(message.data["utterance"], ordinals=True)
         if n is False or n < 0 or n > 8:
             self.speak_dialog("bad.zoom")
             return
     self.change_zoom(n)
Ejemplo n.º 7
0
    def test_extract_number_es(self):
        self.assertEqual(
            sorted(extract_numbers("1 7 cuatro catorce ocho 157", lang='es')),
            [1, 4, 7, 8, 14, 157])
        self.assertEqual(
            sorted(
                extract_numbers(
                    "1 7 cuatro albuquerque naranja John Doe catorce ocho 157",
                    lang='es')), [1, 4, 7, 8, 14, 157])
        self.assertEqual(extract_number("seis punto dos", lang='es'), 6.2)
        self.assertEqual(extract_number("seis punto Dos", lang='es'), 6.2)
        self.assertEqual(extract_number("seis coma dos", lang='es'), 6.2)
        self.assertEqual(extract_numbers("un medio", lang='es'), [0.5])
        self.assertEqual(extract_number("cuarto", lang='es'), 0.25)

        self.assertEqual(extract_number("2.0", lang='es'), 2.0)
        self.assertEqual(extract_number("1/4", lang='es'), 0.25)

        self.assertEqual(extract_number("dos y media", lang='es'), 2.5)
        self.assertEqual(extract_number("catorce y milésima", lang='es'),
                         14.001)

        self.assertEqual(extract_number("dos punto cero dos", lang='es'), 2.02)
Ejemplo n.º 8
0
 def handle_xkcd_comic_intent(self, message):
     number = extract_number(message.data["utterance"],
                             lang=self.lang,
                             ordinals=True)
     total = self.total_comics()
     if number > total:
         self.speak_dialog("num_error", {"total": total})
         self.gui.show_text(str(total) + " comics")
         return
     data = self.get_comic(number)
     url = data["img"]
     title = data["safe_title"]
     caption = data["alt"]
     self.speak(caption)
     self.gui.show_image(url,
                         override_idle=120,
                         title=title,
                         fill='PreserveAspectFit')
Ejemplo n.º 9
0
 def test_extract_number(self):
     self.assertEqual(
         extract_number("dette er den første test", lang="da-dk"), 1)
     #        self.assertEqual(extract_number("dette er den 1. test",
     #                                        lang="da-dk"),
     #                         1)
     self.assertEqual(
         extract_number("dette er den anden test", lang="da-dk"), 2)
     #        self.assertEqual(extract_number("dette er den 2. test",
     #                                        lang="da-dk"),
     #                         2)
     self.assertEqual(
         extract_number("dette er den tredie test", lang="da-dk"), 3)
     self.assertEqual(
         extract_number("dette er test nummer fire", lang="da-dk"), 4)
     self.assertEqual(
         extract_number("dette er test nummer Fire", lang="da-dk"), 4)
     self.assertEqual(
         extract_number("en trediedel af en kop", lang="da-dk"), 1.0 / 3.0)
     self.assertEqual(extract_number("tre kopper", lang="da-dk"), 3)
     self.assertEqual(extract_number("1/3 kop", lang="da-dk"), 1.0 / 3.0)
Ejemplo n.º 10
0
    def handle_ask_number(self, message):
        """Intend handler that the user can ask for the next number/amounts of events.

        Gets executed with the right user input.
        The user can ask a specific number of events.
        For example what's his next five events.
        If there es less events than the user asked, Mycroft will tell the remaining events.

        Args:
            message: A message object, which contains the user inputs.
                     In this case the message contains the asked amounts of events. .
        """

        number_speak = message.data['number']

        number = extract_number(number_speak)

        calendar = self.current_calendar
        if calendar is None:
            self.speak('No calendar accessible')
            return

        future_events = self.get_all_events(calendar=calendar,
                                            start=datetime.now().astimezone())

        if len(future_events) == 0:
            self.speak_dialog('no.appointments.number')
        else:
            if number > len(future_events):
                self.speak(
                    f"You have only {len(future_events)} upcoming events and they are"
                )
                number = len(future_events)
            else:
                self.speak("Your following events are")

            for i in range(number):
                next_event = future_events[i].instance.vevent

                self.helper_speak_event(next_event)
Ejemplo n.º 11
0
from lingua_franca.parse import extract_datetime, extract_number, \
    extract_numbers, extract_duration, normalize

# extract a number
assert extract_number("nothing") is False
assert extract_number("two million five hundred thousand tons of spinning "
                      "metal") == 2500000
assert extract_number("six trillion") == 6000000000000.0
assert extract_number("six trillion", short_scale=False) == 6e+18

assert extract_number("1 and 3/4 cups") == 1.75
assert extract_number("1 cup and a half") == 1.5

## extracts all numbers
assert extract_numbers("nothing") == []
assert extract_numbers("this is a one twenty one  test") == [1.0, 21.0]
assert extract_numbers("1 dog, seven pigs, macdonald had a farm, "
                       "3 times 5 macarena") == [1, 7, 3, 5]

## extract durations
from datetime import timedelta

assert extract_duration("nothing") == (None, 'nothing')

assert extract_duration("Nineteen minutes past the hour") == (timedelta(
    minutes=19), "past the hour")
assert extract_duration("wake me up in three weeks, four hundred ninety seven"
                        " days, and three hundred 91.6 seconds") == (timedelta(
                            weeks=3, days=497,
                            seconds=391.6), "wake me up in , , and")
assert extract_duration(
Ejemplo n.º 12
0
    def test_extract_number(self):
        self.assertEqual(extract_number('to jest pół testu'), 0.5)
        self.assertEqual(
            extract_number("to jest pierwszy test", ordinals=True), 1)
        self.assertEqual(extract_number("to jest 2 test"), 2)
        self.assertEqual(extract_number("to jest drugi test", ordinals=True),
                         2)
        self.assertEqual(extract_number("to jest trzeci test", ordinals=True),
                         3.0)
        self.assertEqual(extract_number("czwarty test", ordinals=True), 4.0)
        self.assertEqual(
            extract_number("trzydziesty szósty test", ordinals=True), 36.0)
        self.assertEqual(extract_number("to jest test numer 4"), 4)
        self.assertEqual(extract_number("jedna trzecia szklanki"), 1.0 / 3.0)
        self.assertEqual(extract_number("trzy szklanki"), 3)
        self.assertEqual(extract_number("1/3 szklanki"), 1.0 / 3.0)
        self.assertEqual(extract_number("jedna czwarta szklanki"), 0.25)
        self.assertEqual(extract_number("1/4 szklanki"), 0.25)
        self.assertEqual(extract_number("jedna czwarta szklanki"), 0.25)
        self.assertEqual(extract_number("2/3 szklanki"), 2.0 / 3.0)
        self.assertEqual(extract_number("3/4 szklanki"), 3.0 / 4.0)
        self.assertEqual(extract_number("1 i 3/4 szklanki"), 1.75)
        self.assertEqual(extract_number("1 szklanka i jedna druga"), 1.5)
        self.assertEqual(extract_number("jedna szklanka i jedna druga"), 1.5)
        self.assertEqual(extract_number("jeden i jedna druga szklanki"), 1.5)
        self.assertEqual(extract_number("trzy czwarte szklanki"), 3.0 / 4.0)
        self.assertEqual(extract_number("dwadzieścia dwa"), 22)
        self.assertEqual(extract_number("Dwadzieścia dwa i trzy piąte"), 22.6)
        self.assertEqual(extract_number("dwieście"), 200)
        self.assertEqual(extract_number("dziewięć tysięcy"), 9000)
        self.assertEqual(extract_number("sześćset sześćdziesiąt sześć"), 666)
        self.assertEqual(extract_number("dwa miliony"), 2000000)
        self.assertEqual(
            extract_number("dwa miliony pięćset tysięcy "
                           "ton metalu"), 2500000)
        self.assertEqual(extract_number("sześć bilionów"), 6000000000000.0)
        self.assertEqual(extract_number("jeden przecinek pięć"), 1.5)
        self.assertEqual(extract_number("trzy kropka czternaście"), 3.14)
        self.assertEqual(extract_number("zero przecinek dwa"), 0.2)
        self.assertEqual(extract_number("miliardy lat starsze"), 1000000000.0)
        self.assertEqual(extract_number("sto tysięcy"), 100000)
        self.assertEqual(extract_number("minus 2"), -2)
        self.assertEqual(extract_number("ujemne siedemdziesiąt"), -70)
        self.assertEqual(extract_number("tysiąc milionów"), 1000000000)
        self.assertEqual(extract_number("sześć trzecich"), 6 / 3)
        self.assertEqual(extract_number("trzydzieści sekund"), 30)
        self.assertEqual(
            extract_number("to jest miliardowy test", ordinals=True), 1e09)
        self.assertEqual(extract_number("to jest miliardowa część"), 1e-9)

        # Verify non-power multiples of ten no longer discard
        # adjacent multipliers
        self.assertEqual(extract_number("dwadzieścia tysięcy"), 20000)
        self.assertEqual(extract_number("pięćdziesiąt milionów"), 50000000)

        # Verify smaller powers of ten no longer cause miscalculation of larger
        # powers of ten (see MycroftAI#86)
        self.assertEqual(
            extract_number("trzysta dwadzieścia miliardów trzysta milionów \
                                        dziewięćset pięćdziesiąt tysięcy sześćset \
                                        siedemdziesiąt pięć kropka osiem"),
            320300950675.8)
        self.assertEqual(
            extract_number("dziewięćset dziewięćdziesiąt dziewięć milionów \
                                        dziewięćset dziewięćdziesiąt dziewięć tysięcy \
                                        dziewięćset dziewięćdziesiąt dziewięć przecinek dziewięć"
                           ), 999999999.9)

        # TODO why does "trillion" result in xxxx.0?
        self.assertEqual(
            extract_number("osiemset bilionów dwieście \
                                        pięćdziesiąt siedem"),
            800000000000257.0)

        self.assertTrue(extract_number("Szybki gracz") is False)
        self.assertTrue(extract_number("krejzi") is False)

        self.assertTrue(extract_number("krejzi zero") is not False)
        self.assertEqual(extract_number("krejzi zero"), 0)

        self.assertTrue(extract_number("super 0") is not False)
        self.assertEqual(extract_number("super 0"), 0)

        self.assertEqual(extract_number("jesteś drugi", ordinals=True), 2)
        self.assertEqual(extract_number("całkowicie 100%"), 100)
Ejemplo n.º 13
0
    def test_extractnumber_it(self):
        """
        Test cases for Italian extract_number, lang='it'
        """
        self.assertEqual(extract_number('questo è il primo test',
                                        lang='it'), 1)
        self.assertEqual(extract_number('questo è il 2 test', lang='it'), 2)
        self.assertEqual(extract_number('questo è il secondo test',
                                        lang='it', ordinals=True), 2)
        self.assertEqual(extract_number('questo è un terzo di test',
                                        lang='it'), 1.0 / 3.0)
        self.assertEqual(extract_number('questo è il terzo test',
                                        lang='it', ordinals=True), 3.0)
        self.assertEqual(extract_number('questo è il trentaseiesimo test',
                                        lang='it'), 36.0)
        self.assertEqual(extract_number('questo è il test numero 4',
                                        lang='it'), 4)
        self.assertEqual(extract_number('una tazza', lang='it'), 1)
        self.assertEqual(extract_number('un gatto', lang='it'), 1)
        self.assertEqual(extract_number('un terzo di tazza',
                                        lang='it'), 1.0 / 3.0)
        self.assertEqual(extract_number('2 quinti di tazza', lang='it'), 0.4)
        self.assertEqual(extract_number('due quinti di tazza', lang='it'), 0.4)
        self.assertEqual(extract_number('tre tazze', lang='it'), 3)
        self.assertEqual(extract_number('1/3 tazze', lang='it'), 1.0 / 3.0)
        self.assertEqual(extract_number('un quarto di tazza', lang='it'), 0.25)
        self.assertEqual(extract_number('1/4 tazza', lang='it'), 0.25)
        self.assertEqual(extract_number('2/3 tazza', lang='it'), 2.0 / 3.0)
        self.assertEqual(extract_number('3/4 tazza', lang='it'), 3.0 / 4.0)
        self.assertEqual(extract_number('1 e 1/4 tazza', lang='it'), 1.25)
        self.assertEqual(extract_number('1 tazza e mezzo', lang='it'), 1.5)
        self.assertEqual(extract_number('una tazza e mezzo', lang='it'), 1.5)
        self.assertEqual(extract_number('una e mezza tazza', lang='it'), 1.5)
        self.assertEqual(extract_number('una e una mezza tazza',
                                        lang='it'), 1.5)
        self.assertEqual(extract_number('tre quarti di tazza',
                                        lang='it'), 3.0 / 4.0)
        self.assertEqual(extract_number('ventidue', lang='it'), 22)
        self.assertEqual(extract_number('duecento', lang='it'), 200)
        self.assertEqual(extract_number('novemila', lang='it'), 9000)
        self.assertEqual(extract_number('duemilioni',
                                        lang='it',
                                        short_scale=False), 2000000)
        self.assertEqual(extract_number('duemilionicinquecentomila '
                                        'tonnellate di metallo',
                                        lang='it'), 2500000)
        self.assertEqual(extract_number('duemilioni cinquecentomila '
                                        'tonnellate di metallo',
                                        lang='it'), 2500000)
        self.assertEqual(extract_number('sei trilioni',
                                        lang='it'), 6000000000000000000.0)
        self.assertEqual(extract_number('sei trilioni', short_scale=True,
                                        lang='it'), 6e+18)
        self.assertEqual(extract_number('unmiliardounmilione',
                                        lang='it',
                                        short_scale=False), 1001000000)
        self.assertEqual(extract_number('unmiliardocento',
                                        lang='it',
                                        short_scale=False), 1000000100)
        self.assertEqual(extract_number('duemiliardiunmilionecentotrentadue',
                                        lang='it'), 2001000132)
        self.assertEqual(extract_number('venti diciassettesimi',
                                        lang='it'), 20.0/17.0)
        self.assertEqual(extract_number('uno punto cinque', lang='it'), 1.5)
        self.assertEqual(extract_number('tre punto quattordici',
                                        lang='it'), 3.14)
        self.assertEqual(extract_number('zero punto due', lang='it'), 0.2)
        self.assertEqual(extract_number('vecchio miliardi di anni',
                                        lang='it'), 1000000000.0)
        self.assertEqual(extract_number('vecchio trilioni di anni',
                                        short_scale=False,
                                        lang='it'), 1000000000000000000.0)
        self.assertEqual(extract_number('centomila', lang='it'), 100000)
        self.assertEqual(extract_number('millequattrocentonovantadue',
                                        lang='it'), 1492)
        self.assertEqual(extract_number('meno 2', lang='it'), -2)
        self.assertEqual(extract_number('meno settanta', lang='it'), -70)
        self.assertEqual(extract_number('mille milioni',
                                        lang='it'), 1000000000)
        self.assertEqual(extract_number('millecentouno',
                                        lang='it'), 1101)
        self.assertEqual(extract_number('un sesto terzo',
                                        lang='it'), 1 / 6 / 3)
        self.assertEqual(extract_number('trenta secondi', lang='it'), 30)
        self.assertEqual(extract_number('trenta secondi', lang='it',
                                        ordinals=True), 30)
        self.assertEqual(extract_number('sette e qualcosa', lang='it'), 7.0)
        self.assertEqual(extract_number('sette punto 5', lang='it'), 7.5)
        self.assertEqual(extract_number('sette punto 575', lang='it'), 7.575)
        self.assertEqual(extract_number('sette e mezzo', lang='it'), 7.5)
        self.assertEqual(extract_number('sette e ottanta', lang='it'), 7.80)
        self.assertEqual(extract_number('sette e otto', lang='it'), 7.8)
        self.assertEqual(extract_number('sette e zero otto',
                                        lang='it'), 7.08)
        self.assertEqual(extract_number('sette e zero zero zero otto gradi',
                                        lang='it'), 7.0008)
        self.assertEqual(extract_number('venti tredicesimi',
                                        lang='it'), 20.0 / 13.0)
        self.assertEqual(extract_number('venti tredicesimi', lang='it',
                                        short_scale=True), 20.0 / 13.0)
        self.assertEqual(extract_number('sei virgola sessantasei',
                                        lang='it'), 6.66)
        self.assertEqual(extract_number('sei virgola sessantasei',
                                        lang='it'), 6.66)
        self.assertEqual(extract_number('seicentosessantasei',
                                        lang='it'), 666)
        self.assertEqual(extract_number('seicento sessantasei',
                                        lang='it'), 666)
        self.assertEqual(extract_number('mille quattrocento novantadue',
                                        lang='it'), 1492)
        self.assertEqual(extract_number('millequattrocentonovantadue',
                                        lang='it'), 1492)
        self.assertEqual(extract_number('sei cento punto zero sei',
                                        lang='it'), 600.06)
        self.assertEqual(extract_number('seicento punto zero zero sei',
                                        lang='it'), 600.006)
        self.assertEqual(extract_number('seicento punto zero zero zero sei',
                                        lang='it'), 600.0006)
        self.assertEqual(extract_number('tre decimi ',
                                        lang='it'), 0.30000000000000004)
        self.assertEqual(extract_number('dodici centesimi',
                                        lang='it'), 0.12)
#        self.assertEqual(extract_number('cinque e quarantadue millesimi',
#                                        lang='it'), 5.042)
        self.assertEqual(extract_number('milleuno',
                                        lang='it'), 1001)
        self.assertEqual(extract_number('due mila ventidue dollari ',
                                        lang='it'), 2022)
        self.assertEqual(extract_number(
            'centoquattordicimilaquattrocentoundici dollari ',
            lang='it', ordinals=True, short_scale=True), 114411)
        self.assertEqual(extract_number('ventitre dollari ', lang='it'), 23)
        self.assertEqual(extract_number('ventuno anni ',
                                        lang='it'), 21)
        self.assertEqual(extract_number('dodici e quarantacinque ',
                                        lang='it'), 12.45)
        self.assertEqual(extract_number('avvisa se qualcuno arriva ',
                                        lang='it'), False)
        self.assertTrue(extract_number('Il giocatore di tennis è veloce',
                                       lang='it') is False)
        self.assertTrue(extract_number('nessuno', lang='it') is False)
        self.assertTrue(extract_number('fraggle zero',
                                       lang='it') is not False)
        self.assertEqual(extract_number('fraggle zero', lang='it'), 0)
        self.assertTrue(extract_number('grobo 0', lang='it') is not False)
        self.assertEqual(extract_number('grobo 0', lang='it'), 0)
        self.assertEqual(extract_number('un paio di birre', lang='it'), 2)
        self.assertEqual(extract_number('un centinaio di birre',
                                        lang='it'), 100)
        self.assertEqual(extract_number('un paio di migliaia di birre',
                                        lang='it'), 2000)
        self.assertEqual(extract_number('una decina di monete',
                                        lang='it'), 10)
        self.assertEqual(extract_number('tre dozzine di uova',
                                        lang='it'), 36)
        self.assertEqual(extract_number('zero gatti',
                                        lang='it'), 0)
        self.assertEqual(extract_number('Zero gatti',
                                        lang='it'), 0)
Ejemplo n.º 14
0
 def test_extract_number(self):
     self.assertEqual(extract_number("dies ist der 1. Test",
                                     lang="de-de"), 1)
     self.assertEqual(extract_number("dies ist der erste Test",
                                     lang="de-de"), 1)
     self.assertEqual(extract_number("dies ist 2 Test", lang="de-de"), 2)
     self.assertEqual(extract_number("dies ist zweiter Test", lang="de-de"),
                      2)
     self.assertEqual(
         extract_number("dies ist der dritte Test", lang="de-de"), 3)
     self.assertEqual(
         extract_number("dies ist der Test Nummer 4", lang="de-de"), 4)
     self.assertEqual(extract_number("ein drittel einer Tasse",
                                     lang="de-de"), 1.0 / 3.0)
     self.assertEqual(extract_number("drei Tassen", lang="de-de"), 3)
     self.assertEqual(extract_number("1/3 Tasse", lang="de-de"), 1.0 / 3.0)
     self.assertEqual(extract_number("eine viertel Tasse", lang="de-de"),
                      0.25)
     self.assertEqual(extract_number("1/4 Tasse", lang="de-de"), 0.25)
     self.assertEqual(extract_number("viertel Tasse", lang="de-de"), 0.25)
     self.assertEqual(extract_number("2/3 Tasse", lang="de-de"), 2.0 / 3.0)
     self.assertEqual(extract_number("3/4 Tasse", lang="de-de"), 3.0 / 4.0)
     self.assertEqual(extract_number("1 und 3/4 Tassen", lang="de-de"),
                      1.75)
     self.assertEqual(extract_number("1 Tasse und eine halbe",
                                     lang="de-de"), 1.5)
     self.assertEqual(
         extract_number("eine Tasse und eine halbe", lang="de-de"), 1.5)
     self.assertEqual(
         extract_number("eine und eine halbe Tasse", lang="de-de"), 1.5)
     self.assertEqual(extract_number("ein und ein halb Tassen",
                                     lang="de-de"), 1.5)
     self.assertEqual(extract_number("drei Viertel Tasse", lang="de-de"),
                      3.0 / 4.0)
     self.assertEqual(extract_number("drei Viertel Tassen", lang="de-de"),
                      3.0 / 4.0)
     self.assertEqual(extract_number("Drei Viertel Tassen", lang="de-de"),
                      3.0 / 4.0)
Ejemplo n.º 15
0
    def test_extract_number(self):
        self.assertEqual(
            extract_number("this is the first test", ordinals=True), 1)
        self.assertEqual(extract_number("this is 2 test"), 2)
        self.assertEqual(extract_number("this is second test", ordinals=True),
                         2)
        self.assertEqual(extract_number("this is the third test"), 1.0 / 3.0)
        self.assertEqual(
            extract_number("this is the third test", ordinals=True), 3.0)
        self.assertEqual(extract_number("the fourth one", ordinals=True), 4.0)
        self.assertEqual(extract_number("the thirty sixth one", ordinals=True),
                         36.0)
        self.assertEqual(extract_number("this is test number 4"), 4)
        self.assertEqual(extract_number("one third of a cup"), 1.0 / 3.0)
        self.assertEqual(extract_number("three cups"), 3)
        self.assertEqual(extract_number("1/3 cups"), 1.0 / 3.0)
        self.assertEqual(extract_number("quarter cup"), 0.25)
        self.assertEqual(extract_number("1/4 cup"), 0.25)
        self.assertEqual(extract_number("one fourth cup"), 0.25)
        self.assertEqual(extract_number("2/3 cups"), 2.0 / 3.0)
        self.assertEqual(extract_number("3/4 cups"), 3.0 / 4.0)
        self.assertEqual(extract_number("1 and 3/4 cups"), 1.75)
        self.assertEqual(extract_number("1 cup and a half"), 1.5)
        self.assertEqual(extract_number("one cup and a half"), 1.5)
        self.assertEqual(extract_number("one and a half cups"), 1.5)
        self.assertEqual(extract_number("one and one half cups"), 1.5)
        self.assertEqual(extract_number("three quarter cups"), 3.0 / 4.0)
        self.assertEqual(extract_number("three quarters cups"), 3.0 / 4.0)
        self.assertEqual(extract_number("twenty two"), 22)
        self.assertEqual(extract_number("two hundred"), 200)
        self.assertEqual(extract_number("nine thousand"), 9000)
        self.assertEqual(extract_number("six hundred sixty six"), 666)
        self.assertEqual(extract_number("two million"), 2000000)
        self.assertEqual(
            extract_number("two million five hundred thousand "
                           "tons of spinning metal"), 2500000)
        self.assertEqual(extract_number("six trillion"), 6000000000000.0)
        self.assertEqual(extract_number("six trillion", short_scale=False),
                         6e+18)
        self.assertEqual(extract_number("one point five"), 1.5)
        self.assertEqual(extract_number("three dot fourteen"), 3.14)
        self.assertEqual(extract_number("zero point two"), 0.2)
        self.assertEqual(extract_number("billions of years older"),
                         1000000000.0)
        self.assertEqual(
            extract_number("billions of years older", short_scale=False),
            1000000000000.0)
        self.assertEqual(extract_number("one hundred thousand"), 100000)
        self.assertEqual(extract_number("minus 2"), -2)
        self.assertEqual(extract_number("negative seventy"), -70)
        self.assertEqual(extract_number("thousand million"), 1000000000)
        self.assertEqual(extract_number("sixth third"), 1 / 6 / 3)
        self.assertEqual(extract_number("sixth third", ordinals=True), 3)
        self.assertEqual(extract_number("thirty second"), 30)
        self.assertEqual(extract_number("thirty second", ordinals=True), 32)
        self.assertEqual(
            extract_number("this is the billionth test", ordinals=True), 1e09)
        self.assertEqual(extract_number("this is the billionth test"), 1e-9)
        self.assertEqual(
            extract_number("this is the billionth test",
                           ordinals=True,
                           short_scale=False), 1e12)
        self.assertEqual(
            extract_number("this is the billionth test", short_scale=False),
            1e-12)
        # TODO handle this case
        # self.assertEqual(
        #    extract_number("6 dot six six six"),
        #    6.666)
        self.assertTrue(extract_number("The tennis player is fast") is False)
        self.assertTrue(extract_number("fraggle") is False)

        self.assertTrue(extract_number("fraggle zero") is not False)
        self.assertEqual(extract_number("fraggle zero"), 0)

        self.assertTrue(extract_number("grobo 0") is not False)
        self.assertEqual(extract_number("grobo 0"), 0)

        self.assertEqual(extract_number("a couple of beers"), 2)
        self.assertEqual(extract_number("a couple hundred beers"), 200)
        self.assertEqual(extract_number("a couple thousand beers"), 2000)
Ejemplo n.º 16
0
 def test_extractnumber_ca(self):
     self.assertEqual(
         extract_number("aquest és el primer intent", lang="ca"), 1)
     self.assertEqual(
         extract_number("i aquesta la segona prova", lang="ca"), 2)
     self.assertEqual(extract_number("això l'intent 2", lang="ca"), 2)
     self.assertEqual(extract_number("això és un terç de pizza", lang="ca"),
                      1.0 / 3.0)
     self.assertEqual(
         extract_number("axiò és la prova del número quatre", lang="ca"), 4)
     self.assertEqual(extract_number("un terç de tassa", lang="ca"),
                      1.0 / 3.0)
     self.assertEqual(extract_number("3 tasses", lang="ca"), 3)
     self.assertEqual(extract_number("1/3 tassa", lang="ca"), 1.0 / 3.0)
     self.assertEqual(extract_number("quart d'hora", lang="ca"), 0.25)
     self.assertEqual(extract_number("1/4 hora", lang="ca"), 0.25)
     self.assertEqual(extract_number("un quart d'hora", lang="ca"), 0.25)
     self.assertEqual(extract_number("2/3 pinga", lang="ca"), 2.0 / 3.0)
     self.assertEqual(extract_number("3/4 pinga", lang="ca"), 3.0 / 4.0)
     self.assertEqual(extract_number("1 i 3/4 cafè", lang="ca"), 1.75)
     self.assertEqual(extract_number("1 cafè i mig", lang="ca"), 1.5)
     self.assertEqual(extract_number("un cafè i un mig", lang="ca"), 1.5)
     self.assertEqual(extract_number("tres quarts de xocolata", lang="ca"),
                      3.0 / 4.0)
     self.assertEqual(extract_number("Tres quarts de xocolate", lang="ca"),
                      3.0 / 4.0)
     self.assertEqual(extract_number("tres quart de xocolata", lang="ca"),
                      3.0 / 4.0)
     self.assertEqual(extract_number("set coma cinc", lang="ca"), 7.5)
     self.assertEqual(extract_number("set coma 5", lang="ca"), 7.5)
     self.assertEqual(extract_number("set i mig", lang="ca"), 7.5)
     self.assertEqual(extract_number("set amb vuitanta", lang="ca"), 7.80)
     self.assertEqual(extract_number("set i vuit", lang="ca"), 7.8)
     self.assertEqual(extract_number("set coma zero vuit", lang="ca"), 7.08)
     self.assertEqual(extract_number("set coma zero zero vuit", lang="ca"),
                      7.008)
     self.assertEqual(extract_number("vint trenta ens", lang="ca"),
                      20.0 / 30.0)
     self.assertEqual(extract_number("dos", lang="ca"), 2)
     self.assertEqual(extract_number("dues", lang="ca"), 2)
     self.assertEqual(extract_number("tres", lang="ca"), 3)
     self.assertEqual(extract_number("quatre", lang="ca"), 4)
     self.assertEqual(extract_number("deu", lang="ca"), 10)
     self.assertEqual(extract_number("trenta-cinc", lang="ca"), 35)
     self.assertEqual(extract_number("seixanta-sis", lang="ca"), 66)
     self.assertEqual(extract_number("vint-i-dues", lang="ca"), 22)
     self.assertEqual(extract_number("vint-i-dos", lang="ca"), 22)
     self.assertEqual(extract_number("quatre-centes", lang="ca"), 400)
     self.assertEqual(extract_number("cinc-cents", lang="ca"), 500)
     self.assertEqual(
         extract_number("sis coma sis-cents seixanta", lang="ca"), 6.66)
     self.assertEqual(extract_number("sis-cents seixanta-sis", lang="ca"),
                      666)
     self.assertEqual(extract_number("sis-cents punt zero sis", lang="ca"),
                      600.06)
     self.assertEqual(
         extract_number("sis-cents coma zero zero sis", lang="ca"), 600.006)
     self.assertEqual(
         extract_number("tres-cents coma zero zero tres", lang="ca"),
         300.003)
Ejemplo n.º 17
0
 def test_extract_number(self):
     self.assertEqual(extract_number("dit is de eerste Test",
                                     lang=LANG, ordinals=True), 1)
     self.assertEqual(extract_number("dit is 2 Test", lang=LANG), 2)
     self.assertEqual(extract_number("dit is tweede Test", lang=LANG,
                                     ordinals=True),
                      2)
     self.assertEqual(
         extract_number("dit is Test drie", lang=LANG), 3)
     self.assertEqual(
         extract_number("dit is Test Drie", lang=LANG), 3)
     self.assertEqual(
         extract_number("dit is de Test Nummer 4", lang=LANG), 4)
     self.assertEqual(extract_number("één derde kopje",
                                     lang=LANG), 1.0 / 3.0)
     self.assertEqual(extract_number("drie kopjes", lang=LANG), 3)
     self.assertEqual(extract_number("1/3 kopje", lang=LANG), 1.0 / 3.0)
     self.assertEqual(extract_number("een kwart kopje", lang=LANG),
                      0.25)
     self.assertEqual(extract_number("1/4 kopje", lang=LANG), 0.25)
     self.assertEqual(extract_number("kwart kopje", lang=LANG), 0.25)
     self.assertEqual(extract_number("2/3 kopje", lang=LANG), 2.0 / 3.0)
     self.assertEqual(extract_number("3/4 kopje", lang=LANG), 3.0 / 4.0)
     self.assertEqual(extract_number("1 en 3/4 kopje", lang=LANG),
                      1.75)
     self.assertEqual(extract_number("1 kopje en een half",
                                     lang=LANG), 1.5)
     self.assertEqual(extract_number("anderhalf kopje",
                                     lang=LANG), 1.5)
     self.assertEqual(extract_number("driekwart kopje", lang=LANG),
                      3.0 / 4.0)
     self.assertEqual(extract_number("driekwart kopje", lang=LANG),
                      3.0 / 4.0)
Ejemplo n.º 18
0
    def test_extractnumber_pt(self):
        self.assertEqual(extract_number("isto e o primeiro teste", lang="pt"),
                         1)
        self.assertEqual(extract_number("isto e o 2 teste", lang="pt"), 2)
        self.assertEqual(extract_number("isto e o segundo teste", lang="pt"),
                         2)
        self.assertEqual(extract_number("isto e um terço de teste", lang="pt"),
                         1.0 / 3.0)
        self.assertEqual(
            extract_number("isto e o teste numero quatro", lang="pt"), 4)
        self.assertEqual(extract_number("um terço de chavena", lang="pt"),
                         1.0 / 3.0)
        self.assertEqual(extract_number("3 canecos", lang="pt"), 3)
        self.assertEqual(extract_number("1/3 canecos", lang="pt"), 1.0 / 3.0)
        self.assertEqual(extract_number("quarto de hora", lang="pt"), 0.25)
        self.assertEqual(extract_number("1/4 hora", lang="pt"), 0.25)
        self.assertEqual(extract_number("um quarto hora", lang="pt"), 0.25)
        self.assertEqual(extract_number("2/3 pinga", lang="pt"), 2.0 / 3.0)
        self.assertEqual(extract_number("3/4 pinga", lang="pt"), 3.0 / 4.0)
        self.assertEqual(extract_number("1 e 3/4 cafe", lang="pt"), 1.75)
        self.assertEqual(extract_number("1 cafe e meio", lang="pt"), 1.5)
        self.assertEqual(extract_number("um cafe e um meio", lang="pt"), 1.5)
        self.assertEqual(
            extract_number("tres quartos de chocolate", lang="pt"), 3.0 / 4.0)
        self.assertEqual(
            extract_number("Tres quartos de chocolate", lang="pt"), 3.0 / 4.0)
        self.assertEqual(extract_number("três quarto de chocolate", lang="pt"),
                         3.0 / 4.0)
        self.assertEqual(extract_number("sete ponto cinco", lang="pt"), 7.5)
        self.assertEqual(extract_number("sete ponto 5", lang="pt"), 7.5)
        self.assertEqual(extract_number("sete e meio", lang="pt"), 7.5)
        self.assertEqual(extract_number("sete e oitenta", lang="pt"), 7.80)
        self.assertEqual(extract_number("sete e oito", lang="pt"), 7.8)
        self.assertEqual(extract_number("sete e zero oito", lang="pt"), 7.08)
        self.assertEqual(extract_number("sete e zero zero oito", lang="pt"),
                         7.008)
        self.assertEqual(extract_number("vinte treze avos", lang="pt"),
                         20.0 / 13.0)
        self.assertEqual(
            extract_number("seis virgula seiscentos e sessenta", lang="pt"),
            6.66)
        self.assertEqual(
            extract_number("seiscentos e sessenta e seis", lang="pt"), 666)

        self.assertEqual(
            extract_number("seiscentos ponto zero seis", lang="pt"), 600.06)
        self.assertEqual(
            extract_number("seiscentos ponto zero zero seis", lang="pt"),
            600.006)
        self.assertEqual(
            extract_number("seiscentos ponto zero zero zero seis", lang="pt"),
            600.0006)
Ejemplo n.º 19
0
    def test_extract_number(self):
        self.assertEqual(extract_number("tohle je první test",
                                        ordinals=True), 1)
        self.assertEqual(extract_number("tohle je 2 test"), 2)
        self.assertEqual(extract_number("tohle je druhý test",
                                        ordinals=True), 2)
        #self.assertEqual(extract_number("tohle je třetí test"), 1.0 / 3.0)
        self.assertEqual(extract_number("tohle je třetí test",
                                        ordinals=True), 3.0)
        self.assertEqual(extract_number("ten čtvrtý", ordinals=True), 4.0)
        self.assertEqual(extract_number(
            "ten třicátý šestý", ordinals=True), 36.0)
        self.assertEqual(extract_number("tohle je test číslo 4"), 4)
        self.assertEqual(extract_number("jedna třetina šálku"), 1.0 / 3.0)
        self.assertEqual(extract_number("tři šálky"), 3)
        self.assertEqual(extract_number("1/3 šálku"), 1.0 / 3.0)
        self.assertEqual(extract_number("čtvrtina šálku"), 0.25)
        self.assertEqual(extract_number("1/4 cup"), 0.25)
        self.assertEqual(extract_number("jedna čtvrtina šálku"), 0.25)
        self.assertEqual(extract_number("2/3 šálků"), 2.0 / 3.0)
        self.assertEqual(extract_number("3/4 šálků"), 3.0 / 4.0)
        self.assertEqual(extract_number("1 a 3/4 šálků"), 1.75)
        self.assertEqual(extract_number("1 šálek a půl"), 1.5)
        self.assertEqual(extract_number("jeden šálek a polovina"), 1.5)
        self.assertEqual(extract_number("jedna a půl šálků"), 1.5)
        self.assertEqual(extract_number("jedna a jedna polovina šálků"), 1.5)
        self.assertEqual(extract_number("tři čtvrtina šálků"), 3.0 / 4.0)
        self.assertEqual(extract_number("tři čtvrtiny šálků"), 3.0 / 4.0)
        self.assertEqual(extract_number("dvacet dva"), 22)
        self.assertEqual(extract_number(
            "Dvacet dva s velkým písmenam na začátku"), 22)
        self.assertEqual(extract_number(
            "dvacet Dva s dva krát velkým písmem"), 22)
        self.assertEqual(extract_number(
            "dvacet Dva s různou velikostí písmen"), 22)
        self.assertEqual(extract_number("Dvacet dva a Tři Pětiny"), 22.6)
        self.assertEqual(extract_number("dvě sto"), 200)
        self.assertEqual(extract_number("devět tisíc"), 9000)
        self.assertEqual(extract_number("šest sto šedesát šest"), 666)
        self.assertEqual(extract_number("dva million"), 2000000)
        self.assertEqual(extract_number("dva million pět sto tisíc "
                                        "tun žhavého kovu"), 2500000)
        self.assertEqual(extract_number("šest trillion"), 6000000000000.0)
        self.assertEqual(extract_number("šest trilion", short_scale=False),
                         6e+18)
        self.assertEqual(extract_number("jedna tečka pět"), 1.5)
        self.assertEqual(extract_number("tři tečka čtrnáct"), 3.14)
        self.assertEqual(extract_number("nula tečka dva"), 0.2)
        self.assertEqual(extract_number("billion roků "),
                         1000000000.0)
        self.assertEqual(extract_number("bilion roků",
                                        short_scale=False),
                         1000000000000.0)
        self.assertEqual(extract_number("jedno sto tisíc"), 100000)
        self.assertEqual(extract_number("mínus 2"), -2)
        self.assertEqual(extract_number("záp**né sedmdesát"), -70)
        self.assertEqual(extract_number("tisíc million"), 1000000000)
        self.assertEqual(extract_number("miliarda", short_scale=False),
                         1000000000)
        self.assertEqual(extract_number("šestina třetina"),
                         1 / 6 / 3)
        self.assertEqual(extract_number("šestina třetí", ordinals=True),
                         3)
        self.assertEqual(extract_number("třicet sekund"), 30)
        self.assertEqual(extract_number("třicátý druhý", ordinals=True), 32)
        self.assertEqual(extract_number("tohle je billiontý test",
                                        ordinals=True), 1e09)
        print("tohle udělat později")
        #self.assertEqual(extract_number("tohle je billiontý test"), 1e-9)

        self.assertEqual(extract_number("tohle je biliontý test",
                                        ordinals=True,
                                        short_scale=False), 1e12)
        print("tohle udělat později")
        # self.assertEqual(extract_number("tohle je biliontý test",
        # short_scale=False), 1e-12)

        # Verify non-power multiples of ten no longer discard
        # adjacent multipliers
        self.assertEqual(extract_number("dvacet tisíc"), 20000)
        self.assertEqual(extract_number("padesát million"), 50000000)

        # Verify smaller powers of ten no longer cause miscalculation of larger
        # powers of ten (see MycroftAI#86)
        self.assertEqual(extract_number("dvacet billion tři sto million \
                                        devět sto padesát tisíc šest sto \
                                        sedmdesát pět tečka osm"),
                         20300950675.8)
        self.assertEqual(extract_number("devět sto devadesát devět million devět \
                                        sto devadesát devět tisíc devět \
                                        sto devadesát devět tečka devět"),
                         999999999.9)

        # TODO why does "trillion" result in xxxx.0?
        self.assertEqual(extract_number("osm sto trillion dva sto \
                                        padesát sedm"), 800000000000257.0)

        # TODO handle this case
        # self.assertEqual(
        #    extract_number("6 dot six six six"),
        #    6.666)
        self.assertTrue(extract_number("Tenisový hráč je rychlý") is False)
        self.assertTrue(extract_number("křehký") is False)

        self.assertTrue(extract_number("křehká nula") is not False)
        self.assertEqual(extract_number("křehká nula"), 0)

        #self.assertTrue(extract_number("grobo 0") is not False)
        #self.assertEqual(extract_number("grobo 0"), 0)

        self.assertEqual(extract_number("dvojice piv"), 2)
        self.assertEqual(extract_number("dvojice sto piv"), 200)
        self.assertEqual(extract_number("dvojice tisíc piv"), 2000)

        self.assertEqual(extract_number(
            "tohle je 7 test", ordinals=True), 7)
        self.assertEqual(extract_number(
            "tohle je 7 test", ordinals=False), 7)
        self.assertTrue(extract_number("tohle je n. test") is False)
        self.assertEqual(extract_number("tohle je 1. test"), 1)
        self.assertEqual(extract_number("tohle je 2. test"), 2)
        self.assertEqual(extract_number("tohle je 3. test"), 3)
        self.assertEqual(extract_number("tohle je 31. test"), 31)
        self.assertEqual(extract_number("tohle je 32. test"), 32)
        self.assertEqual(extract_number("tohle je 33. test"), 33)
        self.assertEqual(extract_number("tohle je 34. test"), 34)
        self.assertEqual(extract_number("celkem 100%"), 100)
Ejemplo n.º 20
0
 def test_extract_number_es(self):
     self.assertEqual(extract_number("sis punt dos", lang='ca'), 6.2)
Ejemplo n.º 21
0
 def test_extractnumber_sv(self):
     self.assertEqual(extract_number("1 och en halv deciliter",
                                     lang='sv-se'), 1.5)
     self.assertEqual(extract_number("det här är det första testet",
                                     lang='sv-se'), 1)
     self.assertEqual(extract_number("det här är test nummer 2",
                                     lang='sv-se'), 2)
     self.assertEqual(extract_number("det här är det andra testet",
                                     lang='sv-se'), 2)
     self.assertEqual(extract_number("det här är tredje testet",
                                     lang='sv-se'), 3)
     self.assertEqual(extract_number("det här är test nummer 4",
                                     lang='sv-se'), 4)
     self.assertEqual(extract_number("en tredjedels dl",
                                     lang='sv-se'), 1.0 / 3.0)
     self.assertEqual(extract_number("tre deciliter",
                                     lang='sv-se'), 3)
     self.assertEqual(extract_number("Tre deciliter",
                                     lang='sv-se'), 3)
     self.assertEqual(extract_number("1/3 deciliter",
                                     lang='sv-se'), 1.0 / 3.0)
     self.assertEqual(extract_number("en kvarts dl",
                                     lang='sv-se'), 0.25)
     self.assertEqual(extract_number("1/4 dl",
                                     lang='sv-se'), 0.25)
     self.assertEqual(extract_number("en kvarts dl",
                                     lang='sv-se'), 0.25)
     self.assertEqual(extract_number("2/3 dl",
                                     lang='sv-se'), 2.0 / 3.0)
     self.assertEqual(extract_number("3/4 dl",
                                     lang='sv-se'), 3.0 / 4.0)
     self.assertEqual(extract_number("1 och 3/4 dl",
                                     lang='sv-se'), 1.75)
     self.assertEqual(extract_number("tre fjärdedels dl",
                                     lang='sv-se'), 3.0 / 4.0)
     self.assertEqual(extract_number("trekvarts kopp",
                                     lang='sv-se'), 3.0 / 4.0)
Ejemplo n.º 22
0
 def test_comma_fraction_logic_es(self):
     # Logic has not been written to parse "#,#" as "#.#"
     # English-style decimal numbers work because they just get float(str)ed
     self.assertEqual(extract_number("2,0", lang='es'), 2.0)
Ejemplo n.º 23
0
 def test_extractnumber_fr(self):
     self.assertEqual(extract_number("voici le premier test", lang="fr-fr"),
                      1)
     self.assertEqual(extract_number("c'est 2 tests", lang="fr-fr"), 2)
     self.assertEqual(extract_number("voici le second test", lang="fr-fr"),
                      2)
     self.assertEqual(extract_number("voici trois tests", lang="fr-fr"), 3)
     self.assertEqual(
         extract_number("voici le test numéro 4", lang="fr-fr"), 4)
     self.assertEqual(extract_number("un tiers de litre", lang="fr-fr"),
                      1.0 / 3.0)
     self.assertEqual(extract_number("3 cuillères", lang="fr-fr"), 3)
     self.assertEqual(extract_number("1/3 de litre", lang="fr-fr"),
                      1.0 / 3.0)
     self.assertEqual(extract_number("un quart de bol", lang="fr-fr"), 0.25)
     self.assertEqual(extract_number("1/4 de verre", lang="fr-fr"), 0.25)
     self.assertEqual(extract_number("2/3 de bol", lang="fr-fr"), 2.0 / 3.0)
     self.assertEqual(extract_number("3/4 de bol", lang="fr-fr"), 3.0 / 4.0)
     self.assertEqual(extract_number("1 et 3/4 de bol", lang="fr-fr"), 1.75)
     self.assertEqual(extract_number("1 bol et demi", lang="fr-fr"), 1.5)
     self.assertEqual(extract_number("un bol et demi", lang="fr-fr"), 1.5)
     self.assertEqual(extract_number("un et demi bols", lang="fr-fr"), 1.5)
     self.assertEqual(extract_number("un bol et un demi", lang="fr-fr"),
                      1.5)
     self.assertEqual(extract_number("trois quarts de bol", lang="fr-fr"),
                      3.0 / 4.0)
     self.assertEqual(extract_number("32.2 degrés", lang="fr-fr"), 32.2)
     self.assertEqual(extract_number("2 virgule 2 cm", lang="fr-fr"), 2.2)
     self.assertEqual(extract_number("2 virgule 0 2 cm", lang="fr-fr"),
                      2.02)
     self.assertEqual(extract_number("ça fait virgule 2 cm", lang="fr-fr"),
                      0.2)
     self.assertEqual(extract_number("point du tout", lang="fr-fr"), False)
     self.assertEqual(extract_number("32.00 secondes", lang="fr-fr"), 32)
     self.assertEqual(
         extract_number("mange trente-et-une bougies", lang="fr-fr"), 31)
     self.assertEqual(extract_number("un trentième", lang="fr-fr"),
                      1.0 / 30.0)
     self.assertEqual(extract_number("un centième", lang="fr-fr"), 0.01)
     self.assertEqual(extract_number("un millième", lang="fr-fr"), 0.001)
     self.assertEqual(extract_number("un 20e", lang="fr-fr"), 1.0 / 20.0)
Ejemplo n.º 24
0
    def test_extract_number(self):
        self.assertEqual(
            extract_number("this is the first test", ordinals=True), 1)
        self.assertEqual(extract_number("this is 2 test"), 2)
        self.assertEqual(extract_number("this is second test", ordinals=True),
                         2)
        self.assertEqual(extract_number("this is the third test"), 1.0 / 3.0)
        self.assertEqual(
            extract_number("this is the third test", ordinals=True), 3.0)
        self.assertEqual(extract_number("the fourth one", ordinals=True), 4.0)
        self.assertEqual(extract_number("the thirty sixth one", ordinals=True),
                         36.0)
        self.assertEqual(extract_number("this is test number 4"), 4)
        self.assertEqual(extract_number("one third of a cup"), 1.0 / 3.0)
        self.assertEqual(extract_number("three cups"), 3)
        self.assertEqual(extract_number("1/3 cups"), 1.0 / 3.0)
        self.assertEqual(extract_number("quarter cup"), 0.25)
        self.assertEqual(extract_number("1/4 cup"), 0.25)
        self.assertEqual(extract_number("one fourth cup"), 0.25)
        self.assertEqual(extract_number("2/3 cups"), 2.0 / 3.0)
        self.assertEqual(extract_number("3/4 cups"), 3.0 / 4.0)
        self.assertEqual(extract_number("1 and 3/4 cups"), 1.75)
        self.assertEqual(extract_number("1 cup and a half"), 1.5)
        self.assertEqual(extract_number("one cup and a half"), 1.5)
        self.assertEqual(extract_number("one and a half cups"), 1.5)
        self.assertEqual(extract_number("one and one half cups"), 1.5)
        self.assertEqual(extract_number("three quarter cups"), 3.0 / 4.0)
        self.assertEqual(extract_number("three quarters cups"), 3.0 / 4.0)
        self.assertEqual(extract_number("twenty two"), 22)
        self.assertEqual(
            extract_number("Twenty two with a leading capital letter"), 22)
        self.assertEqual(extract_number("twenty Two with Two capital letters"),
                         22)
        self.assertEqual(
            extract_number("twenty Two with mixed capital letters"), 22)
        self.assertEqual(extract_number("Twenty two and Three Fifths"), 22.6)
        self.assertEqual(extract_number("two hundred"), 200)
        self.assertEqual(extract_number("nine thousand"), 9000)
        self.assertEqual(extract_number("six hundred sixty six"), 666)
        self.assertEqual(extract_number("two million"), 2000000)
        self.assertEqual(
            extract_number("two million five hundred thousand "
                           "tons of spinning metal"), 2500000)
        self.assertEqual(extract_number("six trillion"), 6000000000000.0)
        self.assertEqual(extract_number("six trillion", short_scale=False),
                         6e+18)
        self.assertEqual(extract_number("one point five"), 1.5)
        self.assertEqual(extract_number("three dot fourteen"), 3.14)
        self.assertEqual(extract_number("zero point two"), 0.2)
        self.assertEqual(extract_number("billions of years older"),
                         1000000000.0)
        self.assertEqual(
            extract_number("billions of years older", short_scale=False),
            1000000000000.0)
        self.assertEqual(extract_number("one hundred thousand"), 100000)
        self.assertEqual(extract_number("minus 2"), -2)
        self.assertEqual(extract_number("negative seventy"), -70)
        self.assertEqual(extract_number("thousand million"), 1000000000)
        self.assertEqual(extract_number("sixth third"), 1 / 6 / 3)
        self.assertEqual(extract_number("sixth third", ordinals=True), 3)
        self.assertEqual(extract_number("thirty second"), 30)
        self.assertEqual(extract_number("thirty second", ordinals=True), 32)
        self.assertEqual(
            extract_number("this is the billionth test", ordinals=True), 1e09)
        self.assertEqual(extract_number("this is the billionth test"), 1e-9)
        self.assertEqual(
            extract_number("this is the billionth test",
                           ordinals=True,
                           short_scale=False), 1e12)
        self.assertEqual(
            extract_number("this is the billionth test", short_scale=False),
            1e-12)

        # Verify non-power multiples of ten no longer discard
        # adjacent multipliers
        self.assertEqual(extract_number("twenty thousand"), 20000)
        self.assertEqual(extract_number("fifty million"), 50000000)

        # Verify smaller powers of ten no longer cause miscalculation of larger
        # powers of ten (see MycroftAI#86)
        self.assertEqual(
            extract_number("twenty billion three hundred million \
                                        nine hundred fifty thousand six hundred \
                                        seventy five point eight"),
            20300950675.8)
        self.assertEqual(
            extract_number("nine hundred ninety nine million nine \
                                        hundred ninety nine thousand nine \
                                        hundred ninety nine point nine"),
            999999999.9)

        # TODO why does "trillion" result in xxxx.0?
        self.assertEqual(
            extract_number("eight hundred trillion two hundred \
                                        fifty seven"), 800000000000257.0)

        # TODO handle this case
        # self.assertEqual(
        #    extract_number("6 dot six six six"),
        #    6.666)
        self.assertTrue(extract_number("The tennis player is fast") is False)
        self.assertTrue(extract_number("fraggle") is False)

        self.assertTrue(extract_number("fraggle zero") is not False)
        self.assertEqual(extract_number("fraggle zero"), 0)

        self.assertTrue(extract_number("grobo 0") is not False)
        self.assertEqual(extract_number("grobo 0"), 0)

        self.assertEqual(extract_number("a couple of beers"), 2)
        self.assertEqual(extract_number("a couple hundred beers"), 200)
        self.assertEqual(extract_number("a couple thousand beers"), 2000)

        self.assertEqual(extract_number("this is the 7th test", ordinals=True),
                         7)
        self.assertEqual(
            extract_number("this is the 7th test", ordinals=False), 7)
        self.assertTrue(extract_number("this is the nth test") is False)
        self.assertEqual(extract_number("this is the 1st test"), 1)
        self.assertEqual(extract_number("this is the 2nd test"), 2)
        self.assertEqual(extract_number("this is the 3rd test"), 3)
        self.assertEqual(extract_number("this is the 31st test"), 31)
        self.assertEqual(extract_number("this is the 32nd test"), 32)
        self.assertEqual(extract_number("this is the 33rd test"), 33)
        self.assertEqual(extract_number("this is the 34th test"), 34)

        self.assertEqual(
            extract_number("you are the second one", ordinals=False), 1)
        self.assertEqual(
            extract_number("you are the second one", ordinals=True), 2)
        self.assertEqual(extract_number("you are the 1st one"), 1)
        self.assertEqual(extract_number("you are the 2nd one"), 2)
        self.assertEqual(extract_number("you are the 3rd one"), 3)
        self.assertEqual(extract_number("you are the 8th one"), 8)
        self.assertEqual(extract_number("totally 100%"), 100)