def testGetNlu(self): ''' 测试getNlu方法 :return: ''' nlu = Nlu(self.data['request']['intents']) self.assertEqual(self.request.get_nlu().to_directive(), nlu.to_directive())
def setUp(self): with open('../json/intent_request.json', encoding='utf-8') as f: self.request_data = f.read() self.request_data = json.loads(self.request_data) self.data = self.request_data['request']['intents'] self.nlu = Nlu(self.data) self.updateIntent = { 'name': self.nlu.get_intent_name(), 'slots': self.data[0]['slots'] }
def __init__(self, data): ''' :param data: 请求数据 ''' self.data = json.loads(data) self.requestType = self.data['request']['type'] self.session = Session(self.data['session']) self.nlu = None if self.requestType == 'IntentRequest': self.nlu = Nlu(self.data['request']['intents']) self.deviceData = None self.arrUserProfile = None
def __init__(self, request_data): """ :param request_data: 请求数据 """ super(Request, self).__init__() if isinstance(request_data, str): request_data = json.loads(request_data) self.data = request_data self.request_type = self.data['request']['type'] self.session = Session(self.data['session']) self.nlu = None if self.request_type == 'IntentRequest': self.nlu = Nlu(self.data['request']['intents']) self.device_data = None self.arr_user_profile = None
def __init__(self, data): """ :param data: 请求数据 """ super(Request, self).__init__() if not isinstance(data, dict): self.data = json.loads(data) else: self.data = data self.request_type = self.data['request']['type'] self.session = Session(self.data['session']) self.nlu = None if self.request_type == 'IntentRequest': self.nlu = Nlu(self.data['request']['intents']) self.deviceData = None self.arrUserProfile = None
def __init__(self, data): ''' :param data: 请求数据 ''' super(Request, self).__init__() if isinstance(data, dict): self.data = data elif isinstance(data, str): self.data = json.loads(data) self.requestType = self.data['request']['type'] self.session = Session(self.data['session']) self.nlu = None if self.requestType == 'IntentRequest': self.nlu = Nlu(self.data['request']['intents']) self.deviceData = None self.arrUserProfile = None
class NluTest(unittest.TestCase): def setUp(self): with open('../json/intent_request.json') as f: self.requestData = f.read() self.requestData = json.loads(self.requestData.encode('utf-8')) self.data = self.requestData['request']['intents'] self.nlu = Nlu(self.data) self.updateIntent = { 'name': self.nlu.get_intent_name(), 'slots': self.data[0]['slots'] } def test_getslot(self): ''' 测试getSlot方法 :return: ''' self.assertEqual(self.nlu.get_slot('city'), '北京') def test_getslotconfirmationstatus(self): ''' 测试getSlotConfirmationStatus方法 :return: ''' self.assertEqual(self.nlu.get_slot_confirmation_status('city'), 'NONE') def test_getintentconfirmationstatus(self): ''' 测试getIntentConfirmationStatus方法 :return: ''' self.assertEqual(self.nlu.get_intent_confirmation_status(), 'NONE') def test_getintentname(self): ''' 测试getIntentName方法 :return: ''' self.assertEqual(self.nlu.get_intent_name(), 'intentName') def test_getupdateintent(self): ''' 测试getUpdateIntent方法 :return: ''' updateIntent = { 'name': self.nlu.get_intent_name(), 'slots': self.data[0]['slots'] } self.assertEqual(self.updateIntent, updateIntent) def test_ask(self): ''' 测试ask方法 :return: ''' self.nlu.ask('location') directive = { 'type': 'Dialog.ElicitSlot', 'slotToElicit': 'location', 'updatedIntent': self.updateIntent } self.assertEqual(self.nlu.to_directive(), directive) def test_setslot(self): ''' 测试setSlot方法 :return: ''' self.nlu.set_slot('monthsalary', 1212) self.assertEqual(self.nlu.get_slot('monthsalary'), 1212) def test_setdelegate(self): ''' 测试setDelegate方法 :return: ''' self.nlu.set_delegate() directive = { 'type': 'Dialog.Delegate', 'updatedIntent': self.updateIntent } self.assertEqual(self.nlu.to_directive(), directive) def test_setconfirmslot(self): ''' 测试setConfirmSlot方法 :return: ''' self.nlu.set_confirm_slot('city') directive = { 'type': 'Dialog.ConfirmSlot', 'slotToConfirm': 'city', 'updatedIntent': self.updateIntent } self.assertEqual(self.nlu.to_directive(), directive) def testSetConfirmIntent(self): ''' 测试setConfirmIntent方法 :return: ''' self.nlu.set_confirm_intent() directive = { 'type': 'Dialog.ConfirmIntent', 'updatedIntent': self.updateIntent } self.assertEqual(self.nlu.to_directive(), directive) pass