Ejemplo n.º 1
0
    def semantic_info(self, robot_code, speech):
        """
        取得普通的语义信息
        :param robot_code: 机器码
        :param speech: 对话
        :return:
        """
        match_dict_list = Nlu_Framework.match(force_utf8_new(speech))
        logging.warn(match_dict_list)
        if not match_dict_list:
            current_status = RobotStatus.get_robot_status(robot_code)
            logging.warn(current_status)
            match_dict_list = Nlu_Framework.match(force_utf8_new(speech),
                                                  {'status': current_status})
            logging.warn(match_dict_list)

        assert len(match_dict_list) <= 1, 'match_dict_list len great than 1'

        # 没命中语义,走其它逻辑
        if not match_dict_list:
            return None

        # 语义信息
        match_info = match_dict_list[0]

        self._update_robot_status(robot_code, match_info['service'])
        return match_info
Ejemplo n.º 2
0
 def test_yaml(self):
     # self._generage()
     file_list = glob.glob('./test/conf/*')
     for file_name in file_list:
         print 'test' + file_name
         yaml_info_list = load_from_yaml(file_name)
         for yaml_info in yaml_info_list:
             match_dict_list = Nlu_Framework.match(force_utf8_new(yaml_info['input']))
             self.assertDictEqual(force_utf8_new(match_dict_list[0]),
                                  force_utf8_new(yaml_info['output']))
Ejemplo n.º 3
0
 def _generage(self):
     """
     第一次产生测试yaml的方法
     :return:
     """
     file_list = glob.glob('./test/conf/*')
     for file_name in file_list:
         yaml_info_list = load_from_yaml(file_name)
         print file_name
         yaml_list = []
         for yaml_info in yaml_info_list:
             match_dict_list = Nlu_Framework.match(force_utf8_new(yaml_info['input']))
             result_dict = {"input": force_utf8_new(yaml_info['input']),
                            "output": match_dict_list[0]}
             yaml_list.append(result_dict)
         yaml_list = force_utf8_new(yaml_list)
         print yaml.safe_dump_all(yaml_list, allow_unicode=True, encoding='utf-8')
Ejemplo n.º 4
0
# import yaml
# # list1 = []
# # for test_sentence in test_list:
# #     match_dict_list = Nlu_Framework.match(test_sentence)
# #     # print str(test_sentence)
# #     dict1 = {"input": test_sentence,
# #              "output": match_dict_list[0]}
# #     list1.append(dict1)
# #     # print force_utf8_new(match_dict_list[0])
# #
# #
# # list1 = force_utf8_new(list1)
# #
# # print yaml.safe_dump_all(list1, allow_unicode=True, encoding='utf-8')
# f = open('./test/test.yaml')
# input = yaml.safe_load_all(f)
# for i in input:
#     print force_utf8_new(i)

# print 'start'
# a = time.time()
# for i in range(1000):
match_dict_list = Nlu_Framework.match('我要听刘德华的冰雨')
print match_dict_list
# b = time.time()
# print a - b
# print match_dict_list

# a = re.match('(小忆我问你)(?P<object>(.)+?)(放在|在)(哪里|什么地方|什么位置)', '小忆我问你手机放在哪里').groups()
# for i in a:
#     print i
Ejemplo n.º 5
0
"""
# test_rule.py
from nlu.nlu_framework import Nlu_Framework
from nlu.rule import Rule
from utils.utils import range_tag, attach_perperty


class Test(object):
    # 标识是test领域(这个service字段必须存在,命中本类中正则时,会输出这个字段)
    service = 'test'
    # 表示抓取2个字长度的信息,输出字段为name
    name = range_tag(2, 'user_name')

    # 正则规则:我的名字是小明
    name_case1 = '我的名字是' + name

    # 生成规则对象
    rule_case1 = Rule(
        attach_perperty(name_case1, {
            'operation': 'query',
            'rule': 1
        }))


Nlu_Framework.register(Test)

match_dict_list = Nlu_Framework.match('我的名字是小明')

for k, v in match_dict_list[0].items():
    print '{} : {}'.format(k, v)
Ejemplo n.º 6
0
#
#
#
#
# import yaml
# # list1 = []
# # for test_sentence in test_list:
# #     match_dict_list = Nlu_Framework.match(test_sentence)
# #     # print str(test_sentence)
# #     dict1 = {"input": test_sentence,
# #              "output": match_dict_list[0]}
# #     list1.append(dict1)
# #     # print force_utf8_new(match_dict_list[0])
# #
# #
# # list1 = force_utf8_new(list1)
# #
# # print yaml.safe_dump_all(list1, allow_unicode=True, encoding='utf-8')
# f = open('./test/test.yaml')
# input = yaml.safe_load_all(f)
# for i in input:
#     print force_utf8_new(i)

# print 'start'
# a = time.time()
# for i in range(1000):
match_dict_list = Nlu_Framework.match('来个脑筋急转弯')
# b = time.time()
# print a - b
print match_dict_list