示例#1
0
 def test_extract_ambiguous_time_cs(self):
     morning = datetime(2017, 6, 27, 8, 1, 2)
     večer = datetime(2017, 6, 27, 20, 1, 2)
     noonish = datetime(2017, 6, 27, 12, 1, 2)
     self.assertEqual(
         extract_datetime('krmení ryb'), None)
     self.assertEqual(
         extract_datetime('den'), None)
     self.assertEqual(
         extract_datetime('týden'), None)
     self.assertEqual(
         extract_datetime('měsíc'), None)
     self.assertEqual(
         extract_datetime('rok'), None)
     self.assertEqual(
         extract_datetime(' '), None)
     self.assertEqual(
         extract_datetime('nakrmit ryby v 10 hodin', morning)[0],
         datetime(2017, 6, 27, 10, 0, 0))
     self.assertEqual(
         extract_datetime('nakrmit ryby v 10 hodin', noonish)[0],
         datetime(2017, 6, 27, 22, 0, 0))
     self.assertEqual(
         extract_datetime('nakrmit ryby v 10 hodin', večer)[0],
         datetime(2017, 6, 27, 22, 0, 0))
示例#2
0
 def test_extract_date_with_may_I_en(self):
     now = datetime(2019, 7, 4, 8, 1, 2)
     may_date = datetime(2019, 5, 2, 10, 11, 20)
     self.assertEqual(
         extract_datetime('May I know what time it is tomorrow', now)[0],
         datetime(2019, 7, 5, 0, 0, 0))
     self.assertEqual(
         extract_datetime('May I when 10 o\'clock is', now)[0],
         datetime(2019, 7, 4, 10, 0, 0))
     self.assertEqual(
         extract_datetime('On 24th of may I want a reminder', may_date)[0],
         datetime(2019, 5, 24, 0, 0, 0))
示例#3
0
 def test_extract_ambiguous_time_en(self):
     morning = datetime(2017, 6, 27, 8, 1, 2)
     evening = datetime(2017, 6, 27, 20, 1, 2)
     noonish = datetime(2017, 6, 27, 12, 1, 2)
     self.assertEqual(
         extract_datetime('feed fish at 10 o\'clock', morning)[0],
         datetime(2017, 6, 27, 10, 0, 0))
     self.assertEqual(
         extract_datetime('feed fish at 10 o\'clock', noonish)[0],
         datetime(2017, 6, 27, 22, 0, 0))
     self.assertEqual(
         extract_datetime('feed fish at 10 o\'clock', evening)[0],
         datetime(2017, 6, 27, 22, 0, 0))
示例#4
0
    def test_datetime_by_date_es(self):
        # test currentDate==None
        _now = datetime.now()
        relative_year = _now.year if (_now.month == 1 and _now.day < 11) else \
            (_now.year + 1)
        self.assertEqual(
            extract_datetime_es("11 ene")[0], datetime(relative_year, 1, 11))

        # test months
        self.assertEqual(
            extract_datetime("11 ene",
                             lang='es',
                             anchorDate=datetime(1998, 1, 1))[0],
            datetime(1998, 1, 11))
        self.assertEqual(
            extract_datetime("11 feb",
                             lang='es',
                             anchorDate=datetime(1998, 2, 1))[0],
            datetime(1998, 2, 11))
        self.assertEqual(
            extract_datetime("11 mar",
                             lang='es',
                             anchorDate=datetime(1998, 3, 1))[0],
            datetime(1998, 3, 11))
        self.assertEqual(
            extract_datetime("11 abr",
                             lang='es',
                             anchorDate=datetime(1998, 4, 1))[0],
            datetime(1998, 4, 11))
        self.assertEqual(
            extract_datetime("11 may",
                             lang='es',
                             anchorDate=datetime(1998, 5, 1))[0],
            datetime(1998, 5, 11))
        # there is an issue with the months of june through september (below)
        # hay un problema con las meses junio hasta septiembre (lea abajo)
        self.assertEqual(
            extract_datetime("11 oct",
                             lang='es',
                             anchorDate=datetime(1998, 10, 1))[0],
            datetime(1998, 10, 11))
        self.assertEqual(
            extract_datetime("11 nov",
                             lang='es',
                             anchorDate=datetime(1998, 11, 1))[0],
            datetime(1998, 11, 11))
        self.assertEqual(
            extract_datetime("11 dic",
                             lang='es',
                             anchorDate=datetime(1998, 12, 1))[0],
            datetime(1998, 12, 11))

        self.assertEqual(extract_datetime("", lang='es'), None)
示例#5
0
 def test_extractdatetime_default_pt(self):
     default = time(9, 0, 0)
     anchor = datetime(2017, 6, 27, 0, 0)
     res = extract_datetime(
         'marca consulta para 2 semanas e 6 dias depois de Sabado',
         anchor, lang='pt-pt', default_time=default)
     self.assertEqual(default, res[0].time())
示例#6
0
 def extractWithFormat_it(text):
     date = datetime(2018, 1, 13, 13, 4)  # Sab 13 Gen, 2018 @ 13:04
     [extractedDate, leftover] = extract_datetime(text,
                                                  date,
                                                  lang='it-it')
     extractedDate = extractedDate.strftime('%Y-%m-%d %H:%M:%S')
     return [extractedDate, leftover]
示例#7
0
 def extractWithFormat(text):
     date = datetime(2017, 6, 27, 10, 1, 2)
     [extractedDate, leftover] = extract_datetime(text,
                                                  date,
                                                  lang='it-it')
     extractedDate = extractedDate.strftime('%Y-%m-%d %H:%M:%S')
     return [extractedDate, leftover]
示例#8
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:])
示例#9
0
 def test_extract_ambiguous_time_it(self):
     mattina = datetime(2017, 6, 27, 8, 1, 2)
     sera = datetime(2017, 6, 27, 20, 1, 2)
     mezzogiorno = datetime(2017, 6, 27, 12, 1, 2)
     self.assertEqual(
         extract_datetime('dai da mangiare ai pesci alle 10 in punto',
                          anchorDate=mattina, lang='it-it')[0],
         datetime(2017, 6, 27, 10, 0, 0))
     self.assertEqual(
         extract_datetime('dai da mangiare ai pesci alle 10 in punto',
                          mezzogiorno, lang='it-it')[0],
         datetime(2017, 6, 27, 22, 0, 0))
     self.assertEqual(
         extract_datetime('dai da mangiare ai pesci alle 10 in punto',
                          sera, lang='it-it')[0],
         datetime(2017, 6, 27, 22, 0, 0))
示例#10
0
 def handle_mag(self, message):
     self.current_camera = "hmimag"
     date = extract_datetime(message.data["utterance"], lang=self.lang)
     if date is not None:
         date, remainder = date
     self._display(date)
     self.set_context("MDI" + self.current_camera)
示例#11
0
    def test_datetime_by_date_es(self):
        # test currentDate==None
        _now = datetime.now()
        relative_year = _now.year if (_now.month == 1 and _now.day < 11) else \
                        (_now.year + 1)
        self.assertEqual(
            extract_datetime_es("11 ene")[0], datetime(relative_year, 1, 11))

        # test months
        self.assertEqual(
            extract_datetime("11 gen",
                             lang='ca',
                             anchorDate=datetime(1998, 1, 1))[0],
            datetime(1998, 1, 11))

        self.assertEqual(extract_datetime("", lang='ca'), None)
示例#12
0
 def extractWithFormat(text):
     date = datetime(2017, 6, 27, 0, 0)
     [extractedDate, leftover] = extract_datetime(text,
                                                  anchorDate=date,
                                                  lang=LANG)
     extractedDate = extractedDate.strftime("%Y-%m-%d %H:%M:%S")
     return [extractedDate, leftover]
示例#13
0
 def extractWithFormat_fr(text):
     date = datetime(2017, 6, 27, 0, 0)
     [extractedDate, leftover] = extract_datetime(text,
                                                  date,
                                                  lang="fr-fr")
     extractedDate = extractedDate.strftime("%Y-%m-%d %H:%M:%S")
     return [extractedDate, leftover]
示例#14
0
 def test_extractdatetime_default_nl(self):
     default = time(9, 0, 0)
     anchor = datetime(2019, 11, 1, 0, 0)
     res = extract_datetime("laten we afspreken op donderdag",
                            anchor,
                            lang=LANG,
                            default_time=default)
     self.assertEqual(default, res[0].time())
示例#15
0
 def test_extractdatetime_default_de(self):
     default = time(9, 0, 0)
     anchor = datetime(2017, 6, 27, 0, 0)
     res = extract_datetime("lass uns treffen am freitag",
                            anchor,
                            lang='de-de',
                            default_time=default)
     self.assertEqual(default, res[0].time())
示例#16
0
 def test_extractdatetime_default_it(self):
     default = time(9, 0, 0)
     anchor = datetime(2017, 6, 27, 0, 0)
     res = extract_datetime('Come è il meteo 3 tra giorni?',
                            anchor,
                            lang='it-it',
                            default_time=default)
     self.assertEqual(default, res[0].time())
示例#17
0
 def test_extractdatetime_default_fr(self):
     default = time(9, 0, 0)
     anchor = datetime(2017, 6, 27, 0, 0)
     res = extract_datetime("faire les plantations le 3ème jour de mars",
                            anchor,
                            lang='fr-fr',
                            default_time=default)
     self.assertEqual(default, res[0].time())
示例#18
0
 def test_extractdatetime_default_da(self):
     default = time(9, 0, 0)
     anchor = datetime(2017, 6, 27, 0, 0)
     res = extract_datetime("lad os mødes på fredag klokken 9 om morgenen",
                            anchor,
                            lang='da-dk',
                            default_time=default)
     self.assertEqual(default, res[0].time())
示例#19
0
 def test_extractdatetime_default_sv(self):
     default = time(9, 0, 0)
     anchor = datetime(2017, 6, 27, 0, 0)
     res = extract_datetime('påminn mig att klippa mig på fredag',
                            anchor,
                            lang='sv-se',
                            default_time=default)
     self.assertEqual(default, res[0].time())
示例#20
0
    def handle_ask_specific(self, message):
        """Intent handler to tell the user his appointments on specific days.

        Gets executed with the right user input.
        The user can ask e.g for a specific day, or if he has any appointments in two weeks.


        Args:
            message: A message object, which contains the user inputs.
                     In this case the message contains the specific date.
        """

        date = message.data['date']

        try:
            start_date = extract_datetime(date)[0]
            end_date = datetime.combine(start_date, start_date.max.time())
            calendar = self.current_calendar
            if calendar is None:
                self.speak('No calendar accessible')
                return
            events = self.get_all_events(
                calendar=calendar,
                start=start_date.astimezone(self.local_tz),
                end=end_date.astimezone(self.local_tz))
            spoken_date = nice_date(start_date)

            if len(events) == 0:

                self.speak_dialog('no.appointments.specific',
                                  {'date': spoken_date})
                next_event = self.get_all_events(calendar=calendar, start=start_date.astimezone(self.local_tz))  # Mycroft needs full lenght. pylint: disable=line-too-long
                if len(next_event) > 0:

                    start_date_string = f"{self.get_ordinal_number(next_event[0].instance.vevent.dtstart.value.day)} of {next_event[0].instance.vevent.dtstart.value.strftime('%B')}"  # Mycroft needs full lenght. pylint: disable=line-too-long

                    summary = self.get_event_title(
                        next_event[0].instance.vevent)

                    self.speak_dialog('yes.next.appointment.specific', {
                        'title': summary,
                        'date': start_date_string
                    })

            elif len(events) >= 1:
                self.speak_dialog('yes.appointments.specific', {'number': len(events), 'date': spoken_date})  # Mycroft needs full lenght. pylint: disable=line-too-long
                for event in events:
                    next_event = event.instance.vevent

                    self.helper_speak_event(next_event)

        except TypeError as type_error:
            self.log.error(type_error)
            self.speak(
                f"{date} is not a valid input. Please rephrase your question.")
        except Exception as exception:  # We want to catch all types of exceptions pylint: disable=broad-except
            self.log.error(exception)
            self.speak("Unexpected error! Check Logs!")
示例#21
0
 def test_extractdatetime_default_ca(self):
     default = time(9, 0, 0)
     anchor = datetime(2017, 6, 27, 0, 0)
     res = extract_datetime(
         'concerta cita per a 2 setmanes i 6 dies després de dissabte',
         anchor,
         lang='ca-es',
         default_time=default)
     self.assertEqual(default, res[0].time())
示例#22
0
 def handle_news(self, message):
     date = extract_datetime(message.data["utterance"], lang="en")
     if date:
         self._display_and_speak(date=date[0])
     else:
         # avoid repeating news
         news_idx = len(self.already_said)
         if news_idx >= self.total_news - 1:
             news_idx = random.randint(0, self.total_news - 1)
         self._display_and_speak(news_idx)
示例#23
0
    def test_extract_datetime_relative_failing(self):
        # parses as "morning" and returns 8:00 on anchorDate
        self.assertEqual(
            extract_datetime("mañana",
                             anchorDate=datetime(1998, 1, 1),
                             lang='es')[0], datetime(1998, 1, 2))

        # unimplemented logic
        self.assertEqual(
            extract_datetime("anoche",
                             anchorDate=datetime(1998, 1, 1),
                             lang='es')[0], datetime(1997, 12, 31, 21))
        self.assertEqual(
            extract_datetime("anteanoche",
                             anchorDate=datetime(1998, 1, 1),
                             lang='es')[0], datetime(1997, 12, 30, 21))
        self.assertEqual(
            extract_datetime("hace tres noches",
                             anchorDate=datetime(1998, 1, 1),
                             lang='es')[0], datetime(1997, 12, 29, 21))
示例#24
0
 def handle_lasco(self, message):
     if message.data.get("inner"):
         self.current_camera = "c2"
     elif message.data.get("outer"):
         self.current_camera = "c3"
     else:
         self.current_camera = random.choice(["c2", "c3"])
     date = extract_datetime(message.data["utterance"], lang=self.lang)
     if date is not None:
         date, remainder = date
     self._display(date)
     self.set_context("LASCO" + self.current_camera)
示例#25
0
    def test_bugged_output_wastebasket(self):
        self.assertEqual(
            extract_datetime("11 jun",
                             lang='es',
                             anchorDate=datetime(1998, 6, 1))[0],
            datetime(1998, 6, 11))
        self.assertEqual(
            extract_datetime("11 junio",
                             lang='es',
                             anchorDate=datetime(1998, 6, 1))[0],
            datetime(1998, 6, 11))
        self.assertEqual(
            extract_datetime("11 jul",
                             lang='es',
                             anchorDate=datetime(1998, 7, 1))[0],
            datetime(1998, 7, 11))
        self.assertEqual(
            extract_datetime("11 ago",
                             lang='es',
                             anchorDate=datetime(1998, 8, 1))[0],
            datetime(1998, 8, 11))
        self.assertEqual(
            extract_datetime("11 sep",
                             lang='es',
                             anchorDate=datetime(1998, 9, 1))[0],
            datetime(1998, 9, 11))

        # It's also failing on years
        self.assertEqual(
            extract_datetime("11 ago 1998", lang='es')[0],
            datetime(1998, 8, 11))
示例#26
0
    def test_extract_datetime_relative(self):
        self.assertEqual(
            extract_datetime("esta noche",
                             anchorDate=datetime(1998, 1, 1),
                             lang='es'),
            [datetime(1998, 1, 1, 21, 0, 0), 'esta'])
        self.assertEqual(
            extract_datetime("ayer noche",
                             anchorDate=datetime(1998, 1, 1),
                             lang='es')[0], datetime(1997, 12, 31, 21))
        self.assertEqual(
            extract_datetime("el noche anteayer",
                             anchorDate=datetime(1998, 1, 1),
                             lang='es')[0], datetime(1997, 12, 30, 21))
        self.assertEqual(
            extract_datetime("el noche ante ante ayer",
                             anchorDate=datetime(1998, 1, 1),
                             lang='es')[0], datetime(1997, 12, 29, 21))
        self.assertEqual(
            extract_datetime("mañana por la mañana",
                             anchorDate=datetime(1998, 1, 1),
                             lang='es')[0], datetime(1998, 1, 2, 8))
        self.assertEqual(
            extract_datetime("ayer por la tarde",
                             anchorDate=datetime(1998, 1, 1),
                             lang='es')[0], datetime(1997, 12, 31, 15))

        self.assertEqual(
            extract_datetime("qué año es",
                             anchorDate=datetime(1998, 1, 1),
                             lang='es')[0], datetime(1998, 1, 1))

        self.assertEqual(
            extract_datetime("hoy 2 de la mañana",
                             lang='es',
                             anchorDate=datetime(1998, 1, 1))[0],
            datetime(1998, 1, 1, 2))
        self.assertEqual(
            extract_datetime("hoy 2 de la tarde",
                             lang='es',
                             anchorDate=datetime(1998, 1, 1))[0],
            datetime(1998, 1, 1, 14))
示例#27
0
 def test_extract_ambiguous_time_pl(self):
     morning = datetime(2017, 6, 27, 8, 1, 2)
     evening = datetime(2017, 6, 27, 20, 1, 2)
     noonish = datetime(2017, 6, 27, 12, 1, 2)
     self.assertEqual(extract_datetime('nakarm rybę'), None)
     self.assertEqual(extract_datetime('dzień'), None)
     self.assertEqual(extract_datetime('tydzień'), None)
     self.assertEqual(extract_datetime('miesiąc'), None)
     self.assertEqual(extract_datetime('rok'), None)
     self.assertEqual(extract_datetime(' '), None)
示例#28
0
    def test_extractdatetime_fr(self):
        def extractWithFormat_fr(text):
            date = datetime(2017, 6, 27, 0, 0)
            [extractedDate, leftover] = extract_datetime(text,
                                                         date,
                                                         lang="fr-fr")
            extractedDate = extractedDate.strftime("%Y-%m-%d %H:%M:%S")
            return [extractedDate, leftover]

        def testExtract_fr(text, expected_date, expected_leftover):
            res = extractWithFormat_fr(text)
            self.assertEqual(res[0], expected_date)
            self.assertEqual(res[1], expected_leftover)

        def extractWithFormatDate2_fr(text):
            date = datetime(2017, 6, 30, 17, 0)
            [extractedDate, leftover] = extract_datetime(text,
                                                         date,
                                                         lang="fr-fr")
            extractedDate = extractedDate.strftime("%Y-%m-%d %H:%M:%S")
            return [extractedDate, leftover]

        def testExtractDate2_fr(text, expected_date, expected_leftover):
            res = extractWithFormatDate2_fr(text)
            self.assertEqual(res[0], expected_date)
            self.assertEqual(res[1], expected_leftover)

        def extractWithFormatNoDate_fr(text):
            [extractedDate, leftover] = extract_datetime(text, lang="fr-fr")
            extractedDate = extractedDate.strftime("%Y-%m-%d %H:%M:%S")
            return [extractedDate, leftover]

        def testExtractNoDate_fr(text, expected_date, expected_leftover):
            res = extractWithFormatNoDate_fr(text)
            self.assertEqual(res[0], expected_date)
            self.assertEqual(res[1], expected_leftover)

        testExtract_fr("Planifier l'embûche dans 5 jours",
                       "2017-07-02 00:00:00", "planifier embûche")
        testExtract_fr("Quel temps fera-t-il après-demain ?",
                       "2017-06-29 00:00:00", "quel temps fera-t-il")
        testExtract_fr("Met un rappel à 10:45 du soir", "2017-06-27 22:45:00",
                       "met 1 rappel")
        testExtract_fr("quel temps est prévu pour vendredi matin ?",
                       "2017-06-30 08:00:00", "quel temps est prévu pour")
        testExtract_fr("quel temps fait-il demain", "2017-06-28 00:00:00",
                       "quel temps fait-il")
        testExtract_fr(
            "rappelle-moi d'appeler maman dans 8 semaines et"
            " 2 jours", "2017-08-24 00:00:00", "rappelle-moi appeler maman")
        testExtract_fr("Jouer des musiques de Beyonce 2 jours après vendredi",
                       "2017-07-02 00:00:00", "jouer musiques beyonce")
        testExtract_fr("Commencer l'invasion à 15 heures 45 jeudi",
                       "2017-06-29 15:45:00", "commencer invasion")
        testExtract_fr("Lundi, commander le gâteau à la boulangerie",
                       "2017-07-03 00:00:00", "commander gâteau à boulangerie")
        testExtract_fr("Jouer la chanson Joyeux anniversaire dans 5 ans",
                       "2022-06-27 00:00:00", "jouer chanson joyeux"
                       " anniversaire")
        testExtract_fr("Skyper Maman à 12 heures 45 jeudi prochain",
                       "2017-07-06 12:45:00", "skyper maman")
        testExtract_fr("Quel temps fera-t-il jeudi prochain ?",
                       "2017-07-06 00:00:00", "quel temps fera-t-il")
        testExtract_fr("Quel temps fera-t-il vendredi matin ?",
                       "2017-06-30 08:00:00", "quel temps fera-t-il")
        testExtract_fr("Quel temps fera-t-il vendredi soir",
                       "2017-06-30 19:00:00", "quel temps fera-t-il")
        testExtract_fr("Quel temps fera-t-il vendredi après-midi",
                       "2017-06-30 15:00:00", "quel temps fera-t-il")
        testExtract_fr("rappelle-moi d'appeler maman le 3 août",
                       "2017-08-03 00:00:00", "rappelle-moi appeler maman")
        testExtract_fr("Acheter des feux d'artifice pour le 14 juil",
                       "2017-07-14 00:00:00", "acheter feux artifice pour")
        testExtract_fr("Quel temps fera-t-il 2 semaines après vendredi",
                       "2017-07-14 00:00:00", "quel temps fera-t-il")
        testExtract_fr("Quel temps fera-t-il mercredi à 7 heures",
                       "2017-06-28 07:00:00", "quel temps fera-t-il")
        testExtract_fr("Quel temps fera-t-il mercredi à 7 heures",
                       "2017-06-28 07:00:00", "quel temps fera-t-il")
        testExtract_fr("Prendre rendez-vous à 12:45 jeudi prochain",
                       "2017-07-06 12:45:00", "prendre rendez-vous")
        testExtract_fr("Quel temps fait-il ce jeudi ?", "2017-06-29 00:00:00",
                       "quel temps fait-il")
        testExtract_fr(
            "Organiser une visite 2 semaines et 6 jours après"
            " samedi", "2017-07-21 00:00:00", "organiser 1 visite")
        testExtract_fr("Commencer l'invasion à 3 heures 45 jeudi",
                       "2017-06-29 03:45:00", "commencer invasion")
        testExtract_fr("Commencer l'invasion à 20 heures jeudi",
                       "2017-06-29 20:00:00", "commencer invasion")
        testExtract_fr("Lancer la fête jeudi à 8 heures du soir",
                       "2017-06-29 20:00:00", "lancer fête")
        testExtract_fr("Commencer l'invasion à 4 heures de l'après-midi jeudi",
                       "2017-06-29 16:00:00", "commencer invasion")
        testExtract_fr("Commencer l'invasion jeudi à midi",
                       "2017-06-29 12:00:00", "commencer invasion")
        testExtract_fr("Commencer l'invasion jeudi à minuit",
                       "2017-06-29 00:00:00", "commencer invasion")
        testExtract_fr("Commencer l'invasion jeudi à dix-sept heures",
                       "2017-06-29 17:00:00", "commencer invasion")
        testExtract_fr("rappelle-moi de me réveiller dans 4 années",
                       "2021-06-27 00:00:00", "rappelle-moi me réveiller")
        testExtract_fr("rappelle-moi de me réveiller dans 4 ans et 4 jours",
                       "2021-07-01 00:00:00", "rappelle-moi me réveiller")
        testExtract_fr("Quel temps fera-t-il 3 jours après demain ?",
                       "2017-07-01 00:00:00", "quel temps fera-t-il")
        testExtract_fr("3 décembre", "2017-12-03 00:00:00", "")
        testExtract_fr("retrouvons-nous à 8:00 ce soir", "2017-06-27 20:00:00",
                       "retrouvons-nous")
        testExtract_fr("retrouvons-nous demain à minuit et demi",
                       "2017-06-28 00:30:00", "retrouvons-nous")
        testExtract_fr("retrouvons-nous à midi et quart",
                       "2017-06-27 12:15:00", "retrouvons-nous")
        testExtract_fr("retrouvons-nous à midi moins le quart",
                       "2017-06-27 11:45:00", "retrouvons-nous")
        testExtract_fr("retrouvons-nous à midi moins dix",
                       "2017-06-27 11:50:00", "retrouvons-nous")
        testExtract_fr("retrouvons-nous à midi dix", "2017-06-27 12:10:00",
                       "retrouvons-nous")
        testExtract_fr("retrouvons-nous à minuit moins 23",
                       "2017-06-27 23:37:00", "retrouvons-nous")
        testExtract_fr("mangeons à 3 heures moins 23 minutes",
                       "2017-06-27 02:37:00", "mangeons")
        testExtract_fr("mangeons aussi à 4 heures moins le quart du matin",
                       "2017-06-27 03:45:00", "mangeons aussi")
        testExtract_fr("mangeons encore à minuit moins le quart",
                       "2017-06-27 23:45:00", "mangeons encore")
        testExtract_fr("buvons à 4 heures et quart", "2017-06-27 04:15:00",
                       "buvons")
        testExtract_fr("buvons également à 18 heures et demi",
                       "2017-06-27 18:30:00", "buvons également")
        testExtract_fr("dormons à 20 heures moins le quart",
                       "2017-06-27 19:45:00", "dormons")
        testExtract_fr("buvons le dernier verre à 10 heures moins 12 du soir",
                       "2017-06-27 21:48:00", "buvons dernier verre")
        testExtract_fr("s'échapper de l'île à 15h45", "2017-06-27 15:45:00",
                       "s'échapper île")
        testExtract_fr("s'échapper de l'île à 3h45min de l'après-midi",
                       "2017-06-27 15:45:00", "s'échapper île")
        testExtract_fr("décale donc ça à 3h48min cet après-midi",
                       "2017-06-27 15:48:00", "décale donc ça")
        testExtract_fr("construire un bunker à 9h42min du matin",
                       "2017-06-27 09:42:00", "construire 1 bunker")
        testExtract_fr("ou plutôt à 9h43 ce matin", "2017-06-27 09:43:00",
                       "ou plutôt")
        testExtract_fr("faire un feu à 8h du soir", "2017-06-27 20:00:00",
                       "faire 1 feu")
        testExtract_fr("faire la fête jusqu'à 18h cette nuit",
                       "2017-06-27 18:00:00", "faire fête jusqu'à")
        testExtract_fr("cuver jusqu'à 4h cette nuit", "2017-06-27 04:00:00",
                       "cuver jusqu'à")
        testExtract_fr("réveille-moi dans 20 secondes aujourd'hui",
                       "2017-06-27 00:00:20", "réveille-moi")
        testExtract_fr("réveille-moi dans 33 minutes", "2017-06-27 00:33:00",
                       "réveille-moi")
        testExtract_fr("tais-toi dans 12 heures et 3 minutes",
                       "2017-06-27 12:03:00", "tais-toi")
        testExtract_fr("ouvre-la dans 1 heure 3", "2017-06-27 01:03:00",
                       "ouvre-la")
        testExtract_fr("ferme-la dans 1 heure et quart", "2017-06-27 01:15:00",
                       "ferme-la")
        testExtract_fr("scelle-la dans 1 heure et demi", "2017-06-27 01:30:00",
                       "scelle-la")
        testExtract_fr("zippe-la dans 2 heures moins 12",
                       "2017-06-27 01:48:00", "zippe-la")
        testExtract_fr("soude-la dans 3 heures moins le quart",
                       "2017-06-27 02:45:00", "soude-la")
        testExtract_fr("mange la semaine prochaine", "2017-07-04 00:00:00",
                       "mange")
        testExtract_fr("bois la semaine dernière", "2017-06-20 00:00:00",
                       "bois")
        testExtract_fr("mange le mois prochain", "2017-07-27 00:00:00",
                       "mange")
        testExtract_fr("bois le mois dernier", "2017-05-27 00:00:00", "bois")
        testExtract_fr("mange l'an prochain", "2018-06-27 00:00:00", "mange")
        testExtract_fr("bois l'année dernière", "2016-06-27 00:00:00", "bois")
        testExtract_fr("reviens à lundi dernier", "2017-06-26 00:00:00",
                       "reviens")
        testExtract_fr("capitule le 8 mai 1945", "1945-05-08 00:00:00",
                       "capitule")
        testExtract_fr("rédige le contrat 3 jours après jeudi prochain",
                       "2017-07-09 00:00:00", "rédige contrat")
        testExtract_fr("signe le contrat 2 semaines après jeudi dernier",
                       "2017-07-06 00:00:00", "signe contrat")
        testExtract_fr("lance le four dans un quart d'heure",
                       "2017-06-27 00:15:00", "lance four")
        testExtract_fr("enfourne la pizza dans une demi-heure",
                       "2017-06-27 00:30:00", "enfourne pizza")
        testExtract_fr("arrête le four dans trois quarts d'heure",
                       "2017-06-27 00:45:00", "arrête four")
        testExtract_fr("mange la pizza dans une heure", "2017-06-27 01:00:00",
                       "mange pizza")
        testExtract_fr("bois la bière dans 2h23", "2017-06-27 02:23:00",
                       "bois bière")
        testExtract_fr("faire les plantations le 3ème jour de mars",
                       "2018-03-03 00:00:00", "faire plantations")
        testExtract_fr("récolter dans 10 mois", "2018-04-27 00:00:00",
                       "récolter")
        testExtract_fr("point 6a: dans 10 mois", "2018-04-27 06:00:00",
                       "point")
        testExtract_fr("l'après-midi démissionner à 4:59",
                       "2017-06-27 16:59:00", "démissionner")
        testExtract_fr("cette nuit dormir", "2017-06-27 02:00:00", "dormir")
        testExtract_fr("ranger son bureau à 1700 heures",
                       "2017-06-27 17:00:00", "ranger son bureau")

        testExtractDate2_fr("range le contrat 2 semaines après lundi",
                            "2017-07-17 00:00:00", "range contrat")
        testExtractDate2_fr("achète-toi de l'humour à 15h",
                            "2017-07-01 15:00:00", "achète-toi humour")
        # Disabling test until French Extract-date incorporates the fixes for
        # UTC / Local timezones.  Until then this test fails periodically
        # whenever test is run and the date in the local timezone (where the
        # test is being run) is a different than the date in UTC.
        #
        # testExtractNoDate_fr("tais-toi aujourd'hui",
        #                   datetime.now().strftime("%Y-%m-%d") + " 00:00:00",
        #                   "tais-toi")
        self.assertEqual(extract_datetime("", lang="fr-fr"), None)
        self.assertEqual(extract_datetime("phrase inutile", lang="fr-fr"),
                         None)
        self.assertEqual(
            extract_datetime("apprendre à compter à 37 heures", lang="fr-fr"),
            None)
示例#29
0
 def extractWithFormatNoDate_fr(text):
     [extractedDate, leftover] = extract_datetime(text, lang="fr-fr")
     extractedDate = extractedDate.strftime("%Y-%m-%d %H:%M:%S")
     return [extractedDate, leftover]
示例#30
0
 def test_extractdatetime_no_time(self):
     """Check that None is returned if no time is found in sentence."""
     self.assertEqual(extract_datetime('Ingen tid', lang='sv-se'), None)