def test_state_transition_no_parameter_state_transfer(self): from_state_id = 99 to_state_id = 100 engine_query_result = EngineQueryResult( self.TEST_INTENT_ID, self.DETERMINISTIC_RESULT_PROB, to_state_id, {}, []) intent_record = IntentRecord(self.TEST_INTENT_ID, from_state_id) intent = Intent(self.TEST_INTENT_ID, 'test_domain', from_state_id, { (from_state_id, None): 'test_reply'}, {}) context_manager = ContextManager() result = context_manager.state_transition( engine_query_result, intent_record, intent, False) self.assertEqual(self.TEST_INTENT_ID, result.intent_id) self.assertEqual(to_state_id, result.state_id)
def test_get_reply_template_lack_para_ask(self): default_state=0 last_state_id=98 intent_record=IntentRecord( self.TEST_INTENT_ID, self.LACK_PARA_STATE_ID) intent=Intent( self.TEST_INTENT_ID, 'test_domain', default_state, {}, [IntentParameter('test_keyword_name', 'test_para', 'ask', 2, 're_ask', None, 'string')]) context_manager=ContextManager() result=context_manager.get_reply_template( intent, intent_record, last_state_id) self.assertEqual('ask', result)
def get_mock_IntentLoader(): with patch.object(IntentLoader, "__init__", lambda x: None): return_IntentLoader = IntentLoader() return_IntentLoader.get_domain_list = Mock( return_value=[self.TEST_DOMAIN_NAME, self.TEST_DOMAIN_NAME_2]) return_IntentLoader.get_intent_dic = Mock( return_value={ self.TEST_INTENT_ID: Intent(self.TEST_INTENT_ID, self.TEST_DOMAIN_NAME, 0, { (self.TEST_TO_STATE_ID, None): self.TEST_REPLY_TEMPLATE }, []) }) return_IntentLoader.get_engine_list = Mock( return_value=get_mock_engine_list()) return return_IntentLoader
def test_get_reply_template_no_para_default_reply(self): last_state_id=0 from_state_id=99 intent_record=IntentRecord(self.TEST_INTENT_ID, from_state_id) intent_record.user_paramenters={ 'test_para': ['test_value', 'test_value2']} intent = Intent( self.TEST_INTENT_ID, 'test_domain', from_state_id, {(from_state_id, None): ['test_reply']}, [IntentParameter('test_keyword_name', 'test_para', 'ask', 2, 're_ask', None, 'string')]) context_manager=ContextManager() result=context_manager.get_reply_template( intent, intent_record, last_state_id) self.assertEqual('test_reply', result)
def test_state_transition_multi_value_slot_less_than_max_but_stop(self): from_state_id=99 to_state_id=100 engine_query_result=EngineQueryResult( self.TEST_INTENT_ID, self.DETERMINISTIC_RESULT_PROB, to_state_id, {}, []) intent_record=IntentRecord(self.TEST_INTENT_ID, from_state_id) intent_record.user_paramenters={'test_para': ['test_value']} intent=Intent( self.TEST_INTENT_ID, 'test_domain', from_state_id, {(from_state_id, from_state_id): 'test_reply'}, [IntentParameter('test_keyword_name', 'test_para', 'ask', 2, 're_ask', None, 'string')]) context_manager=ContextManager() result=context_manager.state_transition( engine_query_result, intent_record, intent, True) self.assertEqual(self.TEST_INTENT_ID, result.intent_id) self.assertEqual(self.PARA_SATISFIED_STATE_ID, result.state_id)
def test_state_transition_None_to_parameter_not_satisfied(self): from_state_id = 99 to_state_id = 100 engine_query_result = EngineQueryResult( self.TEST_INTENT_ID, self.DETERMINISTIC_RESULT_PROB, to_state_id, {}, []) intent_record = IntentRecord(self.TEST_INTENT_ID, from_state_id) intent=Intent( self.TEST_INTENT_ID, 'test_domain', from_state_id, {(from_state_id, from_state_id): 'test_reply'}, [IntentParameter('test_keyword_name', 'test_para', 'ask', 1, None, None, 'string')]) context_manager=ContextManager() result=context_manager.state_transition( engine_query_result, intent_record, intent, False) self.assertEqual(self.TEST_INTENT_ID, result.intent_id) self.assertEqual(self.LACK_PARA_STATE_ID, result.state_id)
def get_intent_dic(self): def select_intent_parameter_by_intent_id(): return [ intent_parameter for intent_parameter in intent_parameter_list if intent_parameter[1] == intent_id ] def select_intent_reply_by_intent_id(): return_dic = {} for reply_intent_id, state_id, reply, last_state_id in intent_reply_list: if reply_intent_id == intent_id: dic_key = (state_id, last_state_id) if dic_key in return_dic: return_dic[dic_key].append(reply) else: return_dic[dic_key] = [reply] return return_dic def parameter_dic_to_object(): return [ IntentParameter(p[0], p[2], p[3], p[4], p[5], p[6], p[7]) for p in this_intent_parameter_list ] return_dic = {} intent_list, intent_parameter_list, intent_reply_list = self._db_interactor.get_intent_list_from_db( ) for intent_id, domain_name, initial_state_id in intent_list: this_intent_parameter_list = select_intent_parameter_by_intent_id() this_intent_reply_dic = select_intent_reply_by_intent_id() this_intent_parameter_object_list = parameter_dic_to_object() return_dic[intent_id] = Intent(intent_id, domain_name, initial_state_id, this_intent_reply_dic, this_intent_parameter_object_list) return return_dic
def _get_intend_dic(self): return { 100: Intent(100, 'News', 2, 'reply', None), 200: Intent(100, 'Weather', 2, 'reply', None) }