def emotional_mindset_func(query, tok, entities): if (re.search('happiness', query)): entities.append('"Status": "Happiness"') elif (re.search('optimism', query)): entities.append('"Status": "Optimism"') elif (re.search('(self(-| )esteem)', query)): entities.append('"Status": "Self_Esteem"') elif (re.search('(self(-| )motivation)', query)): entities.append('"Status": "Self_Motivation"') elif (re.search('(emotional (assessment|intelligence|profile))|eq', query)): entities.append('"Status": "Emotional_Assessment"') else: m = load_model( 'D:\\bot\\botapi\\botapi\\models\\Emotional_Assessment\\Emotional_Mindset_Model.h5' ) score = model_score_LSTM_tokenize(query, tok, m) if ((score[0][0] > score[0][1]) & (score[0][0] > score[0][2]) & (score[0][0] > score[0][3]) & (score[0][0] > score[0][4])): entities.append('"Status": "Happiness"') elif ((score[0][1] > score[0][0]) & (score[0][1] > score[0][2]) & (score[0][1] > score[0][3]) & (score[0][1] > score[0][4])): if (re.search('optimisim|optimistic', query)): entities.append('"Status": "Optimism"') else: entities.append('"Status": "Emotional_Mindset"') elif ((score[0][2] > score[0][0]) & (score[0][2] > score[0][1]) & (score[0][2] > score[0][3]) & (score[0][2] > score[0][4])): entities.append('"Status": "Emotional_Mindset"') elif ((score[0][3] > score[0][0]) & (score[0][3] > score[0][1]) & (score[0][3] > score[0][2]) & (score[0][3] > score[0][4])): entities.append('"Status": "Self_Esteem"') else: entities.append('"Status": "Self_Motivation"') return entities
def persona_model(query, persona_tok): intent = '' m = load_model( 'D:\\bot\\botapi\\botapi\\models\\Behavioral_Assesment\\Assessment_concious_core_persona_Model.h5' ) score = model_score_LSTM_tokenize(query, persona_tok, m) if ((score[0][0] > score[0][1]) & (score[0][0] > score[0][2]) & (score[0][0] > score[0][3])): intent = 'Graphs' elif ((score[0][1] > score[0][0]) & (score[0][1] > score[0][2]) & (score[0][1] > score[0][3])): intent = 'Inquire_Energy' elif ((score[0][2] > score[0][0]) & (score[0][2] > score[0][3]) & (score[0][2] > score[0][3])): intent = 'Inquire_Intesity' else: intent = 'Intensity' return intent
def understanding_self_and_others_func(query, tok, entities): if (re.search('empathy', query)): entities.append('"Status": "Empathy"') elif (re.search('(understanding self (and|&) other)', query)): entities.append('"Status": "Understanding_Self_And_Others"') elif (re.search('understanding self', query)): entities.append('"Status": "Understanding_Self"') else: m = load_model( 'D:\\bot\\botapi\\botapi\\models\\Emotional_Assessment\\Understanding_Self_And_Others_Model.h5' ) score = model_score_LSTM_tokenize(query, tok, m) if ((score[0][0] > score[0][1]) & (score[0][0] > score[0][2])): entities.append('"Status": "Empathy"') elif ((score[0][1] > score[0][0]) & (score[0][1] > score[0][2])): entities.append('"Status": "Understanding_Self_And_Others"') else: entities.append('"Status": "Understanding_Self"') return entities
def mastering_self_func(query, tok, entities): if (re.search('stress managment', query)): entities.append('"Status": "Stress_Managment"') elif (re.search('impulse control', query)): entities.append('"Status": "Impulse_Control"') elif (re.search('emotional self control', query)): entities.append('"Status": "Emotional_Self_Control"') elif (re.search('bias managment', query)): entities.append('"Status": "Bias_Managment"') elif (re.search('change managment', query)): entities.append('"Status": "Change_Managment"') else: m = load_model( 'D:\\bot\\botapi\\botapi\\models\\Emotional_Assessment\\Assessment_emotional_mastering_self.h5' ) score = model_score_LSTM_tokenize(query, tok, m) if ((score[0][0] > score[0][1]) & (score[0][0] > score[0][2]) & (score[0][0] > score[0][3]) & (score[0][0] > score[0][4]) & (score[0][0] > score[0][5])): entities.append('"Status": "Bias_Managment"') elif ((score[0][1] > score[0][0]) & (score[0][1] > score[0][2]) & (score[0][1] > score[0][3]) & (score[0][1] > score[0][4]) & (score[0][1] > score[0][5])): entities.append('"Status": "Change_Managment"') elif ((score[0][2] > score[0][0]) & (score[0][2] > score[0][1]) & (score[0][2] > score[0][3]) & (score[0][2] > score[0][4]) & (score[0][2] > score[0][5])): entities.append('"Status": "Emotional_Self_Control"') elif ((score[0][3] > score[0][0]) & (score[0][3] > score[0][1]) & (score[0][3] > score[0][2]) & (score[0][3] > score[0][4]) & (score[0][3] > score[0][5])): entities.append('"Status": "Impulse_Control"') elif ((score[0][4] > score[0][0]) & (score[0][4] > score[0][1]) & (score[0][4] > score[0][2]) & (score[0][4] > score[0][3]) & (score[0][4] > score[0][5])): entities.append('"Status": "Mastering_Self"') else: entities.append('"Status": "Stress_Managment"') return entities
def mastering_self_with_others(query, tok, entities): if (re.search('assertiveness', query)): entities.append('"Status": "Assertiveness"') elif (re.search('influence', query)): entities.append('"Status": "Influence"') elif (re.search('managing relationship', query)): entities.append('"Status": "Managing_Relationships"') elif (re.search('decision confidence', query)): entities.append('"Status": "Decision_Confidence"') elif (re.search('emotional expression', query)): entities.append('"Status": "Emotional_Expression"') else: m = load_model( 'D:\\bot\\botapi\\botapi\\models\\Emotional_Assessment\\Mastering_self_with_others.h5' ) score = model_score_LSTM_tokenize(query, tok, m) if ((score[0][0] > score[0][1]) & (score[0][0] > score[0][2]) & (score[0][0] > score[0][3]) & (score[0][0] > score[0][4]) & (score[0][0] > score[0][5])): entities.append('"Status": "Assertiveness"') elif ((score[0][1] > score[0][0]) & (score[0][1] > score[0][2]) & (score[0][1] > score[0][3]) & (score[0][1] > score[0][4]) & (score[0][1] > score[0][5])): entities.append('"Status": "Decision_Confidence"') elif ((score[0][2] > score[0][0]) & (score[0][2] > score[0][1]) & (score[0][2] > score[0][3]) & (score[0][2] > score[0][4]) & (score[0][2] > score[0][5])): entities.append('"Status": "Emotional_Expression"') elif ((score[0][3] > score[0][0]) & (score[0][3] > score[0][1]) & (score[0][3] > score[0][2]) & (score[0][3] > score[0][4]) & (score[0][3] > score[0][5])): entities.append('"Status": "Influence"') elif ((score[0][4] > score[0][0]) & (score[0][4] > score[0][1]) & (score[0][4] > score[0][2]) & (score[0][4] > score[0][3]) & (score[0][4] > score[0][5])): entities.append('"Status": "Mastering_Self_With_Others"') else: entities.append('"Status": "Managing_Relationships"') return entities
def Flex_persona(query, flex_tok): intent = '' if (re.search('shift', query)): if (re.search(' above| up', query)): intent = '"Shift" : "Above"' if (re.search(' below| down', query)): intent = '"Shift" : "Below"' else: m = load_model( 'D:\\bot\\botapi\\botapi\\models\\Behavioral_Assesment\\Flex_model.h5' ) score = model_score_LSTM_tokenize(query, flex_tok, m) if ((score[0][0] > score[0][1]) & (score[0][0] > score[0][2]) & (score[0][0] > score[0][3]) & (score[0][0] > score[0][4])): intent = '"Shift" : "Change_Behavior"' elif ((score[0][1] > score[0][0]) & (score[0][1] > score[0][2]) & (score[0][1] > score[0][3]) & (score[0][1] > score[0][4])): if (re.search(' graph| flex', query)): intent = 'Graphs' else: intent = 'Inquiry' elif ((score[0][2] > score[0][0]) & (score[0][2] > score[0][3]) & (score[0][2] > score[0][3]) & (score[0][2] > score[0][4])): intent = "Inquiry" elif ((score[0][3] > score[0][0]) & (score[0][3] > score[0][2]) & (score[0][3] > score[0][1]) & (score[0][3] > score[0][4])): if (re.search('shift below', query)): intent = '"Shift" : "Below"' else: intent = '"Shift" : "Above"' else: if (re.search('shift above', query)): intent = '"Shift" : "Above"' else: intent = '"Shift" : "Below"' return intent
def capability_assessment_model(query, capability_entity, entity): top_intent = '"Assessment"' sub_intent = '"Capability_Assessment"' Score = 100 report_check = 0 graph_check = 0 if (re.search('verbal interpretation', query)): entity.append('"Status" : "Verbal_Interpretation"') entity = main_entity(query, capability_entity[1], entity) elif (re.search('numerical reasoning', query)): entity.append('"Status" : "Numerical_Reasoning"') entity = main_entity(query, capability_entity[1], entity) elif (re.search('spatial visualization', query)): entity.append('"Status" : "Spatial_Visualization"') entity = main_entity(query, capability_entity[1], entity) elif (re.search('perceptual speed', query)): entity.append('"Status" : "Perceptual_Speed"') entity = main_entity(query, capability_entity[1], entity) elif (re.search('verbal reasoning', query)): entity.append('"Status" : "Verbal_Reasoning"') entity = main_entity(query, capability_entity[1], entity) elif (re.search('capability (assessment|profile)', query)): intent = overall(query, capability_entity[2]) if (intent == 'Inquiry'): entity.append('"Status": "Inquiry"') else: entity.append('"Status" : "Capability_Assessment"') if (intent == 'Report'): report_check = 1 entity.append('"Report":"1"') entity.append('"Intensity" : "0"') entity.append('"Percentile" : 0"') elif (intent == 'Score'): entity = main_entity(query, capability_entity[1], entity) elif (intent == 'Graph'): graph_check = 1 entity.append('"Graph":"1"') entity.append('"Intensity" : "0"') entity.append('"Percentile" : 0"') else: m = load_model( 'D:\\bot\\botapi\\botapi\\models\\Capability_Assessment\\capability_assessment.h5py' ) score = model_score_LSTM_tokenize(query, capability_entity[0], m) if ((score[0][0] > score[0][1]) & (score[0][0] > score[0][2]) & (score[0][0] > score[0][3]) & (score[0][0] > score[0][4]) & (score[0][0] > score[0][5])): entity.append('"Status" : "Verbal_Interpretation"') entity = main_entity(query, capability_entity[1], entity) elif ((score[0][1] > score[0][0]) & (score[0][1] > score[0][2]) & (score[0][1] > score[0][3]) & (score[0][1] > score[0][4]) & (score[0][1] > score[0][5])): entity.append('"Status" : "Numerical_Reasoning"') entity = main_entity(query, capability_entity[1], entity) #top_intent = 'numerical_reasoning' elif ((score[0][2] > score[0][0]) & (score[0][2] > score[0][3]) & (score[0][2] > score[0][3]) & (score[0][2] > score[0][4]) & (score[0][2] > score[0][5])): entity.append('"Status" : "Spatial_Visualization"') entity = main_entity(query, capability_entity[1], entity) #top_intent = 'spatial Visualization ' elif ((score[0][3] > score[0][0]) & (score[0][3] > score[0][2]) & (score[0][3] > score[0][1]) & (score[0][3] > score[0][4]) & (score[0][3] > score[0][5])): entity.append('"Status" : "Overall"') intent = overall(query, capability_entity[2]) if (intent == 'Inquiry'): entity.append('"Status": "Inquiry"') else: entity.append('"Status" : "Capability_Assessment"') if (intent == 'Report'): report_check = 1 entity.append('"Report":"1"') entity.append('"Intensity" : "0"') entity.append('"Percentile" : 0"') elif (intent == 'Score'): entity = main_entity(query, capability_entity[1], entity) elif (intent == 'Graph'): graph_check = 1 entity.append('"Graph":"1"') entity.append('"Intensity" : "0"') entity.append('"Percentile" : 0"') elif ((score[0][4] > score[0][0]) & (score[0][4] > score[0][2]) & (score[0][4] > score[0][3]) & (score[0][4] > score[0][1]) & (score[0][4] > score[0][5])): entity.append('"Status" : "Perceptual_Speed"') entity = main_entity(query, capability_entity[1], entity) #top_intent = 'Perceptual Speed' else: entity.append('"Status" : "Verbal_Reasoning"') entity = main_entity(query, capability_entity[1], entity) #top_intent = 'verbal_reasoning' Score = str(Score) if (report_check == 0): entity.append('"Report":"0"') if (graph_check == 0): entity.append('"Graph":"0"') return ('{"TopIntent": ' + top_intent + ', "SubIntent": ' + sub_intent + ', "Percentage":' + Score, entity)
from keras.models import load_model import pandas as pd from functions import token_stems from functions import tok_behavior_flex from functions import model_score_LSTM_tokenize data = pd.read_excel("D:\\virtual\\Org chart.xlsx") text = data['Data'] x = [] for a in text: x.append(token_stems(a)) tok = tok_behavior_flex(x) m = load_model("C:\\Users\\shiza.abid\\Org_chart.h5py") #FOR QUERY query = "send me my organization chart" score = model_score_LSTM_tokenize(query, tok, m) if (score[0][0] > score[0][1]): print("Org chart") else: print("JD") print(score)