import random
import json

from constants.constants import ANSWERS_FOR_UNRECOGNIZED_QUESTIONS


def load_intents():
    with open('./static/data/intents.json', encoding='utf-8', mode='r') as file:
        data = json.load(file)
    intents = {
        'pattern': [],
        'label': []
    }
    labels = []
    for intent in data["intents"]:
        for pattern in intent["patterns"]:
            intents['pattern'].append(pattern)
            intents['label'].append(intent["intent"])

            if intent["intent"] not in labels:
                labels.append(intent["intent"])
    return data


def get_answer_from_tag(intent):
    response = ''
    add_info = ''
    optional_questions = []
    additional_response = ""
    if intent == 'unrecognized_question':
        response = random.choice(ANSWERS_FOR_UNRECOGNIZED_QUESTIONS)
        add_info = ''
    else:
        for tg in load_intents()["intents"]:
            if tg['intent'] == intent:
                try:
                    response = tg['response']
                    add_info = tg['additional_info']
                    optional_questions = tg['options_for_questions']
                    additional_response = tg['additional_response']
                except KeyError:
                    pass
        response = random.choice(response)
    return response, add_info, optional_questions, additional_response


def load_additional_info(key, tag):
    tag = tag.split('_')[1]
    with open('./static/data/info_data.json', encoding='utf-8', mode='r') as file:
        data = json.load(file)
    return data[key][tag]

4886b2f5787e064ee11e4acf686e491090e41255
<mask token>


def get_answer_from_tag(intent):
    response = ''
    add_info = ''
    optional_questions = []
    additional_response = ''
    if intent == 'unrecognized_question':
        response = random.choice(ANSWERS_FOR_UNRECOGNIZED_QUESTIONS)
        add_info = ''
    else:
        for tg in load_intents()['intents']:
            if tg['intent'] == intent:
                try:
                    response = tg['response']
                    add_info = tg['additional_info']
                    optional_questions = tg['options_for_questions']
                    additional_response = tg['additional_response']
                except KeyError:
                    pass
        response = random.choice(response)
    return response, add_info, optional_questions, additional_response


<mask token>

<mask token>


def get_answer_from_tag(intent):
    response = ''
    add_info = ''
    optional_questions = []
    additional_response = ''
    if intent == 'unrecognized_question':
        response = random.choice(ANSWERS_FOR_UNRECOGNIZED_QUESTIONS)
        add_info = ''
    else:
        for tg in load_intents()['intents']:
            if tg['intent'] == intent:
                try:
                    response = tg['response']
                    add_info = tg['additional_info']
                    optional_questions = tg['options_for_questions']
                    additional_response = tg['additional_response']
                except KeyError:
                    pass
        response = random.choice(response)
    return response, add_info, optional_questions, additional_response


def load_additional_info(key, tag):
    tag = tag.split('_')[1]
    with open('./static/data/info_data.json', encoding='utf-8', mode='r'
        ) as file:
        data = json.load(file)
    return data[key][tag]

<mask token>


def load_intents():
    with open('./static/data/intents.json', encoding='utf-8', mode='r'
        ) as file:
        data = json.load(file)
    intents = {'pattern': [], 'label': []}
    labels = []
    for intent in data['intents']:
        for pattern in intent['patterns']:
            intents['pattern'].append(pattern)
            intents['label'].append(intent['intent'])
            if intent['intent'] not in labels:
                labels.append(intent['intent'])
    return data


def get_answer_from_tag(intent):
    response = ''
    add_info = ''
    optional_questions = []
    additional_response = ''
    if intent == 'unrecognized_question':
        response = random.choice(ANSWERS_FOR_UNRECOGNIZED_QUESTIONS)
        add_info = ''
    else:
        for tg in load_intents()['intents']:
            if tg['intent'] == intent:
                try:
                    response = tg['response']
                    add_info = tg['additional_info']
                    optional_questions = tg['options_for_questions']
                    additional_response = tg['additional_response']
                except KeyError:
                    pass
        response = random.choice(response)
    return response, add_info, optional_questions, additional_response


def load_additional_info(key, tag):
    tag = tag.split('_')[1]
    with open('./static/data/info_data.json', encoding='utf-8', mode='r'
        ) as file:
        data = json.load(file)
    return data[key][tag]

import random
import json
from constants.constants import ANSWERS_FOR_UNRECOGNIZED_QUESTIONS


def load_intents():
    with open('./static/data/intents.json', encoding='utf-8', mode='r'
        ) as file:
        data = json.load(file)
    intents = {'pattern': [], 'label': []}
    labels = []
    for intent in data['intents']:
        for pattern in intent['patterns']:
            intents['pattern'].append(pattern)
            intents['label'].append(intent['intent'])
            if intent['intent'] not in labels:
                labels.append(intent['intent'])
    return data


def get_answer_from_tag(intent):
    response = ''
    add_info = ''
    optional_questions = []
    additional_response = ''
    if intent == 'unrecognized_question':
        response = random.choice(ANSWERS_FOR_UNRECOGNIZED_QUESTIONS)
        add_info = ''
    else:
        for tg in load_intents()['intents']:
            if tg['intent'] == intent:
                try:
                    response = tg['response']
                    add_info = tg['additional_info']
                    optional_questions = tg['options_for_questions']
                    additional_response = tg['additional_response']
                except KeyError:
                    pass
        response = random.choice(response)
    return response, add_info, optional_questions, additional_response


def load_additional_info(key, tag):
    tag = tag.split('_')[1]
    with open('./static/data/info_data.json', encoding='utf-8', mode='r'
        ) as file:
        data = json.load(file)
    return data[key][tag]

import random
import json

from constants.constants import ANSWERS_FOR_UNRECOGNIZED_QUESTIONS


def load_intents():
    with open('./static/data/intents.json', encoding='utf-8', mode='r') as file:
        data = json.load(file)
    intents = {
        'pattern': [],
        'label': []
    }
    labels = []
    for intent in data["intents"]:
        for pattern in intent["patterns"]:
            intents['pattern'].append(pattern)
            intents['label'].append(intent["intent"])

            if intent["intent"] not in labels:
                labels.append(intent["intent"])
    return data


def get_answer_from_tag(intent):
    response = ''
    add_info = ''
    optional_questions = []
    additional_response = ""
    if intent == 'unrecognized_question':
        response = random.choice(ANSWERS_FOR_UNRECOGNIZED_QUESTIONS)
        add_info = ''
    else:
        for tg in load_intents()["intents"]:
            if tg['intent'] == intent:
                try:
                    response = tg['response']
                    add_info = tg['additional_info']
                    optional_questions = tg['options_for_questions']
                    additional_response = tg['additional_response']
                except KeyError:
                    pass
        response = random.choice(response)
    return response, add_info, optional_questions, additional_response


def load_additional_info(key, tag):
    tag = tag.split('_')[1]
    with open('./static/data/info_data.json', encoding='utf-8', mode='r') as file:
        data = json.load(file)
    return data[key][tag]
