Ejemplo n.º 1
0
    def validate(self, dispatcher: CollectingDispatcher, tracker: Tracker,
                 domain: Dict[Text, Any]) -> List[Dict]:

        slot_values = self.extract_other_slots(dispatcher, tracker, domain)
        slot_to_fill = tracker.get_slot(REQUESTED_SLOT)

        if slot_to_fill:
            slot_values.update(
                self.extract_requested_slot(dispatcher, tracker, domain))

        else:
            temp = tracker.get_latest_entity_values('PER')
            aux = None
            for i in temp:
                if i.lower() != "hola":
                    aux = i
            aux2 = next(tracker.get_latest_entity_values('persona'), None)
            loc = next(tracker.get_latest_entity_values('LOC'), None)
            misc = next(tracker.get_latest_entity_values('MISC'), None)
            if aux is None and aux2 is not None:
                return [SlotSet('persona', aux2.title())]
            elif aux is not None and aux is not "Hola":
                return [SlotSet('persona', aux.title())]
            elif loc is not None:
                return [SlotSet('persona', loc)]
            elif misc is not None:
                return [SlotSet('persona', misc)]
            else:
                dispatcher.utter_message("Dime cómo te llamas")
                return []

        return [SlotSet(slot, value) for slot, value in slot_values.items()]
Ejemplo n.º 2
0
    def _utter_next_event(self, tracker: Tracker,
                          dispatcher: CollectingDispatcher) -> None:
        location = next(tracker.get_latest_entity_values('location'), None)
        events = self._get_events()

        if location:
            events_for_location = [e for e in events if e.location == location]
            if not events_for_location and events:
                next_event = events[0]
                dispatcher.utter_message(
                    "Sorry, there are currently no events "
                    "at your location. However, the next "
                    "event is the {} in {} on {}."
                    "".format(next_event.name_as_link(), next_event.location,
                              next_event.formatted_date()))
            elif events_for_location:
                next_event = events_for_location[0]
                dispatcher.utter_message(
                    "The next event in {} is the {} on {}."
                    " Hope to see you there!"
                    "".format(location, next_event.name_as_link(),
                              next_event.formatted_date()))
        elif events:
            next_event = events[0]
            dispatcher.utter_message("The next event is the {} in {} on {}. "
                                     "Hope to see you there!"
                                     "".format(next_event.name_as_link(),
                                               next_event.location,
                                               next_event.formatted_date()))
Ejemplo n.º 3
0
    def _utter_next_event(self,
                          tracker: Tracker,
                          dispatcher: CollectingDispatcher
                          ) -> None:
        location = next(tracker.get_latest_entity_values('location'), None)
        events = self._get_events()

        if location:
            events_for_location = [e for e in events
                                   if e.city == location or
                                   e.country == location]
            if not events_for_location and events:
                next_event = events[0]
                dispatcher.utter_template(
                    'utter_no_event_for_location_but_next',
                    tracker, **next_event.as_kwargs())
            elif events_for_location:
                next_event = events_for_location[0]
                dispatcher.utter_template('utter_next_event_for_location',
                                          tracker,
                                          **next_event.as_kwargs())
        elif events:
            next_event = events[0]
            dispatcher.utter_template('utter_next_event', tracker,
                                      **next_event.as_kwargs())
Ejemplo n.º 4
0
    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        date = None
        saved_time = None
        num_persone = None

        if any(tracker.get_latest_entity_values("num_persone")):
            num = next(tracker.get_latest_entity_values("num_persone"))
            if int(num) > 0:
                num_persone = num

        if any(tracker.get_latest_entity_values(
                "time")):  # check if Duckling got a time entity
            date = next(tracker.get_latest_entity_values('time'), None)
            time = next(tracker.get_latest_entity_values('time'), None)
            time = time.split("T")[1].split(":")
            time_to_evaluate = int(time[0])
            num_persone_fix = 0  # used to handle the case where duckling extract num_persone as time
            if num_persone is not None:
                num_persone_fix = int(num_persone)

            if time_to_evaluate != 0 and time_to_evaluate != num_persone_fix:  # handle case with no time entered and case
                # where duckling extract num_persone as time
                if time_to_evaluate < 11:
                    time_to_evaluate += 12  # from 02:00 to 14:00
                if (11 <= time_to_evaluate < 15) or (18 <= time_to_evaluate <
                                                     23):
                    saved_time = str(time_to_evaluate) + ":" + time[
                        1] + ":" + time[2] + ":" + time[3]
                    # from 2019-06-18T12:00:00.000+02:00 to 12:00:00.000+02:00
                else:
                    dispatcher.utter_template("utter_orario_chiuso", tracker)

            if datetime.strptime(date[:19], '%Y-%m-%dT%H:%M:%S').weekday(
            ) == 0:  # check if it's monday (close day)
                dispatcher.utter_template('utter_lunedi_chiuso', tracker)
            else:
                date = date.split("T")[0]

        #save in the slot the information that we got

        return [
            SlotSet('data', date),
            SlotSet('orario', saved_time),
            SlotSet('num_persone', num_persone)
        ]
Ejemplo n.º 5
0
    def validate(self, dispatcher: CollectingDispatcher, tracker: Tracker,
                 domain: Dict[Text, Any]) -> List[Dict]:
        temp = {}
        intent = tracker.latest_message['intent'].get('name')
        MISC = next(tracker.get_latest_entity_values('MISC'), None)
        libro = next(tracker.get_latest_entity_values('libro'), None)
        ORG = next(tracker.get_latest_entity_values('ORG'), None)
        loc = next(tracker.get_latest_entity_values('LOC'), None)
        PER = next(tracker.get_latest_entity_values('PER'), None)
        temp['libro'] = None
        temp['autores'] = None

        if intent == 'consulta_libros_kw' or intent == 'consulta_libro_kw' or \
                intent == 'consulta_libros_titulo_autor' or intent == 'consulta_libro_titulo_autor' or \
                intent == 'consulta_libros_titulo' or intent == 'consulta_libro_titulo' or \
                intent == 'consulta_libros_kw_autor' or intent == 'consulta_libro_kw_autor':
            if (MISC is not None
                    and libro is None) or (MISC is not None
                                           and libro is not None
                                           and len(libro) < len(MISC)):
                temp['libro'] = next(tracker.get_latest_entity_values('MISC'),
                                     None)
            elif libro is not None:
                temp['libro'] = libro.capitalize()
            elif loc is not None:
                temp['libro'] = loc
            elif PER is not None:
                temp['libro'] = PER
            elif ORG is not None:
                temp['libro'] = ORG

        if intent == 'consulta_libros_autor' or intent == 'consulta_libro_autor' or \
               intent == 'consulta_libros_autor' or intent == 'consulta_libro_autor' or \
                intent == 'consulta_libros_titulo_autor' or intent == 'consulta_libro_titulo_autor' or \
                intent == 'consulta_libros_kw_autor' or intent == 'consulta_libro_kw_autor':
            if PER is not None:
                if temp['libro'] is not None and PER.lower(
                ) == temp['libro'].lower():
                    autores = tracker.get_latest_entity_values('PER')
                    aux = None
                    for i in autores:
                        if i.lower() != temp['libro'].lower():
                            aux = i
                    temp['autores'] = aux
                else:
                    temp['autores'] = PER

        return [
            SlotSet('libro', temp['libro']),
            SlotSet('autores', temp['autores'])
        ]
Ejemplo n.º 6
0
 def run(self, dispatcher: CollectingDispatcher, tracker: Tracker,
         domain: Dict[Text, Any]):
     return [
         SlotSet("location",
                 next(tracker.get_latest_entity_values("city"), None))
     ]