def test_ask_division_depression_headache(self):
        answer_formatter = AnswerFormatter()

        intent_record = IntentRecord(200, 3)
        intent_record.user_paramenters = {'symptom': ['憂鬱', '頭痛']}
        reply_template = '建議您至{0}就診'
        answer = answer_formatter.formate_answer(intent_record, reply_template)
        self.assertEqual(answer['output'], '建議您至精神科就診')
    def test_ask_humidity_taipei(self):
        answer_formatter = AnswerFormatter()
        answer_formatter._query_external_api_json = self._get_mock_query_external_api(
        )

        intent_record = IntentRecord(104, 3)
        intent_record.user_paramenters = {'weather_query_city': '台北'}
        reply_template = '今天{0}的濕度為{1}%'
        answer = answer_formatter.formate_answer(intent_record, reply_template)

        self.assertEqual(answer['output'], '今天台北的天氣為晴,溫度為20度,濕度為50度')
Exemple #3
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)
Exemple #4
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
Exemple #5
0
    def test_get_reply_template_lack_para_reask(self):
        default_state=0
        last_state_id=98
        intent_record=IntentRecord(
            self.TEST_INTENT_ID, self.LACK_PARA_STATE_ID)
        intent_record.user_paramenters={
            'test_para': ['test_value', 'test_value2']}
        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('re_ask', result)
Exemple #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)
Exemple #7
0
        def get_intent_record_fit_intent_id_in_intent_record_list(user_intent_id, intent_record_list, current_intent):
            match_intent_record = next(
                (record for record in intent_record_list if record.intent_id == user_intent_id), None)
            if not match_intent_record:
                match_intent_record = IntentRecord(
                    user_intent_id, current_intent.initial_state_id)

            match_intent_record = fill_slot_with_default(
                current_intent, match_intent_record)

            return match_intent_record
Exemple #8
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)
Exemple #9
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)
Exemple #10
0
 def _get_IntentRecord(self, id, state_id):
     return_obj = IntentRecord(id, state_id)
     return_obj.user_paramenters = {'test_para_name': 'test_para_value'}
     return return_obj