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")
 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")
    def handle_team_query(self, message):
        teamNum = int(extractnumber(message.data["utterance"]))
        teamLower = teamNum % 100  # 4
        teamUpper = (teamNum - teamLower) / 100  # 4
        if (teamLower > 9):
            speak = pronounce_number(int(teamUpper)) + " " + pronounce_number(
                int(teamLower))
        else:
            speak = pronounce_number(
                int(teamUpper)) + " oh " + pronounce_number(int(teamLower))

        self.log.debug("Team #:" + str(teamNum))
        if teamNum in self.teams1:
            speechData = {
                "num": self.teams1[teamNum]["number"],
                "name": self.teams1[teamNum]["name"],
                "rank": self.teams1[teamNum]["rank"],
                "div": self.event1["subtitle"],
                "ps": int(self.teams1[teamNum]["powerScore"])
            }
            self.speak_dialog("team.info", speechData)

        else:
            if teamNum in self.teams2:
                speechData = {
                    "num": self.teams2[teamNum]["number"],
                    "name": self.teams2[teamNum]["name"],
                    "rank": self.teams2[teamNum]["rank"],
                    "div": self.event2["subtitle"],
                    "ps": int(self.teams2[teamNum]["powerScore"])
                }
                self.speak_dialog("team.info", speechData)
            else:
                self.speak("I don't know them.")
 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")
 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")
 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")
    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")
    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")
 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")
 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")
Exemple #11
0
    def handle_tracker_iss(self, message):
        # get the 'current' latitude and longitude of the ISS from open-notify.org in JSON
        reqISSLocation = requests.get(
            "http://api.open-notify.org/iss-now.json")
        issObj = json.loads(
            reqISSLocation.text)  # JSON payload of ISS location data
        latISS = issObj['iss_position']['latitude']
        lngISS = issObj['iss_position']['longitude']
        latISSstr = pronounce_number(float(latISS), lang=self.lang, places=4)
        lngISSstr = pronounce_number(float(lngISS), lang=self.lang, places=4)
        lang = self.lang[:2]
        # construct a string witj ISS lat & long to determine a geographic object/toponym associated with it
        # This is "Reverse Gecoding" availbe from geonames.org
        # Sign up for a free user name at http://www.geonames.org/ and repalce YourUserName with it
        # !! remember to activate web servoces for your user name !!
        oceanGeoNamesReq = "http://api.geonames.org/oceanJSON?lat=" + latISS + "&lng=" + lngISS + "&lang=" + lang + "&username=mycroft_iss_tracker"
        landGeoNamesReq = "http://api.geonames.org/countryCodeJSON?formatted=true&lat=" + latISS + "&lng=" + lngISS + "&lang=" + lang + "&username=mycroft_iss_tracker&style=full"

        self.log.info(oceanGeoNamesReq)
        self.log.info(landGeoNamesReq)

        # Since the Earth is 3/4 water, we'll chek to see if the ISS is over water first;
        # in the case where this is not so, we handle the exception by  searching for a country it is
        # over, and is this is not coded for on GenNames, we just we say we don't know

        oceanGeoNamesRes = requests.get(oceanGeoNamesReq)
        toponymObj = json.loads(oceanGeoNamesRes.text)
        try:
            toponym = "the " + toponymObj['ocean']['name']
        except KeyError:
            landGeoNamesRes = requests.get(landGeoNamesReq)
            toponymObj = json.loads(landGeoNamesRes.text)
            toponym = toponymObj['countryName']
        except Exception:
            toponym = "unknown"

        # print "the ISS is over: " + toponym
        if toponym == "unknown":
            self.speak_dialog("location.unknown", {
                "latitude": latISSstr,
                "longitude": lngISSstr
            })
        else:
            self.speak_dialog("location.current", {
                "latitude": latISSstr,
                "longitude": lngISSstr,
                "toponym": toponym
            })
Exemple #12
0
    def handle_heartbeat_intent(self, message):
        value = message.data.get("Value")

        if not value:
            self.speak_dialog("error.input.mh")
            return

        try:
            value = int(value)

        except Exception:
            self.speak_dialog("error.input.mh")
            return

        person = self.get_response("person.mh")
        person = "" if not person else person

        self.log.error(value)
        self.log.error(person)

        heartbeat_data = [(now_local(), "heartbeat", str(value), "", person)]

        confirm = self.ask_yesno("confirm.heartbeat.mh",
                                 {"value": pronounce_number(value)})

        if confirm == "yes":
            if not self.insert_db(heartbeat_data):
                self.speak_dialog("error.save.mh")
    def handle_status_timer(self, message):
        if not self.active_timers:
            self.speak_dialog("no.active.timer")
            return

        utt = message.data["utterance"]

        # If asking about all, or only 1 timer exists then speak
        if len(self.active_timers) == 1:
            timer_matches = self.active_timers
        else:
            # get max 2 matches, unless user explicitly asks for all
            result, timer_matches = self._get_timer_matches(utt, max_results=2)
            if result == "User Cancelled":
                return

        # Speak the relevant dialog
        if timer_matches is None:
            self.speak_dialog('timer.not.found')
        else:
            number_of_timers = len(timer_matches)
            if number_of_timers > 1:
                num = pronounce_number(number_of_timers)
                self.speak_dialog('number.of.timers', {'num': num})
            for timer in timer_matches:
                self._speak_timer(timer)
Exemple #14
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")
 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")
 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")
 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")
def nice_duration(duration, lang="en-us", speech=True):
    """ Convert duration in seconds to a nice spoken timespan

    Examples:
       duration = 60  ->  "1:00" or "one minute"
       duration = 163  ->  "2:43" or "two minutes forty three seconds"

    Args:
        duration: time, in seconds
        speech (bool): format for speech (True) or display (False)
    Returns:
        str: timespan as a string
    """
    days = duration // 86400
    hours = duration // 3600 % 24
    minutes = duration // 60 % 60
    seconds = duration % 60
    if speech:
        out = ""
        if days > 0:
            out += pronounce_number(days)
            out += " days " if days == 1 else " day "
        if hours > 0:
            out += pronounce_number(hours)
            out += " hour " if hours == 1 else " hours "
        if minutes > 0:
            out += pronounce_number(minutes)
            out += " minute " if minutes == 1 else " minutes "
        if seconds > 0:
            out += pronounce_number(seconds)
            out += " second" if seconds == 1 else " seconds"
        return out
    else:
        # M:SS, MM:SS, H:MM:SS, Dd H:MM:SS format
        out = ""
        if days > 0:
            out = str(days) + "d "
        if hours > 0:
            out += str(hours) + ":"
        if minutes < 10 and hours > 0:
            out += "0"
        out += str(minutes) + ":"
        if seconds < 10:
            out += "0"
        out += str(seconds)
        return out
Exemple #19
0
    def ask_selection(self,
                      options,
                      dialog='',
                      data=None,
                      min_conf=0.65,
                      numeric=False):
        """Read options, ask dialog question and wait for an answer.

        This automatically deals with fuzzy matching and selection by number
        e.g.
            "first option"
            "last option"
            "second option"
            "option number four"

        Arguments:
              options (list): list of options to present user
              dialog (str): a dialog id or string to read AFTER all options
              data (dict): Data used to render the dialog
              min_conf (float): minimum confidence for fuzzy match, if not
                                reached return None
              numeric (bool): speak options as a numeric menu
        Returns:
              string: list element selected by user, or None
        """
        assert isinstance(options, list)

        if not len(options):
            return None
        elif len(options) == 1:
            return options[0]

        if numeric:
            for idx, opt in enumerate(options):
                opt_str = "{number}, {option_text}".format(
                    number=pronounce_number(idx + 1, self.lang),
                    option_text=opt)

                self.speak(opt_str, wait=True)
        else:
            opt_str = join_list(options, "or", lang=self.lang) + "?"
            self.speak(opt_str, wait=True)

        resp = self.get_response(dialog=dialog, data=data)

        if resp:
            match, score = match_one(resp, options)
            if score < min_conf:
                if self.voc_match(resp, 'last'):
                    resp = options[-1]
                else:
                    num = extract_number(resp, self.lang, ordinals=True)
                    resp = None
                    if num and num < len(options):
                        resp = options[num - 1]
            else:
                resp = match
        return resp
 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")
 def test_large_numbers(self):
     self.assertEqual(
         pronounce_number(299792458, short_scale=True, lang="it"),
         "duecento novantanovemilioni, settecento "
         "novantaduemila, quattrocento cinquantotto")
     self.assertEqual(
         pronounce_number(299792458, short_scale=False, lang="it"),
         "duecento novantanove milioni, settecento "
         "novantaduemila, quattrocento cinquantotto")
     self.assertEqual(
         pronounce_number(100034000000299792458,
                          short_scale=True,
                          lang="it"),
         "centotrilioni, trentaquattrobiliardi, "
         "duecento novantanovemilioni, settecento "
         "novantaduemila, quattrocento cinquantotto")
     self.assertEqual(
         pronounce_number(100034000000299792458,
                          short_scale=False,
                          lang="it"),
         "cento trilioni, trentaquattromila miliardi, "
         "duecento novantanove milioni, settecento "
         "novantaduemila, quattrocento cinquantotto")
     self.assertEqual(
         pronounce_number(10000000000, short_scale=True, lang="it"),
         "diecimiliardi")
     self.assertEqual(
         pronounce_number(1000000000000, short_scale=True, lang="it"),
         "bilioni")
     self.assertEqual(
         pronounce_number(1000001, short_scale=True, lang="it"),
         "un milione, uno")
Exemple #22
0
    def handle_pressure_intent(self, message):
        top = self.get_response("top.mh")

        if not top:
            self.speak_dialog("error.input.mh")
            return

        try:
            top = float(top)

        except Exception:
            self.speak_dialog("error.input.mh")
            return

        bottom = self.get_response("bottom.mh")

        if not bottom:
            self.speak_dialog("error.input.mh")
            return

        try:
            bottom = float(bottom)

        except Exception:
            self.speak_dialog("error.input.mh")
            return

        person = self.get_response("person.mh")
        person = "" if not person else person

        self.log.error(top)
        self.log.error(bottom)
        self.log.error(person)

        pressure_data = [(now_local(), "pressure", str(top), "", person),
                         (now_local(), "pressure", str(bottom), "", person)]

        confirm = self.ask_yesno("confirm.pressure.mh", {
            "top": pronounce_number(top),
            "bottom": pronounce_number(bottom)
        })

        if confirm == "yes":
            if not self.insert_db(pressure_data):
                self.speak_dialog("error.save.mh")
 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")
Exemple #24
0
 def test_convert_negative_int(self):
     self.assertEqual(pronounce_number(-1), "negative one")
     self.assertEqual(pronounce_number(-10), "negative ten")
     self.assertEqual(pronounce_number(-15), "negative fifteen")
     self.assertEqual(pronounce_number(-20), "negative twenty")
     self.assertEqual(pronounce_number(-27), "negative twenty seven")
     self.assertEqual(pronounce_number(-30), "negative thirty")
     self.assertEqual(pronounce_number(-33), "negative thirty three")
 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")
 def test_convert_negative_int(self):
     self.assertEqual(pronounce_number(-1), "negative one")
     self.assertEqual(pronounce_number(-10), "negative ten")
     self.assertEqual(pronounce_number(-15), "negative fifteen")
     self.assertEqual(pronounce_number(-20), "negative twenty")
     self.assertEqual(pronounce_number(-27), "negative twenty seven")
     self.assertEqual(pronounce_number(-30), "negative thirty")
     self.assertEqual(pronounce_number(-33), "negative thirty three")
 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), "minus fünfzehn")
     self.assertEqual(pronounce_number(-20), "minus zwanzig")
     self.assertEqual(pronounce_number(-27), "minus siebenundzwanzig")
     self.assertEqual(pronounce_number(-30), "minus dreißig")
     self.assertEqual(pronounce_number(-33), "minus dreiunddreißig")
 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")
 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")
Exemple #30
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")
Exemple #31
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")
 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")
Exemple #33
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")
 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")
 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")
Exemple #36
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")
 def test_convert_negative_int_de(self):
     self.assertEqual(pronounce_number(-1, lang="de-de"), "minus eins")
     self.assertEqual(pronounce_number(-10, lang="de-de"), "minus zehn")
     self.assertEqual(pronounce_number(-15, lang="de-de"),
                      u"minus fünfzehn")
     self.assertEqual(pronounce_number(-20, lang="de-de"), "minus zwanzig")
     self.assertEqual(pronounce_number(-27, lang="de-de"),
                      "minus siebenundzwanzig")
     self.assertEqual(pronounce_number(-30, lang="de-de"), u"minus dreißig")
     self.assertEqual(pronounce_number(-33, lang="de-de"),
                      u"minus dreiunddreißig")
Exemple #38
0
 def test_convert_negative_int_de(self):
     self.assertEqual(pronounce_number(-1, lang="de-de"), "minus eins")
     self.assertEqual(pronounce_number(-10, lang="de-de"), "minus zehn")
     self.assertEqual(pronounce_number(-15, lang="de-de"),
                      u"minus fünfzehn")
     self.assertEqual(pronounce_number(-20, lang="de-de"), "minus zwanzig")
     self.assertEqual(pronounce_number(-27, lang="de-de"),
                      "minus siebenundzwanzig")
     self.assertEqual(pronounce_number(-30, lang="de-de"), u"minus dreißig")
     self.assertEqual(pronounce_number(-33, lang="de-de"),
                      u"minus dreiunddreißig")
 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")
Exemple #40
0
 def num_worker(self, line):
     ### translate numbers to int
     num = ""
     number = ""
     if not extract_numbers(line, lang=self.lang) == []:
         num = extract_numbers(line,
                               short_scale=False,
                               ordinals=False,
                               lang=self.lang)
     #num = re.sub(r'(\.0)', '', str(num))
     #num = re.findall(r'\d+', num)
     if not num is False:
         for item in num:
             print("item #" + str(item))
             if not pronounce_number(
                     float(item), lang=self.lang, short_scale=True) == []:
                 number = pronounce_number(float(item),
                                           lang=self.lang,
                                           short_scale=True)
             else:
                 number = ""
             line = line.replace(number, str(item))
             self.log.info(str(line))
     return line
 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")
Exemple #42
0
    def _normalized_numbers(self, sentence):
        """normalized numbers to word equivalent.

        Args:
            sentence (str): setence to speak

        Returns:
            stf: normalized sentences to speak
        """
        try:
            numbers = re.findall(r'\d+', sentence)
            normalized_num = [(num, pronounce_number(int(num)))
                              for num in numbers]
            for num, norm_num in normalized_num:
                sentence = sentence.replace(num, norm_num, 1)
        except TypeError:
            LOG.exception("type error in mimic2_tts.py _normalized_numbers()")
        return sentence
    def _normalized_numbers(self, sentence):
        """normalized numbers to word equivalent.

        Args:
            sentence (str): setence to speak

        Returns:
            stf: normalized sentences to speak
        """
        try:
            numbers = re.findall(r'\d+', sentence)
            normalized_num = [
                (num, pronounce_number(int(num)))
                for num in numbers
            ]
            for num, norm_num in normalized_num:
                sentence = sentence.replace(num, norm_num, 1)
        except TypeError:
            LOG.exception("type error in mimic2_tts.py _normalized_numbers()")
        return sentence
Exemple #44
0
 def match_room(self, my_room, wiserrooms): # Nudge room name towards best match of room from Wiser Hub
     rooms = ['house']
     pronounce_to_name = {'house':'house'}
     for room in wiserrooms:
         name = room.get("Name").lower()
         rooms.append(name)
         pronounce_to_name[name] = name
         ex_number = extract_number(name, short_scale=True, ordinals=False, lang=None)
         if ex_number != False: # add alternative with one set of spelled out numbers
             n_number = pronounce_number(ex_number, lang=None, places=2)
             name_num = name.replace(str(ex_number),n_number)
             #LOGGER.info("{} => {} => {}".format(ex_number, n_number, name_num))
             rooms.append(name_num)
             pronounce_to_name[name_num] = name
     #LOGGER.info(pronounce_to_name)
     #LOGGER.info(rooms)
     match, confidence = match_one(my_room, list(rooms))
     LOGGER.info("Match room: ({} <=> {}) @{:.4f} => {}".format(my_room, match, confidence, pronounce_to_name[match]))
     if confidence > 0.65:
         return pronounce_to_name[match]
     else:
         return my_room
Exemple #45
0
def nice_date_de(local_date):

    # dates are returned as, for example:
    # "Samstag, der siebte Juli zweitausendachtzehn"
    # this returns the years as regular numbers,
    # not 19 hundred ..., but one thousand nine hundred
    # which is fine from the year 2000

    de_months = [
        'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August',
        'September', 'October', 'November', 'Dezember'
    ]

    de_weekdays = [
        'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag',
        'Sonntag'
    ]

    return de_weekdays[local_date.weekday()] + ", der " \
            + pronounce_ordinal_de(local_date.day) + " " \
            + de_months[local_date.month - 1] \
            + " " + pronounce_number(local_date.year, lang = "de")
Exemple #46
0
    def handle_sugar_intent(self, message):
        value = message.data.get("Value")

        if not value:
            self.speak_dialog("error.input.mh")
            return

        try:
            value = float(value)

        except Exception:
            self.speak_dialog("error.input.mh")
            return

        meal_status = self.get_response("meal.mh")

        if not meal_status:
            return

        person = self.get_response("person.mh")
        person = "" if not person else person

        self.log.error(value)
        self.log.error(meal_status)
        self.log.error(person)

        sugar_data = [(now_local(), "diabetes", str(value), meal_status,
                       person)]

        confirm = self.ask_yesno("confirm.sugar.mh", {
            "meal": meal_status,
            "value": pronounce_number(value)
        })

        if confirm == "yes":
            if not self.insert_db(sugar_data):
                self.speak_dialog("error.save.mh")
 def test_convert_decimals_hu(self):
     self.assertEqual(pronounce_number(1.234, lang="hu-hu"),
                      "egy egész huszonhárom század")
     self.assertEqual(pronounce_number(21.234, lang="hu-hu"),
                      "huszonegy egész huszonhárom század")
     self.assertEqual(pronounce_number(21.234, lang="hu-hu", places=1),
                      "huszonegy egész két tized")
     self.assertEqual(pronounce_number(21.234, lang="hu-hu", places=0),
                      "huszonegy")
     self.assertEqual(pronounce_number(21.234, lang="hu-hu", places=3),
                      "huszonegy egész kétszázharmincnégy ezred")
     self.assertEqual(pronounce_number(21.234, lang="hu-hu", places=4),
                      "huszonegy egész kétezer-háromszáznegyven tízezred")
     self.assertEqual(pronounce_number(21.234, lang="hu-hu", places=5),
                      "huszonegy egész huszonháromezer-négyszáz százezred")
     self.assertEqual(pronounce_number(-1.234, lang="hu-hu"),
                      "mínusz egy egész huszonhárom század")
     self.assertEqual(pronounce_number(-21.234, lang="hu-hu"),
                      "mínusz huszonegy egész huszonhárom század")
     self.assertEqual(pronounce_number(-21.234, lang="hu-hu", places=1),
                      "mínusz huszonegy egész két tized")
     self.assertEqual(pronounce_number(-21.234, lang="hu-hu", places=0),
                      "mínusz huszonegy")
     self.assertEqual(pronounce_number(-21.234, lang="hu-hu", places=3),
                      "mínusz huszonegy egész kétszázharmincnégy ezred")
     self.assertEqual(pronounce_number(-21.234, lang="hu-hu", places=4),
                      "mínusz huszonegy egész "
                      "kétezer-háromszáznegyven tízezred")
     self.assertEqual(pronounce_number(-21.234, lang="hu-hu", places=5),
                      "mínusz huszonegy egész "
                      "huszonháromezer-négyszáz százezred")
 def test_convert_int_nl(self):
     self.assertEqual(pronounce_number(123456789123456789, lang="nl-nl"),
                      u"éénhonderddrieentwintig biljard "
                      "vierhonderdzesenvijftig biljoen "
                      "zevenhonderdnegenentachtig miljard "
                      "éénhonderddrieentwintig miljoen "
                      "vierhonderdzesenvijftigduizend"
                      "zevenhonderdnegenentachtig")
     self.assertEqual(pronounce_number(1, lang="nl-nl"), u"één")
     self.assertEqual(pronounce_number(10, lang="nl-nl"), "tien")
     self.assertEqual(pronounce_number(15, lang="nl-nl"), "vijftien")
     self.assertEqual(pronounce_number(20, lang="nl-nl"), "twintig")
     self.assertEqual(pronounce_number(27, lang="nl-nl"),
                      "zevenentwintig")
     self.assertEqual(pronounce_number(30, lang="nl-nl"), "dertig")
     self.assertEqual(pronounce_number(33, lang="nl-nl"), u"drieendertig")
     self.assertEqual(pronounce_number(71, lang="nl-nl"),
                      u"éénenzeventig")
     self.assertEqual(pronounce_number(80, lang="nl-nl"), "tachtig")
     self.assertEqual(pronounce_number(74, lang="nl-nl"),
                      "vierenzeventig")
     self.assertEqual(pronounce_number(79, lang="nl-nl"),
                      "negenenzeventig")
     self.assertEqual(pronounce_number(91, lang="nl-nl"),
                      u"éénennegentig")
     self.assertEqual(pronounce_number(97, lang="nl-nl"),
                      "zevenennegentig")
     self.assertEqual(pronounce_number(300, lang="nl-nl"), "driehonderd")
 def test_convert_decimals(self):
     self.assertEqual(pronounce_number(1.234),
                      "one point two three")
     self.assertEqual(pronounce_number(21.234),
                      "twenty one point two three")
     self.assertEqual(pronounce_number(21.234, places=1),
                      "twenty one point two")
     self.assertEqual(pronounce_number(21.234, places=0),
                      "twenty one")
     self.assertEqual(pronounce_number(21.234, places=3),
                      "twenty one point two three four")
     self.assertEqual(pronounce_number(21.234, places=4),
                      "twenty one point two three four")
     self.assertEqual(pronounce_number(21.234, places=5),
                      "twenty one point two three four")
     self.assertEqual(pronounce_number(-1.234),
                      "negative one point two three")
     self.assertEqual(pronounce_number(-21.234),
                      "negative twenty one point two three")
     self.assertEqual(pronounce_number(-21.234, places=1),
                      "negative twenty one point two")
     self.assertEqual(pronounce_number(-21.234, places=0),
                      "negative twenty one")
     self.assertEqual(pronounce_number(-21.234, places=3),
                      "negative twenty one point two three four")
     self.assertEqual(pronounce_number(-21.234, places=4),
                      "negative twenty one point two three four")
     self.assertEqual(pronounce_number(-21.234, places=5),
                      "negative twenty one point two three four")
 def test_convert_int(self):
     self.assertEqual(pronounce_number(0, lang="es"), "cero")
     self.assertEqual(pronounce_number(1, lang="es"), "uno")
     self.assertEqual(pronounce_number(10, lang="es"), "diez")
     self.assertEqual(pronounce_number(15, lang="es"), "quince")
     self.assertEqual(pronounce_number(21, lang="es"), "veintiuno")
     self.assertEqual(pronounce_number(27, lang="es"), "veintisiete")
     self.assertEqual(pronounce_number(30, lang="es"), "treinta")
     self.assertEqual(pronounce_number(19, lang="es"), "diecinueve")
     self.assertEqual(pronounce_number(88, lang="es"), "ochenta y ocho")
     self.assertEqual(pronounce_number(46, lang="es"), "cuarenta y seis")
     self.assertEqual(pronounce_number(99, lang="es"), "noventa y nueve")
 def test_convert_int_da(self):
     # self.assertEqual(pronounce_number(123456789123456789, lang="da-dk"),
     #                 "ethundredetreogtyvebilliarder"
     #                 "firehundredeseksoghalvtresbillioner"
     #                 "syvhundredeogfirsmiliarder"
     #                 "ethundredetreogtyvemillioner"
     #                 "firehundredeseksoghalvtrestusindesyvhundredeniog \
     #                  firs")
     self.assertEqual(pronounce_number(1, lang="da-dk"), "en")
     self.assertEqual(pronounce_number(10, lang="da-dk"), "ti")
     self.assertEqual(pronounce_number(15, lang="da-dk"), "femten")
     self.assertEqual(pronounce_number(20, lang="da-dk"), "tyve")
     self.assertEqual(pronounce_number(27, lang="da-dk"), "syvogtyve")
     self.assertEqual(pronounce_number(30, lang="da-dk"), "tredive")
     self.assertEqual(pronounce_number(33, lang="da-dk"), "treogtredive")
     self.assertEqual(pronounce_number(71, lang="da-dk"), "enoghalvfjers")
     self.assertEqual(pronounce_number(80, lang="da-dk"), "firs")
     self.assertEqual(pronounce_number(74, lang="da-dk"), "fireoghalvfjers")
     self.assertEqual(pronounce_number(79, lang="da-dk"), "nioghalvfjers")
     self.assertEqual(pronounce_number(91, lang="da-dk"), "enoghalvfems")
     self.assertEqual(pronounce_number(97, lang="da-dk"), "syvoghalvfems")
     self.assertEqual(pronounce_number(300, lang="da-dk"), "trehundrede")
 def test_convert_decimals(self):
     self.assertEqual(pronounce_number(1.234, lang="it"),
                      "uno virgola due tre")
     self.assertEqual(pronounce_number(21.234, lang="it"),
                      "ventuno virgola due tre")
     self.assertEqual(pronounce_number(21.234, lang="it", places=1),
                      "ventuno virgola due")
     self.assertEqual(pronounce_number(21.234, lang="it", places=0),
                      "ventuno")
     self.assertEqual(pronounce_number(21.234, lang="it", places=3),
                      "ventuno virgola due tre quattro")
     self.assertEqual(pronounce_number(21.234, lang="it", places=4),
                      "ventuno virgola due tre quattro")
     self.assertEqual(pronounce_number(21.234, lang="it", places=5),
                      "ventuno virgola due tre quattro")
     self.assertEqual(pronounce_number(-21.234, lang="it"),
                      "meno ventuno virgola due tre")
     self.assertEqual(pronounce_number(-21.234, lang="it", places=1),
                      "meno ventuno virgola due")
     self.assertEqual(pronounce_number(-21.234, lang="it", places=0),
                      "meno ventuno")
     self.assertEqual(pronounce_number(-21.234, lang="it", places=3),
                      "meno ventuno virgola due tre quattro")
     self.assertEqual(pronounce_number(-21.234, lang="it", places=4),
                      "meno ventuno virgola due tre quattro")
     self.assertEqual(pronounce_number(-21.234, lang="it", places=5),
                      "meno ventuno virgola due tre quattro")
    def test_convert_int_de(self):
        self.assertEqual(pronounce_number(123456789123456789),
                         "einhundertdreiundzwanzig Billiarden "
                         "vierhundertsechsundfünfzig Billionen "
                         "siebenhundertneunundachtzig Milliarden "
                         "einhundertdreiundzwanzig Millionen "
                         "vierhundertsechsundfünfzigtausendsiebenhundert"
                         "neunundachtzig")
        self.assertEqual(pronounce_number(1), "eins")
        self.assertEqual(pronounce_number(10), "zehn")
        self.assertEqual(pronounce_number(15), u"fünfzehn")
        self.assertEqual(pronounce_number(20), "zwanzig")
        self.assertEqual(pronounce_number(27), "siebenundzwanzig")
        self.assertEqual(pronounce_number(30), u"dreißig")
        self.assertEqual(pronounce_number(33), u"dreiunddreißig")

        self.assertEqual(pronounce_number(71), "einundsiebzig")
        self.assertEqual(pronounce_number(80), "achtzig")
        self.assertEqual(pronounce_number(74), "vierundsiebzig")
        self.assertEqual(pronounce_number(79), "neunundsiebzig")
        self.assertEqual(pronounce_number(91), "einundneunzig")
        self.assertEqual(pronounce_number(97), "siebenundneunzig")
        self.assertEqual(pronounce_number(300), "dreihundert")
 def test_convert_int_de(self):
     self.assertEqual(pronounce_number(123456789123456789, lang="de-de"),
                      "einhundertdreiundzwanzig Billiarden "
                      "vierhundertsechsundfünfzig Billionen "
                      "siebenhundertneunundachtzig Milliarden "
                      "einhundertdreiundzwanzig Millionen "
                      "vierhundertsechsundfünfzigtausendsiebenhundert"
                      "neunundachtzig")
     self.assertEqual(pronounce_number(1, lang="de-de"), "eins")
     self.assertEqual(pronounce_number(10, lang="de-de"), "zehn")
     self.assertEqual(pronounce_number(15, lang="de-de"), u"fünfzehn")
     self.assertEqual(pronounce_number(20, lang="de-de"), "zwanzig")
     self.assertEqual(pronounce_number(27, lang="de-de"),
                      "siebenundzwanzig")
     self.assertEqual(pronounce_number(30, lang="de-de"), u"dreißig")
     self.assertEqual(pronounce_number(33, lang="de-de"), u"dreiunddreißig")
     self.assertEqual(pronounce_number(71, lang="de-de"),
                      "einundsiebzig")
     self.assertEqual(pronounce_number(80, lang="de-de"), "achtzig")
     self.assertEqual(pronounce_number(74, lang="de-de"),
                      "vierundsiebzig")
     self.assertEqual(pronounce_number(79, lang="de-de"),
                      "neunundsiebzig")
     self.assertEqual(pronounce_number(91, lang="de-de"),
                      "einundneunzig")
     self.assertEqual(pronounce_number(97, lang="de-de"),
                      "siebenundneunzig")
     self.assertEqual(pronounce_number(300, lang="de-de"), "dreihundert")
 def test_convert_decimals(self):
     self.assertEqual(pronounce_number(1.234, lang="es"),
                      "uno coma dos tres")
     self.assertEqual(pronounce_number(21.234, lang="es"),
                      "veintiuno coma dos tres")
     self.assertEqual(pronounce_number(21.234, lang="es", places=1),
                      "veintiuno coma dos")
     self.assertEqual(pronounce_number(21.234, lang="es", places=0),
                      "veintiuno")
     self.assertEqual(pronounce_number(21.234, lang="es", places=3),
                      "veintiuno coma dos tres cuatro")
     self.assertEqual(pronounce_number(21.234, lang="es", places=4),
                      "veintiuno coma dos tres cuatro")
     self.assertEqual(pronounce_number(21.234, lang="es", places=5),
                      "veintiuno coma dos tres cuatro")
     self.assertEqual(pronounce_number(-21.234, lang="es"),
                      "menos veintiuno coma dos tres")
     self.assertEqual(pronounce_number(-21.234, lang="es", places=1),
                      "menos veintiuno coma dos")
     self.assertEqual(pronounce_number(-21.234, lang="es", places=0),
                      "menos veintiuno")
     self.assertEqual(pronounce_number(-21.234, lang="es", places=3),
                      "menos veintiuno coma dos tres cuatro")
     self.assertEqual(pronounce_number(-21.234, lang="es", places=4),
                      "menos veintiuno coma dos tres cuatro")
     self.assertEqual(pronounce_number(-21.234, lang="es", places=5),
                      "menos veintiuno coma dos tres cuatro")
 def test_convert_negative_int(self):
     self.assertEqual(pronounce_number(-1, lang="es"), "menos uno")
     self.assertEqual(pronounce_number(-10, lang="es"), "menos diez")
     self.assertEqual(pronounce_number(-15, lang="es"), "menos quince")
     self.assertEqual(pronounce_number(-21, lang="es"), "menos veintiuno")
     self.assertEqual(pronounce_number(-27, lang="es"), "menos veintisiete")
     self.assertEqual(pronounce_number(-30, lang="es"), "menos treinta")
     self.assertEqual(pronounce_number(-35, lang="es"),
                      "menos treinta y cinco")
     self.assertEqual(pronounce_number(-83, lang="es"),
                      "menos ochenta y tres")
     self.assertEqual(pronounce_number(-19, lang="es"), "menos diecinueve")
     self.assertEqual(pronounce_number(-88, lang="es"),
                      "menos ochenta y ocho")
     self.assertEqual(pronounce_number(-46, lang="es"),
                      "menos cuarenta y seis")
     self.assertEqual(pronounce_number(-99, lang="es"),
                      "menos noventa y nueve")
Exemple #57
0
 def test_convert_decimals(self):
     self.assertEqual(pronounce_number(1.234, lang="pt"),
                      "um vírgula dois três")
     self.assertEqual(pronounce_number(21.234, lang="pt"),
                      "vinte e um vírgula dois três")
     self.assertEqual(pronounce_number(21.234, lang="pt", places=1),
                      "vinte e um vírgula dois")
     self.assertEqual(pronounce_number(21.234, lang="pt", places=0),
                      "vinte e um")
     self.assertEqual(pronounce_number(21.234, lang="pt", places=3),
                      "vinte e um vírgula dois três quatro")
     self.assertEqual(pronounce_number(21.234, lang="pt", places=4),
                      "vinte e um vírgula dois três quatro")
     self.assertEqual(pronounce_number(20.234, lang="pt", places=5),
                      "vinte vírgula dois três quatro")
     self.assertEqual(pronounce_number(-21.234, lang="pt"),
                      "menos vinte e um vírgula dois três")
     self.assertEqual(pronounce_number(-21.234, lang="pt", places=1),
                      "menos vinte e um vírgula dois")
     self.assertEqual(pronounce_number(-21.234, lang="pt", places=0),
                      "menos vinte e um")
     self.assertEqual(pronounce_number(-21.234, lang="pt", places=3),
                      "menos vinte e um vírgula dois três quatro")
     self.assertEqual(pronounce_number(-21.234, lang="pt", places=4),
                      "menos vinte e um vírgula dois três quatro")
     self.assertEqual(pronounce_number(-21.234, lang="pt", places=5),
                      "menos vinte e um vírgula dois três quatro")
 def test_convert_decimals_nl(self):
     self.assertEqual(pronounce_number(1.234, lang="nl-nl"),
                      u"één komma twee drie")
     self.assertEqual(pronounce_number(21.234, lang="nl-nl"),
                      u"éénentwintig komma twee drie")
     self.assertEqual(pronounce_number(21.234, lang="nl-nl", places=1),
                      u"éénentwintig komma twee")
     self.assertEqual(pronounce_number(21.234, lang="nl-nl", places=0),
                      u"éénentwintig")
     self.assertEqual(pronounce_number(21.234, lang="nl-nl", places=3),
                      u"éénentwintig komma twee drie vier")
     self.assertEqual(pronounce_number(21.234, lang="nl-nl", places=4),
                      u"éénentwintig komma twee drie vier nul")
     self.assertEqual(pronounce_number(21.234, lang="nl-nl", places=5),
                      u"éénentwintig komma twee drie vier nul nul")
     self.assertEqual(pronounce_number(-1.234, lang="nl-nl"),
                      u"min één komma twee drie")
     self.assertEqual(pronounce_number(-21.234, lang="nl-nl"),
                      u"min éénentwintig komma twee drie")
     self.assertEqual(pronounce_number(-21.234, lang="nl-nl", places=1),
                      u"min éénentwintig komma twee")
     self.assertEqual(pronounce_number(-21.234, lang="nl-nl", places=0),
                      u"min éénentwintig")
     self.assertEqual(pronounce_number(-21.234, lang="nl-nl", places=3),
                      u"min éénentwintig komma twee drie vier")
     self.assertEqual(pronounce_number(-21.234, lang="nl-nl", places=4),
                      u"min éénentwintig komma twee drie vier nul")
     self.assertEqual(pronounce_number(-21.234, lang="nl-nl", places=5),
                      u"min éénentwintig komma twee drie vier nul nul")
 def test_convert_decimals_de(self):
     self.assertEqual(pronounce_number(1.234, lang="de-de"),
                      "eins Komma zwei drei")
     self.assertEqual(pronounce_number(21.234, lang="de-de"),
                      "einundzwanzig Komma zwei drei")
     self.assertEqual(pronounce_number(21.234, lang="de-de", places=1),
                      "einundzwanzig Komma zwei")
     self.assertEqual(pronounce_number(21.234, lang="de-de", places=0),
                      "einundzwanzig")
     self.assertEqual(pronounce_number(21.234, lang="de-de", places=3),
                      "einundzwanzig Komma zwei drei vier")
     self.assertEqual(pronounce_number(21.234, lang="de-de", places=4),
                      "einundzwanzig Komma zwei drei vier null")
     self.assertEqual(pronounce_number(21.234, lang="de-de", places=5),
                      "einundzwanzig Komma zwei drei vier null null")
     self.assertEqual(pronounce_number(-1.234, lang="de-de"),
                      "minus eins Komma zwei drei")
     self.assertEqual(pronounce_number(-21.234, lang="de-de"),
                      "minus einundzwanzig Komma zwei drei")
     self.assertEqual(pronounce_number(-21.234, lang="de-de", places=1),
                      "minus einundzwanzig Komma zwei")
     self.assertEqual(pronounce_number(-21.234, lang="de-de", places=0),
                      "minus einundzwanzig")
     self.assertEqual(pronounce_number(-21.234, lang="de-de", places=3),
                      "minus einundzwanzig Komma zwei drei vier")
     self.assertEqual(pronounce_number(-21.234, lang="de-de", places=4),
                      "minus einundzwanzig Komma zwei drei vier null")
     self.assertEqual(pronounce_number(-21.234, lang="de-de", places=5),
                      "minus einundzwanzig Komma zwei drei vier null null")
 def test_convert_dacimals_da(self):
     self.assertEqual(pronounce_number(1.234, lang="da-dk"),
                      "en komma to tre")
     self.assertEqual(pronounce_number(21.234, lang="da-dk"),
                      "enogtyve komma to tre")
     self.assertEqual(pronounce_number(21.234, lang="da-dk", places=1),
                      "enogtyve komma to")
     self.assertEqual(pronounce_number(21.234, lang="da-dk", places=0),
                      "enogtyve")
     self.assertEqual(pronounce_number(21.234, lang="da-dk", places=3),
                      "enogtyve komma to tre fire")
     self.assertEqual(pronounce_number(21.234, lang="da-dk", places=4),
                      "enogtyve komma to tre fire nul")
     self.assertEqual(pronounce_number(21.234, lang="da-dk", places=5),
                      "enogtyve komma to tre fire nul nul")
     self.assertEqual(pronounce_number(-1.234, lang="da-dk"),
                      "minus en komma to tre")
     self.assertEqual(pronounce_number(-21.234, lang="da-dk"),
                      "minus enogtyve komma to tre")
     self.assertEqual(pronounce_number(-21.234, lang="da-dk", places=1),
                      "minus enogtyve komma to")
     self.assertEqual(pronounce_number(-21.234, lang="da-dk", places=0),
                      "minus enogtyve")
     self.assertEqual(pronounce_number(-21.234, lang="da-dk", places=3),
                      "minus enogtyve komma to tre fire")
     self.assertEqual(pronounce_number(-21.234, lang="da-dk", places=4),
                      "minus enogtyve komma to tre fire nul")
     self.assertEqual(pronounce_number(-21.234, lang="da-dk", places=5),
                      "minus enogtyve komma to tre fire nul nul")