Пример #1
0
 def reply(self,
           slots: Dict[Slot, str],
           user_id=None) -> SingleTextResponse:
     output = self._es.search(index='shop-index',
                              body={
                                  "query": {
                                      "match": {
                                          "type": {
                                              "query": 'food',
                                              "fuzziness": "2"
                                          }
                                      }
                                  }
                              })['hits']['hits']
     output = output[0:min(3, len(output))]
     answer = []
     for x in output:
         x = x['_source']
         answer.append(
             SingleImageResponse(is_finished=True,
                                 is_successful=True,
                                 text=f'{x["name"]}, '
                                 f'floor: {x["floor"]}, type: {x["type"]}',
                                 img_url=x['image_url']))
     yield MultiImageBasedResponse(is_finished=True,
                                   is_successful=True,
                                   list_of_single_img_responses=answer)
    def reply(self,
              slots: Dict[Slot, str],
              user_id=None) -> Union[SingleTextResponse, SingleImageResponse]:
        shop_name = self._initial_slots[Slot.ShopByName]

        output = self._es.search(index='shop-index',
                                 body={
                                     "query": {
                                         "match": {
                                             "name": {
                                                 "query": shop_name,
                                                 "fuzziness": "2"
                                             }
                                         }
                                     }
                                 })['hits']['hits'][0]['_source']

        text = f'{output["name"]}, floor: {output["floor"]}, type: {output["type"]}'
        # TODO add description

        if output['image_url']:
            yield SingleImageResponse(is_finished=True,
                                      is_successful=True,
                                      text=text,
                                      img_url=output['image_url'],
                                      img_description='')
        else:
            yield SingleTextResponse(is_finished=True,
                                     is_successful=True,
                                     text=text)
Пример #3
0
    def reply(self, slots: Dict[Slot, str], user_id=None) -> Union[SingleTextResponse, SingleImageResponse]:

        name, profession = self._initial_slots[Slot.Name], self._initial_slots[Slot.NameProfession]
        output = self._es.search(index='collection-index', body={
            "query": {
                "match": {
                    "about_author.name": {
                        "query": name,
                        "fuzziness": "2"
                    }
                }
            }
        })['hits']['hits']
        output = random.choice(output)

        hall = output["_source"]["hall"] if output["_source"]["hall"] else random.randint(1, 25)
        picture_name = "'{}'".format(output["_source"]["art_name"])

        text = f'{name}, основная отрасль искусства: {profession}. Страна {output["_source"]["country"]}. ' \
               f'Одно из популярных произведений {picture_name}. Посмотреть на шедевр можно в {hall} зале'

        raw_text = clean_html(output['_source']['text']).split('.')

        summary = '.'.join(raw_text[0:2]) if len(raw_text) >= 2 else '.'.join(raw_text) + '.'

        descr = clean_html(output['_source']['annotation']) if output['_source']['annotation'] != 'empty' \
            else summary

        if output["_source"]['img']:
            yield SingleImageResponse(is_finished=True, is_successful=True, text=text,
                                      img_url=f'https://pushkinmuseum.art{output["_source"]["img"]}', img_description=descr)
        else:
            yield SingleTextResponse(is_finished=True, is_successful=True, text=text)
Пример #4
0
    def reply(self,
              slots: Dict[Slot, str],
              user_id=None) -> SingleTextResponse:
        output = self._es.search(index='shop-index',
                                 body={
                                     "query": {
                                         "match": {
                                             "type": {
                                                 "query": 'rentalcar',
                                                 "fuzziness": "2"
                                             }
                                         }
                                     }
                                 })['hits']['hits'][0]['_source']
        text = f'{output["name"]}, floor: {output["floor"]}, type: {output["type"]}'

        if output['image_url']:
            yield SingleImageResponse(is_finished=True,
                                      is_successful=True,
                                      text=text,
                                      img_url=output['image_url'],
                                      img_description='')
        else:
            yield SingleTextResponse(is_finished=True,
                                     is_successful=True,
                                     text=text)
Пример #5
0
    def reply(cls, slots: Dict[Slot, str], user_id=None) -> Union[SingleTextWithFactAttachments, SingleTextResponse]:
        hall = slots.get(Slot.HallName)

        if not hall:
            yield cls.FALLBACK_RESPONSE

        previous_location = cls._get_previous_location(user_id)
        previous_location_changed = False

        if previous_location:
            query, slots = yield SingleTextResponse(is_finished=False,
                                             is_successful=True,
                                             text=f'Скажите, находитесь ли вы сейчас в холле "{previous_location}"?')
            if query.lower() not in ['да', 'верно', 'ага']:
                previous_location_changed = True

        if previous_location_changed or not previous_location:
            _, slots = yield SingleTextResponse(is_finished=False,
                                             is_successful=True,
                                             text='Пожалуйста, уточните, в каком холле вы сейчас находитесь.')
            previous_location = slots.get(Slot.HallName)
            if not previous_location:
                yield cls.FALLBACK_RESPONSE

        route_builder = RouteBuilder(NEIGHBOR_PLACES)
        from_place = cls._find_corresponding_hall(previous_location)
        to_place = cls._find_corresponding_hall(hall)
        cls._log_previous_location(user_id=user_id, location=hall)
        try:
            route = route_builder.get_nearest_route(from_place=from_place, to_place= to_place)
            if len(route) == 1:
                yield SingleTextResponse(is_finished=True,
                                         is_successful=True,
                                         text='Вы уже на месте!')
            if len(route) <= 3:
                yield SingleTextResponse(is_finished=True,
                                         is_successful=True,
                                         text=cls._generate_route_text_description(route))
            else:
                draw_route_on_image(image_path=cls.MAP_IMAGE_PATH,
                                    route=route,
                                    save_img_path=cls.SAVE_IMAGE_PATH)
                yield SingleImageResponse(is_finished=True,
                                          is_successful=True,
                                          img_local_path=cls.SAVE_IMAGE_PATH,
                                          text='Следуйте проложенному маршруту!')
        except (ValueError, RouteBuilderError):
            yield cls.FALLBACK_RESPONSE
Пример #6
0
    def reply(self,
              slots: Dict[Slot, str],
              user_id=None) -> Union[SingleTextResponse, SingleImageResponse]:
        event_name = self._initial_slots[Slot.EventName]

        output = self._es.search(index='event-index',
                                 body={
                                     "query": {
                                         "match": {
                                             "event_name": {
                                                 "query": event_name,
                                                 "fuzziness": "2"
                                             }
                                         }
                                     }
                                 })['hits']['hits'][0]['_source']

        data_begin, data_end = output['dateBegin'], output['dateEnd']
        name = output['event_name']
        halls = output['halls'] if output['halls'] else 'уточняется'
        event_type = output['type']
        price = clean_html(
            output['price']) if output['price'] else 'уточняется'
        raw_text = clean_html(output['text']).split('.')
        summary = '.'.join(
            raw_text[0:5]) if len(raw_text) >= 5 else '.'.join(raw_text) + '.'

        text = f"{name}. Тип мероприятия: {event_type}. Будет проходить с {data_begin} по {data_end}. " \
               f"Место проведения: {halls}. Стоимость билетов: {price}.\nКоротко о событии: {summary}.".replace('\n'
                                                                                                                '<br '
                                                                                                                '/>',
                                                                                                                '').replace(' 00:00:00', '')
        img = output['img'] if output['img'] else output['extra_img']

        if img:
            yield SingleImageResponse(
                is_finished=True,
                is_successful=True,
                text=text,
                img_url=f'https://pushkinmuseum.art/{img}',
                img_description='')
        else:
            yield SingleTextResponse(is_finished=True,
                                     is_successful=True,
                                     text=text)
Пример #7
0
    def reply(self,
              slots: Dict[Slot, str],
              user_id=None) -> Union[SingleTextResponse, SingleImageResponse]:
        output = self._initial_slots[Slot.SlotByTag]
        output = output[0:min(3, len(output))]

        answer = []
        for x in output:
            x = x['_source']
            answer.append(
                SingleImageResponse(is_finished=True,
                                    is_successful=True,
                                    text=f'{x["name"]}, '
                                    f'floor: {x["floor"]}, type: {x["type"]}',
                                    img_url=x['image_url']))
        yield MultiImageBasedResponse(is_finished=True,
                                      is_successful=True,
                                      list_of_single_img_responses=answer)
Пример #8
0
    def reply(self,
              slots: Dict[Slot, str],
              user_id=None) -> Union[SingleTextResponse, SingleImageResponse]:
        art_name = self._initial_slots[Slot.ArtName]

        output = self._es.search(index='collection-index',
                                 body={
                                     "query": {
                                         "match": {
                                             "art_name": {
                                                 "query": art_name,
                                                 "fuzziness": "2"
                                             }
                                         }
                                     }
                                 })['hits']['hits'][0]

        author = output['_source']['about_author'][
            'name'] if 'about_author' in output['_source'] else 'неизвестен'
        hall = output["_source"]["hall"] if output["_source"][
            "hall"] != 'empty' else random.randint(1, 25)
        text = f'Работа {art_name}. Автор {author}. Посмотреть на шедевр можно в зале {hall}'

        raw_text = clean_html(output['_source']['text']).split('.')
        summary = '.'.join(
            raw_text[0:2]) if len(raw_text) >= 2 else '.'.join(raw_text) + '.'

        descr = clean_html(output['_source']['annotation']) if output['_source']['annotation'] != 'empty' \
            else summary

        if output["_source"]['img']:
            yield SingleImageResponse(
                is_finished=True,
                is_successful=True,
                text=text,
                img_url=f'https://pushkinmuseum.art{output["_source"]["img"]}',
                img_description=descr)
        else:
            yield SingleTextResponse(is_finished=True,
                                     is_successful=True,
                                     text=f'{text}\n{descr}')