Esempio n. 1
0
 def get_mock_ContextManager():
     mock_ContextManager = ContextManager()
     mock_ContextManager.state_transition = Mock(
         return_value=IntentRecord(self.TEST_INTENT_ID,
                                   state_id_after_transition))
     mock_ContextManager.get_reply_template = Mock(
         return_value=self.TEST_REPLY_TEMPLATE)
     return mock_ContextManager
Esempio n. 2
0
    def __init__(self):
        # system
        self.intent_dic = {}
        self.engine_list = [] 
        self.domain_list = []
        self.answer_formatter_dic = {}

        self._intent_loader = IntentLoader()
        self._domain_selector = DomainSelector()
        self._context_manager = ContextManager()
        self._global_preprocessors = [SynonymPreprocessor()]

        self._get_dialog_state, self._set_dialog_state = self._decide_get_and_set_dialog_state_method()
        self._load_domain()
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
Esempio n. 5
0
    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)
Esempio n. 6
0
    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)
Esempio n. 7
0
    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)