Пример #1
0
def analyze_response(response_data):
    """
    Analyze LUIS response
    :param response_data: response data
    :return: response analyzed
    """
    try:
        # Retrieve intent
        intent = response_data['topScoringIntent']['intent']
        score = response_data['topScoringIntent']['score']
        log.info('|LUIS| Intent that we got [{}]'.format(intent))

        # Initialize answer array
        answer = list()

        # Check score
        if score < SCORE_THRESHOLD:
            answer.extend(error.get_message())
            return answer

        # Select intent
        if intent.startswith('Indication.Activity'):
            answer.extend(activities.get_message(response_data))
        elif intent.startswith('HackUPC'):
            answer.extend(hackupc.get_message(response_data))
        elif intent.startswith('HardwareLab'):
            answer.extend(hardware_lab.get_message(response_data))
        elif intent.startswith('Logistics'):
            answer.extend(logistics.get_message(response_data))
        elif intent.startswith('Meals'):
            answer.extend(meals.get_message(response_data))
        elif intent.startswith('Mentor'):
            answer.extend(mentor.get_message(response_data))
        elif intent.startswith('Indication.Place'):
            answer.extend(places.get_message(response_data))
        elif intent.startswith('Project'):
            answer.extend(projects.get_message(response_data))
        elif intent.startswith('Smalltalk'):
            answer.extend(smalltalk.get_message(response_data))
        elif intent.startswith('Sponsors'):
            answer.extend(sponsors.get_message(response_data))
        elif intent.startswith('Support'):
            answer.extend(support.get_message(response_data))
        else:
            if exists_biene(response_data):
                answer.extend(['BIENE'])
            else:
                answer.extend(error.get_message())
            return answer

        # Check for biene manually
        if exists_biene(response_data):
            answer.extend(['BIENE'])
        # Return array of answers
        return answer

    except Exception as e:
        # Log error and return default error message
        log.error(e)
        return error.get_message()
Пример #2
0
def get_message(response_type):
    """
    Return a message from a sponsor intent
    :param response_type luis response
    """
    with open(
            'hackupc/bienebot/responses/places/places_data.json') as json_data:
        data = json.load(json_data)

        intent = response_type['topScoringIntent']['intent']
        list_intent = intent.split('.')

        entities = response_type['entities']

        # Log stuff
        if entities:
            log_info = '|RESPONSE| About [{}] getting [{}]'.format(
                entities[0]['entity'], list_intent[1])
        else:
            log_info = '|RESPONSE| No entities about places'
        log.info(log_info)

        switcher = {'When': when, 'Where': where, 'Help': help_place}
        # Get the function from switcher dictionary
        func = switcher.get(list_intent[2], lambda: error.get_message())
        # Execute the function
        return func(data, entities)
Пример #3
0
def get_message(response_type):
    """
    Return a message from a logistics intent.
    :param response_type LUIS response.
    """
    with open('hackupc/bienebot/responses/logistics/logistics_data.json'
              ) as json_data:
        data = json.load(json_data)

        prediction = response_type['prediction']

        entities = prediction['entities']

        question_type = entities.get('QuestionType', [['When']])[0][0]

        if question_type not in ACCEPTED_QUESTION_TYPES:
            question_type = 'When'

        logistics = entities.get('Logistic', [['']])[0][0]

        switcher = {'How': how, 'When': when, 'Where': where}
        # Get the function from switcher dictionary
        func = switcher.get(question_type, lambda: error.get_message())
        # Execute the function
        return func(data, logistics)
Пример #4
0
def get_message(response_type):
    """
    Return a message from a sponsor intent.
    :param response_type LUIS response.
    """
    with open('hackupc/bienebot/responses/sponsors/sponsors_data.json') as json_data:
        data = json.load(json_data)

        intent = response_type['topScoringIntent']['intent']
        list_intent = intent.split('.')
        entities = response_type['entities']

        # Log stuff
        if entities:
            entity = entities[0]['entity']
            log_info = f'|RESPONSE| About [{entity}] getting [{list_intent[1]}]'
        else:
            log_info = f'|RESPONSE| Getting [{list_intent[1]}] about all sponsors'
        log.debug(log_info)

        switcher = {
            'Which': which_sponsor,
            'Help': help_sponsor,
            'AllChallenges': all_challenges_sponsor,
            'Where': where,
            'Challenge': challenge,
            'Contact': contact
        }
        # Get the function from switcher dictionary
        func = switcher.get(list_intent[1], lambda: error.get_message())
        # Execute the function
        return func(data, entities)
Пример #5
0
def analyze_response(response_data):
    """
    Analyze LUIS response.
    :param response_data: Response data to analyze.
    :return: Response analyzed.
    """
    try:
        # Retrieve intent
        prediction = response_data['prediction']
        intent = prediction['topIntent']
        score = prediction['intents'][intent]['score']
        log.debug(f'|LUIS| Intent that we got [{intent}]')

        # Initialize answer array
        answer = list()

        # Check score (if score retrieved from the API is lower than the config. value, discard the option and raise error.)
        if score < SCORE_THRESHOLD:
            answer.extend(error.get_message())
            return answer

        # Select intent
        if intent == 'Indication.Activity':
            answer.extend(activities.get_message(response_data))
        elif intent == 'HackUPC':
            answer.extend(hackupc.get_message(response_data))
        elif intent == 'HardwareLab':
            answer.extend(hardware_lab.get_message(response_data))
        elif intent == 'Logistics':
            answer.extend(logistics.get_message(response_data))
        elif intent == 'Meals':
            answer.extend(meals.get_message(response_data))
        elif intent == 'Mentor':
            answer.extend(mentor.get_message(response_data))
        elif intent == 'Indication.Place':
            answer.extend(places.get_message(response_data))
        elif intent == 'Project':
            answer.extend(projects.get_message(response_data))
        elif intent == 'Smalltalk':
            answer.extend(smalltalk.get_message(response_data))
        elif intent.startswith('Sponsors'):
            answer.extend(sponsors.get_message(response_data))
        elif intent == 'Support':
            answer.extend(support.get_message(response_data))
        else:
            if exists_biene(response_data):
                answer.extend(['BIENE'])
            else:
                answer.extend(error.get_message())
            return answer

        # Check for biene manually
        if exists_biene(response_data):
            answer.extend(['BIENE'])

        # Return array of answers
        return answer

    except Exception as e:
        log.exception(e)
        return error.get_message()