class Music(object): # 标识是music领域 service = 'music' story_name = story_name.join_all stop_words = stop_words.join_all pronoun = pronoun.join_all can_words = modals.join_all adverb = adverb.join_all ask = honorific.join_all give = '(给)' want = '(要|想要|想|需要)' # 语义意图,仅支持一种,播放 listen = '(听|来)(一)?(首)?' sing = '(唱|播放|播|来|看|放|听)' # 音乐人名 artist = range_tag(4, 'artist') # 音乐名 music_name = range_tag(8, 'song') # 音乐的说法 music = '(音乐|儿歌|歌曲|歌)' # robot robot = '(你|机器人|小忆)' # me me = '(我|我们|咱|咱们|俺)' # 再,又 again = '(再|又|多)' # 首 an = e('((一)?(首|个))') # 你唱 you_sing = robot + sing # 听音乐 case_1 = me + e(want) + listen + e(you_sing) \ + o(an) + o(music, music_name) + e(stop_words) case_2 = me + e(want) + listen + e(you_sing) + e(artist) + e('的') + o(music, music_name) case_3 = sing + music_name # (给我)唱首xxx的歌 case_4 = e(give) + e(me) + sing + an + artist + '的歌' rule_1 = Rule(attach_perperty(case_1, {'operation': 'play', 'rule': 1})) rule_2 = Rule(attach_perperty(case_2, {'operation': 'play', 'rule': 2})) rule_3 = Rule(attach_perperty(case_3, {'operation': 'play', 'rule': 3})) rule_4 = Rule(attach_perperty(case_4, {'operation': 'play', 'rule': 4}))
class Music(object): # 标识是music领域 service = 'music' story_name = story_name.join_all stop_words = stop_words.join_all pronoun = pronoun.join_all can_words = modals.join_all adverb = adverb.join_all ask = honorific.join_all want = '(要|想要|想|需要)' # 语义意图,仅支持一种,播放 listen = '(听|来)(一)?(首)?' sing = '(唱|播放|播|来|看)(一)?(个|段|首)?' # 音乐人名 artist = range_tag(4, 'artist') # 音乐名 music_name = range_tag(8, 'song') # 音乐的说法 music = '(音乐|儿歌|歌曲|歌)' # robot robot = '(你|机器人|小忆)' # me me = '(我|我们|咱|咱们|俺)' # 再,又 again = '(再|又|多)' # 首 an = e('首|一首') # 你唱 you_sing = robot + sing # 听音乐 case_1 = e(me) + e(want) + e(again) + e(adverb) + listen + e(you_sing) \ + o(an) + o(music, story_name) + e(stop_words) case_2 = e(me) + e(want) + e(again) + e(adverb) + listen + e(you_sing) \ + e(artist) + e('的') + music_name case_3 = sing + music_name
class StoreLocation(object): # 标识是store_location领域 service = 'store_location' pronoun = pronoun.join_all modals = modals.join_all prep = prep.join_all degree = degree.join_all honorific = honorific.join_all interj = interj.join_all prefix_unsual = '(今天|现在)' auxiliary = auxiliary.join_all quantifier = quantifier.join_all numeral = numeral.join_all adjective = adjective.join_all adverb = adverb.join_all stop_words = stop_words.join_all vehicle = vehicle_name.join_all # 如果结尾使用非则会导致完全不匹配而失败 set_location_1_5 = range_tag(5, name='location', start=1) # 为了解决相近的(放|在|放在)问题使用非贪婪 object_1_5 = '(?P<object>(.)+?)' location_1_5 = '(?P<location>(.)+?)' set_prefix = '(小忆我告诉你)' query_prefix = '(小忆我问你)' put = '(放在|在)' keep = '((在)|(放)|(放在))' where = o('哪里', '什么地方', '什么位置') # 设置位置表达方式1: set_case1 = set_prefix + object_1_5 + put + set_location_1_5 rule_set_case1 = Rule( attach_perperty(set_case1, { 'operation': 'set', 'rule': 1 })) # 查询位置表达方式1: query_case1 = query_prefix + object_1_5 + keep + where + e(stop_words) rule_query_case1 = Rule( attach_perperty(query_case1, { 'operation': 'query', 'rule': 2 }))
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 }))
class Entertainment(object): # 标识是entertainment领域 service = 'entertainment' pronoun = pronoun.join_all modals = modals.join_all prep = prep.join_all degree = degree.join_all honorific = honorific.join_all interj = interj.join_all prefix_unsual = '(今天|现在)' auxiliary = auxiliary.join_all quantifier = quantifier.join_all numeral = numeral.join_all adjective = adjective.join_all adverb = adverb.join_all stop_words = stop_words.join_all prefix = o(pronoun, prep, modals, degree, honorific, interj, prefix_unsual) postfix = o(auxiliary, prep, pronoun) infix = o(prep, pronoun, degree) prefix_0_5 = r(prefix, 0, 5) postfix_0_3 = r(postfix, 0, 3) play = '(玩|玩儿|打开|启动)' game = '(的)?' + '(游戏|程序|软件)' name = range_tag(12, 'name') names_1 = '认知' names_1 = attach_perperty(names_1, {'id':1}) names_2 = '英语' names_2 = attach_perperty(names_2, {'id':2}) names = o(names_1, names_2) names = attach_name(names, 'name') study = '(学习)' # 游戏语义解析 game_case1 = prefix_0_5 + play + e(name) + e(study) + game + postfix_0_3 # 玩 [xxx] 游戏 rule_game_case1 = Rule(attach_perperty(r(game_case1, 1, 3), {'operation': 'start', 'rule': 1})) game_case2 = prefix_0_5 + play + names + e(study) + game + postfix_0_3 # 玩 认知 游戏 rule_game_case2 = Rule(attach_perperty(r(game_case2, 1, 3), {'operation': 'start', 'rule': 2})) game_case3 = names + game # 认知 游戏 rule_game_case3 = Rule(attach_perperty(r(game_case3, 1, 3), {'operation': 'start', 'rule': 3})) game_case4 = names + study # 英语 学习 rule_game_case4 = Rule(attach_perperty(r(game_case4, 1, 3), {'operation': 'start', 'rule': 4}))
class Story(object): # 标识是story领域 service = 'story' story_name = story_name.join_all stop_words = stop_words.join_all pronoun = pronoun.join_all can_words = modals.join_all adverb = adverb.join_all ask = honorific.join_all want = '(要|想要|想|需要)' # 语义意图,仅支持一种,播放 listen = '(听|看)(一)?(个)?' tell = '(讲|说|播|播放|来|看)(一)?(个|段)?' # 故事分类 story_type = '(童话|寓言|神话|传奇|成语|睡前|名人|益智|历史|民间|爱国|人物|动物|儿童小说|战争)' story_type = attach_name(story_type, 'genre') # 不故道名字的故事 unknow_story_name = range_tag(6, 'unknow_story_name') + "的" # 不能明确理解语义的限定词,统一归类到TAG tag = range_tag(12, 'tag') # 故事的感觉 sence = '(幽默|讽刺)' sence = attach_name(sence, 'sence') # 故事适合的听众 audience = '(儿童|3岁|4岁|5岁|6岁|7岁|8岁)' audience = attach_name(audience, 'audience') # 故事的说法,包含这些词的会被归类到故事语义 story = '(故事|寓言|童话)' # 直接说故事名称 title_case = o(listen, tell) + story_name + stop_words # robot robot = '(你|机器人|小忆)' # me me = '(我|我们|咱|咱们|俺)' # 再,又 again = '(再|又|多)' # 个 an = e('个|一个') # 你讲 you_say = robot + tell # 听故事 case_1 = e(me) + e(want) + e(again) + e(adverb) + listen + e(you_say) \ + o(story, story_name) + e(stop_words) case_2 = e(me) + e(want) + e(again) + e(adverb) + listen + e(you_say) \ + o(story_type, sence, audience, story_name) + e('的') + story + any_w case_3 = e(me) + e(want) + e(again) + e(adverb) + listen + e(you_say) \ + tag + e('的') + story_name + any_w # 故事我要听 case_4 = story_name + me + e(want) + listen # 我能请你给我讲故事 case_5 = e(me) + e(can_words) + e(ask) + e(robot) + e(adverb) + e('来') \ + e('给') + e(me) + e(again) + tell + an \ + o(story, story_name) + any_w case_6 = e(me) + e(can_words) + e(ask) + e(robot) + e(adverb) + e('来') \ + e('给') + e(me) + e(again) + tell + an \ + any_w + o(story_type, sence, audience, story_name, unknow_story_name) + e('的') \ + story + any_w # 你会讲小红帽的故事吗 case_8 = e(robot) + e(can_words) + e(adverb) + e('给') + e(me) + e(again) \ + tell + an + e(o(story_type, sence, audience, story_name, unknow_story_name)) \ + e('的') + story + any_w # 小红帽的故事你会讲吗 case_9 = story_name + e('的') + e(story) + e(robot) + e(can_words) + e( tell) + e(stop_words) # 小红帽的故事给我讲吧 case_10 = story_name + e('的') + e(story) + e(ask) + e('为|给') + e(me) \ + tell + e(stop_words) # 那讲个故事吧 case_11 = e(can_words) + e('请') + tell + '(个|一个)' \ + o(story_type, sence, audience, story_name) + any_w # 不好听 换个故事 case_12 = any_w + e(robot) + e(adverb) + '(换|变|再找)' \ + an + e(tag) + e(story_type) + e('的') + story + any_w rule_1 = Rule(attach_perperty(case_1, {'operation': 'play', 'rule': 1})) rule_2 = Rule(attach_perperty(case_2, {'operation': 'play', 'rule': 2})) rule_3 = Rule(attach_perperty(case_3, {'operation': 'play', 'rule': 3})) rule_4 = Rule(attach_perperty(case_4, {'operation': 'play', 'rule': 4})) rule_5 = Rule(attach_perperty(case_5, {'operation': 'play', 'rule': 5})) rule_6 = Rule(attach_perperty(case_6, {'operation': 'play', 'rule': 6})) rule_8 = Rule(attach_perperty(case_8, {'operation': 'play', 'rule': 8})) rule_9 = Rule(attach_perperty(case_9, {'operation': 'play', 'rule': 9})) rule_10 = Rule(attach_perperty(case_10, {'operation': 'play', 'rule': 10})) rule_11 = Rule(attach_perperty(case_11, {'operation': 'play', 'rule': 11})) rule_12 = Rule(attach_perperty(case_12, {'operation': 'play', 'rule': 12}))
class Profile(object): # 标识是profile领域 service = 'profile' pronoun = pronoun.join_all stop_words = stop_words.join_all modals = modals.join_all me = '(我|俺|咱)' me = attach_perperty(me, {'subject': 'user'}) your = '(你)' your = attach_perperty(your, {'subject': 'robot'}) person = o(me, your) ti_ch_0_3 = range_tag(3, start=0) what = '(什么|几|多少|啥)' what_name = '(什么|啥)' know = '(知道|清楚|明白|了解|知不知道|知道不知道|搞清楚|看|说)' name = '(名字|名称|名|称呼)' name = attach_perperty(name, {'attribute': 'name'}) age = '(年级|年龄|岁)' age = attach_perperty(age, {'attribute': 'age'}) man = '(男|男生|男人|帅哥|男同学)' man = attach_perperty(man, {'gender': 1}) woman = '(女|女生|女人|美女|女同学)' woman = attach_perperty(woman, {'gender': 2}) gender = o(man, woman) strange_relation = range_tag(4) strange_relation = attach_name(strange_relation, 'relationDesc') strange_relation = attach_perperty(strange_relation, {'relationid': 99, 'closeReletive': 'no'}) relationid_0 = '(小){0,1}主人' relationid_0 = attach_perperty(relationid_0, {'relationid': 0, 'closeReletive': 'yes'}) relationid_1 = '(爸爸|老豆|老爸)' relationid_1 = attach_perperty(relationid_1, {'relationid': 1, 'closeReletive': 'yes'}) relationid_2 = '(妈妈|老妈|妈)' relationid_2 = attach_perperty(relationid_2, {'relationid': 2, 'closeReletive': 'yes'}) relationid_3 = '(爷爷|祖父)' relationid_3 = attach_perperty(relationid_3, {'relationid': 3, 'closeReletive': 'yes'}) relationid_4 = '(奶奶|祖母)' relationid_4 = attach_perperty(relationid_4, {'relationid': 4, 'closeReletive': 'yes'}) relationid_5 = '(姥姥|外婆|外祖母)' relationid_5 = attach_perperty(relationid_5, {'relationid': 5, 'closeReletive': 'yes'}) relationid_6 = '(姥爷|外公|外祖父)' relationid_6 = attach_perperty(relationid_6, {'relationid': 6, 'closeReletive': 'yes'}) relationid_7 = '(哥哥|哥)' relationid_7 = attach_perperty(relationid_7, {'relationid': 7, 'closeReletive': 'yes'}) relationid_8 = '(弟弟|弟)' relationid_8 = attach_perperty(relationid_8, {'relationid': 8, 'closeReletive': 'yes'}) relationid_9 = '(姐姐|姐)' relationid_9 = attach_perperty(relationid_9, {'relationid': 9, 'closeReletive': 'yes'}) relationid_10 = '(妹妹|妹)' relationid_10 = attach_perperty(relationid_10, {'relationid': 10, 'closeReletive': 'yes'}) relationid_11 = '(伯伯|叔叔)' relationid_11 = attach_perperty(relationid_11, {'relationid': 11, 'closeReletive': 'no'}) relationid_12 = '(伯母|婶婶)' relationid_12 = attach_perperty(relationid_12, {'relationid': 12, 'closeReletive': 'no'}) relationid_13 = '(姑姑)' relationid_13 = attach_perperty(relationid_13, {'relationid': 13, 'closeReletive': 'no'}) relationid_14 = '(姑父|姑丈)' relationid_14 = attach_perperty(relationid_14, {'relationid': 14, 'closeReletive': 'no'}) relationid_15 = '(舅舅|舅公)' relationid_15 = attach_perperty(relationid_15, {'relationid': 15, 'closeReletive': 'no'}) relationid_16 = '(舅妈|舅母)' relationid_16 = attach_perperty(relationid_16, {'relationid': 16, 'closeReletive': 'no'}) relationid_17 = '(姨姨|姨|姨妈)' relationid_17 = attach_perperty(relationid_17, {'relationid': 17, 'closeReletive': 'no'}) relationid_18 = '(姨夫|姨丈)' relationid_18 = attach_perperty(relationid_18, {'relationid': 18, 'closeReletive': 'no'}) relationid_19 = '(堂哥|堂弟|表哥|表弟)' relationid_19 = attach_perperty(relationid_19, {'relationid': 19, 'closeReletive': 'no'}) relationid_20 = '(堂姐|堂妹|表姐|表妹)' relationid_20 = attach_perperty(relationid_20, {'relationid': 20, 'closeReletive': 'no'}) relation = o(relationid_0, relationid_1, relationid_2, relationid_3, relationid_4, relationid_5, relationid_6, relationid_7, relationid_8, relationid_9, relationid_10, relationid_11, relationid_11, relationid_12, relationid_13, relationid_14, relationid_15, relationid_16, relationid_17, relationid_18, relationid_19, relationid_20) relation = attach_name(relation, 'relationDesc') master = '(小主人|他|你)' slave = '(你|机器人|小忆)' real_name = range_tag(3, 'name') real_age = range_not_tag(2, what, 'age') # 我叫什么名字 query_name1 = person + '(叫)' + what + name query_name1 = attach_perperty(query_name1, {'attribute': 'name', 'rule': 'queryName1'}) # 我几岁 query_age1 = person + '(今年|现在)?' + what + '岁' query_age1 = attach_perperty(query_age1, {'attribute': 'age', 'rule': 'queryName1'}) # 你知道我的名字吗 query_name2 = ti_ch_0_3 + slave + ti_ch_0_3 + know + person + ti_ch_0_3 + name + e(stop_words) query_name2 = attach_perperty(query_name2, {'attribute': 'name', 'rule': 'queryName2'}) # 你知道我叫什么吗 query_name3 = ti_ch_0_3 + slave + ti_ch_0_3 + know + person + ti_ch_0_3 + '叫' + what_name + e(name) + e(stop_words) query_name3 = attach_perperty(query_name3, {'attribute': 'name', 'rule': 'queryName3'}) # 你几岁 query_age2 = ti_ch_0_3 + slave + ti_ch_0_3 + what + age + e(stop_words) query_age2 = attach_perperty(query_age2, {'rule': 'query_age2'}) # 你多大 query_age3 = ti_ch_0_3 + person + ti_ch_0_3 + '(多大)' + e('(年龄|年纪)') + e(stop_words) query_age3 = attach_perperty(query_age3, {'rule': 'query_age3'}) # 你看我多大了 query_age4 = ti_ch_0_3 + slave + know + person + '(多大)' + e('(年龄|年纪)') + e(stop_words) query_age4 = attach_perperty(query_age4, {'rule': 'query_age4'}) # 你知道我是谁吗(我是谁) query_relation1 = ti_ch_0_3 + e(slave) + e(know) + person + ti_ch_0_3 + '(谁)' + e(stop_words) query_relation1 = attach_perperty(query_relation1, {'attribute': 'relation', 'rule': 'queryRelation1'}) # 你知道我的性别? query_gender1 = ti_ch_0_3 + slave + ti_ch_0_3 + know + person + ti_ch_0_3 + '(性别|男女|是男是女|男的女的)' + e(stop_words) query_gender1 = attach_perperty(query_gender1, {'attribute': 'gender', 'rule': 'queryGender1'}) # 我是男是女? query_gender2 = ti_ch_0_3 + person + ti_ch_0_3 + '(性别|男女|是男是女)' + e(stop_words) query_gender2 = attach_perperty(query_gender2, {'attribute': 'gender', 'rule': 'queryGender2'}) get = o(query_name1, query_name2, query_name3, query_age1, query_age2, query_age3, query_age4, query_relation1, query_gender1, query_gender2) rule_get = Rule(attach_perperty(get, {'operation': 'get'})) # 我叫XX answer_name = ti_ch_0_3 + person + ti_ch_0_3 + "(叫)" + real_name answer_name = attach_perperty(answer_name, {'rule': 'answerName'}) # 我XX岁 answer_age = ti_ch_0_3 + person + e('(今年|现在)') + real_age + '岁' + e(stop_words) # answer_age = ti_ch_0_3 + person + e('(今年|现在)') + real_age + '岁' + e(stop_words) answer_age = attach_perperty(answer_age, {'rule': 'answerAge'}) # 我是男/女的 answer_gender = ti_ch_0_3 + person + '(是|就是)' + gender + e(stop_words) answer_gender = attach_perperty(answer_gender, {'rule': 'answerGender'}) # 我是小主人的xx answer_relation_1 = ti_ch_0_3 + person + '(是|就是)' + master + '(的)' + relation + e(stop_words) answer_relation_1 = attach_perperty(answer_relation_1, {'rule': 'answerRelation1'}) # 我是小主人/爸爸 answer_relation_2 = ti_ch_0_3 + person + '(是|就是)' + relation answer_relation_2 = attach_perperty(answer_relation_2, {'rule': 'answerRelation2'}) # 我是小主人的三爷爷 answer_relation_3 = ti_ch_0_3 + person + '(就是|是)' + e('你|小忆|机器人|小主人') + e('的') + strange_relation answer_relation_3 = attach_perperty(answer_relation_3, {'rule': 'answerRelation3'}) rule_strange_relation = Rule(attach_perperty(answer_relation_3, {'operation': 'answer'})) answer = o(answer_name, answer_age, answer_gender, answer_relation_1, answer_relation_2) rule_answer = Rule(attach_perperty(answer, {'operation': 'answer'}))
adjective = adjective.join_all adverb = adverb.join_all stop_words = stop_words.join_all want = '(要|想要|想|需要)' prefix = o(pronoun, prep, modals, degree, honorific, interj, prefix_unsual) postfix = o(auxiliary, prep, pronoun) infix = o(prep, pronoun, degree) prefix_0_5 = r(prefix, 0, 5) prefix_0_3 = r(prefix, 0, 3) postfix_0_3 = r(postfix, 0, 3) # 位置 bedroom = attach_perperty('(卧室|卧房|睡房)', {'position': 'bedroom'}) main_bedroom = attach_perperty('(主卧)', {'position': 'main_bedroom'}) second_bedroom = attach_perperty('(次卧)', {'position': 'second_bedroom'}) living_room = attach_perperty('(客厅)', {'position': 'living_room'}) kitchen = attach_perperty('(厨房)', {'position': 'kitchen'}) dining_room = attach_perperty('(餐厅)', {'position': 'dining_room'}) bath_room = attach_perperty('(卫生间)', {'position': 'bath_room'}) position = o(bedroom, main_bedroom, second_bedroom, living_room, kitchen, dining_room, bath_room) + e('的') # 动作特征词 turn_on = attach_perperty('开|打开', {'operation': 'turn_on'}) turn_off = attach_perperty('(关上|关闭|关下|关一下|关掉|关)', {'operation': 'turn_off'}) turn_up = attach_perperty('(调高|升高|升起来)', {'operation': 'turn_up'}) turn_down = attach_perperty('(调低|降低|降下来)', {'operation': 'turn_down'}) desc = range_tag(6, 'desc')
stop_words = stop_words.join_all want = '(要|想要|想|需要)' prefix = o(pronoun, prep, modals, degree, honorific, interj, prefix_unsual) postfix = o(auxiliary, prep, pronoun) infix = o(prep, pronoun, degree) prefix_0_5 = r(prefix, 0, 5) postfix_0_3 = r(postfix, 0, 3) # 语义意图,仅支持一种,播放 see = '(听|看)' + e('一') + e('个') tell = '(讲|说|播放|播|来|看|打开)' + e('一') + e('个|段') # 不能明确理解语义的限定词,统一归类到TAG tag = range_tag(12, 'tag') # robot robot = '(你|机器人|小忆)' # me me = '(我|我们|咱|咱们|俺)' # 再,又 again = '(再|又|多)' # ask ask = '(请|让|叫|要|要求|麻烦)' # give give = '(给|对|帮忙|帮助|帮|为)'
class Vehicle(object): # 标识是vehicle领域 service = 'vehicle' pronoun = pronoun.join_all modals = modals.join_all prep = prep.join_all degree = degree.join_all honorific = honorific.join_all interj = interj.join_all prefix_unsual = '(今天|现在)' auxiliary = auxiliary.join_all quantifier = quantifier.join_all numeral = numeral.join_all adjective = adjective.join_all adverb = adverb.join_all stop_words = stop_words.join_all vehicle = vehicle_name.join_all ti_ch_0_3 = range_tag(3, start=0) show = '(样子|形状|外表|图片)' what = '(什么|哪种|怎么|啥)' append = '(加|增加|添加|加上|补充|再|再来|再加|再次|再一次|继续|接着)' append = attach_perperty(append, {'operation': 'append'}) # me me = '(我|我们|咱|咱们|俺)' # ask ask = '(请|让|要|要求|麻烦)' # 再,又 again = '(再|又|多)' # robot robot = '(你|机器人|小忆)' want = '(要|想|想要|需要|能)' look = '(放|来|看|给)' + e('一') + e('个|辆') look = attach_perperty(look, {'operation': 'name'}) # 消防车是什么样子的 case1 = ti_ch_0_3 + vehicle + ti_ch_0_3 + what + show + e(stop_words) rule_case1 = Rule(attach_perperty(case1, {'operation': 'name', 'rule': 1})) # 我能请你给我看下自行车 case2 = e(me) + e(want) + e(again) + e('请') + e(robot) + e(look) + e( me) + e(adverb) + look + e('下') + vehicle + e(stop_words) rule_case2 = Rule(attach_perperty(case2, { 'operation': 'query', 'rule': 2 })) # 小忆我要自行车 case3 = e(robot) + me + e(want) + e(look) + vehicle + e(stop_words) rule_case3 = Rule(attach_perperty(case3, { 'operation': 'query', 'rule': 3 })) # 消防车是干什么的 case4 = ti_ch_0_3 + vehicle + '(是)' + ti_ch_0_3 + what + ti_ch_0_3 + '(用)?' + ti_ch_0_3 rule_case4 = Rule(attach_perperty(case4, { 'operation': 'query', 'rule': 4 })) # 自行车 case5 = vehicle + e('我要看') + e(stop_words) rule_case5 = Rule(attach_perperty(case5, { 'operation': 'query', 'rule': 5 })) # 小忆你有没有自行车 case6 = e(robot) + e('你') + '(有没有)' + vehicle + e('我') + e('要') + e( '看') + e(stop_words) rule_case6 = Rule(attach_perperty(case6, { 'operation': 'query', 'rule': 6 })) # 再加一辆自行车 case7 = ti_ch_0_3 + append + ti_ch_0_3 + quantifier + vehicle + ti_ch_0_3 rule_case7 = Rule( attach_perperty(case7, { 'operation': 'append', 'rule': 7 }))
class Animal(object): # 标识是animal领域 service = 'animal' animal = animal_name.join_all pronoun = pronoun.join_all stop_words = stop_words.join_all modals = modals.join_all want = '(要|想|想要)' query1 = '(查|查询|看|显示)(一下)?' query2 = '(长|什么)' query3 = '(样|外表|形状)' query4 = '(显示|找|搜索|学习|展览|展示|展出|放|表演|播|陈现|陈放|放映|给|出|画|拿)(一下)?' roar = '(叫|叫声)' append = '(加|增加|添加|加上)' how = '(如何|怎么)' call = '(是|叫)' animal_type = '(虫|鸟)' animal_type = attach_name(animal_type, 'type') all_animal = o(animal, animal_type) # 老虎(进入动物场景后,说动物名才起作用) case_1 = attach_perperty(all_animal, {'operation': 'query', 'rule': 1}) rule_1 = Rule(case_1, {'status': 'animal'}) # 老虎长什么样 case_2 = all_animal + any_w + '({})?'.format( query2) + any_w + query3 + any_w case_2 = attach_perperty(case_2, {'operation': 'query', 'rule': 2}) rule_2 = Rule(case_2) # 我现在想要看虫 case_3 = e(pronoun) + e( stop_words) + want + any_w + query1 + any_w + animal_type + any_w case_3 = attach_perperty(case_3, {'operation': 'query', 'rule': 3}) rule_3 = Rule(case_3) # 给我显示个大老虎看看 case_4 = e(modals) + e(pronoun) + query4 + any_w + all_animal + stop_words case_4 = attach_perperty(case_4, {'operation': 'query', 'rule': 4}) rule_4 = Rule(case_4) # 我要个大老虎看看 case_5 = pronoun + want + any_w + all_animal + any_w case_5 = attach_perperty(case_5, {'operation': 'query', 'rule': 5}) rule_5 = Rule(case_5) # 什么是老虎 case_6 = query2 + call + all_animal case_6 = attach_perperty(case_6, {'operation': 'query', 'rule': 6}) rule_6 = Rule(case_6) # 老虎怎么叫 case_7 = any_w + all_animal + any_w + how + roar + any_w case_7 = attach_perperty(case_7, {'operation': 'roar', 'rule': 7}) rule_7 = Rule(case_7) # 再加一只老虎 tag = range_tag(2, 'tag') case_8 = e(pronoun) + e(stop_words) + append + tag + all_animal + e( stop_words) case_8 = attach_perperty(case_8, {'operation': 'append', 'rule': 8}) rule_8 = Rule(case_8 + "{1,3}")