Exemple #1
0
def __check_callback(key, old_value, new_value):
    if key in __callbacks:
        if not Helper.is_equal(old_value, new_value):
            if key in __callbacks:
                cb = __callbacks[key]
                callback = cb[0]
                target_value = cb[1]
                if 'any' == target_value or Helper.is_equal(
                        new_value, target_value):
                    callback(key, new_value)
            else:
                logger.error("No %s callback to run.", key)
Exemple #2
0
def __detect_intent_texts(project_id, session_id, texts, language_code):
    """Returns the result of detect intent with texts as inputs.

    Using the same `session_id` between requests allows continuation
    of the conversation."""
    session_client = dialogflow.SessionsClient()

    session = session_client.session_path(project_id, session_id)
    # print('Session path: {}\n'.format(session))

    for text in texts:
        text_input = dialogflow.types.TextInput(text=text,
                                                language_code=language_code)

        query_input = dialogflow.types.QueryInput(text=text_input)

        response = session_client.detect_intent(session=session,
                                                query_input=query_input)

        if Helper.is_debug():
            print('=' * 20)
            print('Query text: {}'.format(response.query_result.query_text))
            print('Detected intent: {} (confidence: {})\n'.format(
                response.query_result.intent.display_name,
                response.query_result.intent_detection_confidence))
            print('Fulfillment text: {}\n'.format(
                response.query_result.fulfillment_text))

    return response.query_result
Exemple #3
0
    def __walk_timer(self):
        # arrived = Information.get_information('sub1_arrived')
        dest = Information.get_information('sub1_destination')
        # 如果還沒到且目的地不同,就會前進
        if dest is not None:
            # dest = Information.get_information('sub1_destination')
            if not Helper.is_arrived(self.current_location, dest):
                if len(self.locations) > 0:
                    self.current_location = self.locations.pop(0)
                    Information.set_information("location",
                                                self.current_location)
                    logger.debug("walk to: %s", str(self.current_location))
            if Helper.is_arrived(self.current_location, dest):
                logger.warn("Arrived.")
                Information.set_information('sub1_destination', None)
                # Information.set_information("sub1_arrived", True)

        if self.running:
            Timer(5, self.__walk_timer).start()
Exemple #4
0
def find_similar_location(name):
    threshold = 0.8
    s = 0
    name2, loc2 = None, None
    for k in __locations:
        s1 = Helper.similarity(name, k)
        if s1 >= threshold and s1 > s:
            s = s1
            loc2 = __locations[k]
            name2 = k

    return name2, loc2
Exemple #5
0
    def __start_dialogue(self, flac_file):
        resp = Dialogflow.send_voice(flac_file)
        threading.Thread(target=lambda: os.remove(flac_file)).start()
        logger.debug('Query text: {}'.format(resp.query_text))
        logger.debug('Detected intent: {} (confidence: {})'.format(
            resp.intent.action, resp.intent_detection_confidence))
        logger.debug('Fulfillment text: {}'.format(resp.fulfillment_text))

        action_module = Helper.get_module(intents.__name__, resp.action)
        if action_module is not None:
            logger.debug('Found module: {}'.format(str(action_module)))
            action_module.implement_intent(self.dialogue_client, resp)
        else:
            logger.error('Cannot find module: {}'.format(resp.action))
Exemple #6
0
import os
import threading
import time
import random
from dialogue import Helper, Dialogflow
from dialogue import intents

logger = Helper.get_module_logger(__name__)


class UserProcessor(threading.Thread):
    def __init__(self, group=None, args=(), kwargs=None, verbose=None):
        super(UserProcessor, self).__init__()
        self.user_words = args[0]
        self.dialogue_client = args[1]
        self.running = True
        logger.debug("__init__")
        return

    def __start_dialogue(self, flac_file):
        resp = Dialogflow.send_voice(flac_file)
        threading.Thread(target=lambda: os.remove(flac_file)).start()
        logger.debug('Query text: {}'.format(resp.query_text))
        logger.debug('Detected intent: {} (confidence: {})'.format(
            resp.intent.action, resp.intent_detection_confidence))
        logger.debug('Fulfillment text: {}'.format(resp.fulfillment_text))

        action_module = Helper.get_module(intents.__name__, resp.action)
        if action_module is not None:
            logger.debug('Found module: {}'.format(str(action_module)))
            action_module.implement_intent(self.dialogue_client, resp)