def setUp(self): HttpRasa.make_continue_request('utter_change_location', 'test', 'restart') HttpRasa.make_continue_request_with_set_slot('utter_change_location', 'test', 'welcomeform_end', True) print('')
def test_give_number_intent(self): print('-- give_number --') self.csv_file.write("GIVE NUMBER\n") give_number_messages = [ 'My phone number is 634586960', "123456789", "34263748523", "My number is 34263748528" ] give_number_entities = [ '634586960', '123456789', '34263748523', "34263748528" ] counter = 0 for message in give_number_messages: json_result = HttpRasa.make_parse_request_from_text( message, 'test') json_intent = JsonRasaParser.get_intent_from_parse_response( json_result) second_json_intent = JsonRasaParser.get_intent_position_from_response( json_result, 2) json_slots = JsonRasaParser.get_slots_from_response(json_result) self.intent_check("give_number", message, json_intent, second_json_intent) self.slot_check("number", give_number_entities[counter], json_slots) counter = counter + 1 self.csv_file.write("\n")
def test_give_name_intent(self): print('-- give_name_intent --') self.csv_file.write("GIVE NAME\n") give_name_messages = { "My name is Jose": "jose", "My name is Ivan": "ivan", "My name is Alvaro": "alvaro", "The name's Pedro": "pedro", "My name is Paula": "paula", "The name's Paula": "paula", "My name is Alberto": "alberto", "My name is Cesar": "cesar" } counter = 0 for message in give_name_messages: print(message) json_result = HttpRasa.make_parse_request_from_text( message, 'test') json_intent = JsonRasaParser.get_intent_from_parse_response( json_result) second_json_intent = JsonRasaParser.get_intent_position_from_response( json_result, 2) json_slots = JsonRasaParser.get_slots_from_response(json_result) self.intent_check("give_name", message, json_intent, second_json_intent) self.slot_check("PERSON", give_name_messages[message], json_slots) counter = counter + 1 self.csv_file.write("\n")
def simulate_flow(self, parse_word, parse_action, continue_actions): json_result = HttpRasa.make_parse_request_from_text(parse_word, 'test') json_next_action = JsonRasaParser.get_next_action_from_response( json_result) print('From phrase: ' + parse_word) print('expected action: ' + parse_action) print('real action: ' + json_next_action) self.assertEqual(parse_action, json_next_action) next_action = parse_action for continue_action in continue_actions: json_result = HttpRasa.make_continue_request(next_action, 'test') next_action = JsonRasaParser.get_next_action_from_response( json_result) self.assertEqual(continue_action, next_action)
def test_welcome_flow(self): print('welcome_flow') HttpRasa.make_continue_request_with_set_slot('utter_change_location', 'test', 'welcomeform_end', True) self.simulate_flow('hello', 'utter_greet', ['action_listen']) self.simulate_flow('My name is fsdsfvsdcvdf', 'utter_no_name', ['action_listen']) self.simulate_flow('My name is edsxascdsacxsa', 'utter_no_name', ['action_listen']) self.simulate_flow('My name is Jose', 'utter_give_name', ['action_listen']) self.simulate_flow('My number is 938', 'utter_no_number', ['action_listen']) self.simulate_flow('My number is 32', 'utter_no_number', ['action_listen']) self.simulate_flow('My number is 789654321', 'utter_give_number', ['utter_give_location', 'action_listen']) ##Check if the state machine base is reset self.simulate_flow('lost', 'utter_lost', ['action_listen'])
def test_greet_intent(self): print('-- greet_intent --') self.csv_file.write("GREET\n") greet_messages = ['Hello', "hey there", "good morning", "good evening"] for message in greet_messages: json_result = HttpRasa.make_parse_request_from_text( message, 'test') json_intent = JsonRasaParser.get_intent_from_parse_response( json_result) second_json_intent = JsonRasaParser.get_intent_position_from_response( json_result, 2) self.intent_check("greet", message, json_intent, second_json_intent) self.csv_file.write("\n")
def test_lost_intent(self): print('-- lost_intent --') self.csv_file.write("LOST\n") goodbye_messages = [ 'lost', "i don't know where i am", "i am afraid i am lost", "i'm lost", "Help", "I am lost, help!" ] for message in goodbye_messages: json_result = HttpRasa.make_parse_request_from_text( message, 'test') json_intent = JsonRasaParser.get_intent_from_parse_response( json_result) second_json_intent = JsonRasaParser.get_intent_position_from_response( json_result, 2) self.intent_check("lost", message, json_intent, second_json_intent) self.csv_file.write("\n")
def test_distance_intent(self): print('-- distance_intent --') self.csv_file.write("DISTANCE\n") goHome_messages = [ 'distance', "how far am i from home?", "am i too far from home?", "What is the distance between me and my home?" ] for message in goHome_messages: json_result = HttpRasa.make_parse_request_from_text( message, 'test') json_intent = JsonRasaParser.get_intent_from_parse_response( json_result) second_json_intent = JsonRasaParser.get_intent_position_from_response( json_result, 2) self.intent_check("distance", message, json_intent, second_json_intent) self.csv_file.write("\n")
def test_go_home_intent(self): print('-- go_home_intent --') self.csv_file.write("GO HOME\n") goHome_messages = [ 'go home', "i want to go back", "i wanna go home", "Can you show me the route to my home?", "Show me the route to home", "I would like to go home" ] for message in goHome_messages: json_result = HttpRasa.make_parse_request_from_text( message, 'test') json_intent = JsonRasaParser.get_intent_from_parse_response( json_result) second_json_intent = JsonRasaParser.get_intent_position_from_response( json_result, 2) self.intent_check("go_home", message, json_intent, second_json_intent) self.csv_file.write("\n")
def test_change_location_intent(self): print('-- change_location --') self.csv_file.write("CHANGE LOCATION\n") give_number_messages = [ 'i want to change my location', 'change location', 'change home location' ] counter = 0 for message in give_number_messages: json_result = HttpRasa.make_parse_request_from_text( message, 'test') json_intent = JsonRasaParser.get_intent_from_parse_response( json_result) second_json_intent = JsonRasaParser.get_intent_position_from_response( json_result, 2) self.intent_check("change_location", message, json_intent, second_json_intent) counter = counter + 1 self.csv_file.write("\n")
def setUpClass(cls): cls.csv_file.write( 'Message; Confidence factor; Diff CF; Second intent \n') HttpRasa.make_continue_request('utter_change_location', 'test', 'restart')