class Battery(object): # 标识是battery领域 service = 'battery' 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 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) query = '(查|查询|告诉我)(下)?' howmuch = '(多少|百分之多少|百分之几|几个|几格)' left = '(还)?(剩|剩余|剩下|有)' + e(howmuch) power = '(的)?(电量|电|电池)' # [剩余电量]语义解析:电量/查电量/告诉我电量/还剩多少电量/电量剩多少 battery_case1 = prefix_0_5 + e( query) + left + power + postfix_0_3 # [查询] 剩余 电量 battery_case2 = prefix_0_5 + e( query) + power + left + postfix_0_3 # [查询] 电量 剩余 battery_case3 = e(query) + power # 电量 battery_sentence = o(battery_case1, battery_case2, battery_case3) rule_battery_sentence = Rule( attach_perperty(r(battery_sentence, 1, 3), { 'operation': 'get', '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 ExtendInstruction(object): service = 'extend_instruction' 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 prefix = o(pronoun, prep, modals, degree, honorific, interj, prefix_unsual) postfix = o(auxiliary, prep, pronoun) infix = o(prep, pronoun, degree) # 被中止的指令 play = '(播放|播|说话|说|唱歌|唱|歌唱|讲故事|讲|听歌|听故事|听|跳舞|跳)' # 中止特征词 do_not = '(不要|不|不想|不准|不想要|别)' stop = '(停一停|停一下|停止|暂停|停下|停|打住|闭嘴|安静|打断|shut up|stop)' get = '(知道|明白|理解|了解)' prefix_0_5 = r(prefix, 0, 5) postfix_0_3 = r(postfix, 0, 3) # 中止语义解析 # 请你不要播放了;别说了; stop_case1 = prefix_0_5 + do_not + e(degree) + play + postfix_0_3 # 请你不要播放了;别说了; stop_case2 = prefix_0_5 + stop + play + postfix_0_3 # 麻烦你停一下好吗;停停停;停啊停啊停啊 stop_case3 = prefix_0_5 + o(stop, get) + postfix_0_3 stop_sentence = r(o(stop_case1, stop_case2, stop_case3), 1, 3) rule_stop_sentence = Rule( attach_perperty(stop_sentence, { 'operation': 'stop', 'rule': 1 })) # 是语义解析:绝对正确啊;相当可以啊;挺好;对对对; yes = '(对|好|可以|行|正确|那还用说)' yes_case1 = e(adjective) + yes + r(auxiliary, 0, 3) yes_sentence = r(yes_case1, 1, 3) rule_yes_sentence = Rule( attach_perperty(yes_sentence, { 'operation': 'yes', 'rule': 2 })) # 不是语义解析:完全不对;不太行;不是很对啊;不行不行; not_str = '(不是|不|没|没有)' no_case1 = not_str + yes no_case2 = prefix_0_5 + not_str + e(degree) + yes + postfix_0_3 no_sentence = r(o(no_case1, no_case2), 1, 3) rule_no_sentence = Rule( attach_perperty(no_sentence, { 'operation': 'no', 'rule': 3 })) # [不告诉你]语义解析:我不告诉你;不想告诉你;就不告诉你; tell_not = e(adverb) + "(不想|不)" tell = "(告诉)" wont_tell_case1 = prefix_0_5 + tell_not + e(degree) + tell + e( pronoun) + postfix_0_3 rule_wont_tell_sentence = Rule( attach_perperty(wont_tell_case1, { 'operation': 'wonttell', 'rule': 4 }))
class XiaoYi(object): # 标识是xiaoyi领域 service = 'xiaoyi' 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 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) show = '(显示|打开|亮出|查|查询)(下)?' your = '(你|机器|机器人|小忆)(的)?' # [二维码]语义解析 barcode = '(二维码|身份证)' barcode_case1 = barcode barcode_case2 = prefix_0_5 + show + e( your) + barcode + postfix_0_3 # 显示 二维码 barcode_case3 = prefix_0_5 + your + barcode + postfix_0_3 # 机器人 二维码 barcode_sentence = o(barcode_case1, barcode_case2, barcode_case3) rule_barcode_sentence = Rule( attach_perperty(barcode_sentence, { 'attribute': 'barcode', 'operation': 'get', 'rule': 1 })) # [软件版本]语义解析 version = '(软件)?(版本)(号|信息)?' version_case1 = version version_case2 = prefix_0_5 + show + e( your) + version + postfix_0_3 # 显示 版本号 version_case3 = prefix_0_5 + your + version + postfix_0_3 # 机器人 版本号 version_sentence = o(version_case1, version_case2, version_case3) rule_version_sentence = Rule( attach_perperty(version_sentence, { 'attribute': 'version', 'operation': 'get', 'rule': 2 })) # [绑定状态]语义解析 bind = '(绑定状态)' bind_case1 = bind bind_case2 = prefix_0_5 + show + e(your) + bind + postfix_0_3 # 显示 绑定状态 bind_case3 = prefix_0_5 + your + bind + postfix_0_3 # 机器人 绑定状态 bind_sentence = o(bind_case1, bind_case2, bind_case3) rule_bind_sentence = Rule( attach_perperty(bind_sentence, { 'attribute': 'bind', 'operation': 'get', 'rule': 3 })) # [网络状态]语义解析 wifi = '(网络状态)' wifi_case1 = wifi # 网络状态 wifi_case2 = prefix_0_5 + show + e(your) + wifi + postfix_0_3 # 显示 网络状态 wifi_case3 = prefix_0_5 + your + wifi + postfix_0_3 # 机器人 网络状态 wifi_sentence = o(wifi_case1, wifi_case2, wifi_case3) rule_wifi_sentence = Rule( attach_perperty(wifi_sentence, { 'attribute': 'wifi', 'operation': 'get', 'rule': 4 }))
class Photo(object): # 标识是photo领域 service = 'photo' 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 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_5 = r(postfix, 0, 5) # 拍特征词 take = '(拍|照|合|来)' # 照片特征词 photo = '(照|照片|相|相片|像|像片|影|合影)' # 打开特征词 open = '(打开|开启|启动)' # 相机特征词 camera = '(相机|照相机|摄像头)' # 不好写规则的特征表达 take_photo = photo + photo # 拍照语义解析 photo_case1 = prefix_0_5 + take + photo + postfix_0_5 # 拍照 rule_photo_case1 = Rule( attach_perperty(r(photo_case1, 1, 3), { 'operation': 'take', 'rule': 1 })) photo_case2 = prefix_0_5 + '(把|将)?' + photo + take + postfix_0_5 # 照 拍 rule_photo_case2 = Rule( attach_perperty(r(photo_case2, 1, 3), { 'operation': 'take', 'rule': 2 })) photo_case3 = prefix_0_5 + '(把|将)?' + photo + take + any_w + quantifier + postfix_0_5 # 拍 照; rule_photo_case3 = Rule( attach_perperty(r(photo_case3, 1, 3), { 'operation': 'take', 'rule': 3 })) photo_case4 = prefix_0_5 + take + any_w + quantifier + photo + postfix_0_5 # 拍 张 照; rule_photo_case4 = Rule( attach_perperty(r(photo_case4, 1, 3), { 'operation': 'take', 'rule': 4 })) photo_case5 = prefix_0_5 + '(拍|照)' + '(我|我们)' + postfix_0_5 # 拍我 rule_photo_case5 = Rule( attach_perperty(r(photo_case5, 1, 3), { 'operation': 'take', 'rule': 5 })) photo_case6 = prefix_0_5 + open + camera + postfix_0_5 # 打开 相机 rule_photo_case6 = Rule( attach_perperty(r(photo_case6, 1, 3), { 'operation': 'take', 'rule': 6 })) photo_case7 = prefix_0_5 + '(把|将)?' + camera + open + postfix_0_5 # 相机 打开 rule_photo_case7 = Rule( attach_perperty(r(photo_case7, 1, 3), { 'operation': 'take', 'rule': 7 }))
class Volume(object): # 标识是volume领域 service = 'volume' 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 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) # 调整特征词 # $change_up{direction%up} = (增 | 加 | 升 | 扩)[$numeral_words] [$quantifier_words]; change_up = '(增|加|升|扩)' + e(numeral) + e(quantifier) change_up = attach_perperty(change_up, {'direction': "up"}) # $change_down{direction%down} = (减 | 降 | 缩)[$numeral_words] [$quantifier_words]; change_down = '(减|降|缩)' + e(numeral) + e(quantifier) change_down = attach_perperty(change_down, {'direction': "down"}) # $change = (调 | 调整 | 调节 | 调动 | 调理 | 调弄 | 改变 | 转变 | 弄 | 搞 | 放 | 变 | 整); change = '(调|调整|调节|调动|调理|调弄|改变|转变|弄|搞|放|变|整)' # 方向 # $up{direction%up} = (大 | 高 | 强 | 重 | 响 | 响亮)[$numeral_words] [$quantifier_words]; up = '(大|高|强|重|响|响亮)' + e(numeral) + e(quantifier) up = attach_perperty(up, {'direction': "up"}) # $down{direction%down} = (小 | 低 | 弱 | 轻 | 低沉)[$numeral_words] [$quantifier_words]; down = '(小|低|弱|轻|低沉)' + e(numeral) + e(quantifier) down = attach_perperty(down, {'direction': "down"}) # $maximum{direction%up}{step%toend} = [(到 | 至)](最大 | 最高 | 最强 | 最重 | 最响 | 最亮); maximum = e('到|至') + '(最大|最高|最强|最重|最响|最亮)' maximum = attach_perperty(maximum, {'direction': "up", 'step': "toend"}) # $minimum{direction%down}{step%toend} = [(到 | 至)](最小 | 最低 | 最弱 | 最轻); minimum = e('到|至') + '(最小|最低|最弱|最轻)' minimum = attach_perperty(minimum, {'direction': "down", 'step': "toend"}) # $direction = ($up | $down | $maximum | $minimum); direction = o(up, down, maximum, minimum) # 反转的方向,用于双重否定的场景 # $reverse_up{direction%down} = (大 | 高 | 强 | 重 | 响 | 响亮)[$numeral_words] [$quantifier_words]; reverse_up = '(大|高|强|重|响|响亮)' + e(numeral) + e(quantifier) reverse_up = attach_perperty(reverse_up, {'direction': "down"}) # $reverse_down{direction%up} = (小 | 低 | 弱 | 轻 | 低沉)[$numeral_words] [$quantifier_words]; reverse_down = '(小|低|弱|轻|低沉)' + e(numeral) + e(quantifier) reverse_down = attach_perperty(reverse_down, {'direction': "up"}) # $reverse_maximum{direction%down}{step%toend} = [(到 | 至)](最大 | 最高 | 最强 | 最重 | 最响 | 最亮); reverse_maximum = e('(到|至)') + '(最大|最高|最强|最重|最响|最亮)' reverse_maximum = attach_perperty(reverse_maximum, { 'direction': "down", 'step': "toend" }) # $reverse_minimum{direction%up}{step%toend} = [(到 | 至)](最小 | 最低 | 最弱 | 最轻); reverse_minimum = e('(到|至)') + '(最小|最低|最弱|最轻)' reverse_minimum = attach_perperty(reverse_minimum, { 'direction': "up", 'step': "toend" }) # $reverse_direction = ($reverse_up | $reverse_down | $reverse_maximum | $reverse_minimum); reverse_direction = o(reverse_up, reverse_down, reverse_maximum, reverse_minimum) # $change_case1 = ($change_up | $change_down) [$direction]; change_case1 = o(change_up, change_down) + e(direction) # $change_case2 = [$change] [$degree_words] $direction; change_case2 = e(change) + e(degree) + direction # $change_case3 = (往|向|朝) [$degree_words] $direction [$change]; change_case3 = '(往|向|朝)' + e(degree) + direction + e(change) # $change_direction = ($change_case1 | $change_case2 | $change_case3); change_direction = o(change_case1, change_case2, change_case3) # 音量调节特征词 # $volume = (把|将)<0-1> [你的] (声音 | 声 | 声儿 | 音量 | 音响 | 喇叭 | 喇叭声 | 说话力气)[$numeral_words] [$quantifier_words]; volume = r('(把|将)', 0, 1) + e('你的') + '(声音|声儿|声|音量|音响|喇叭|喇叭声|说话力气)' + e( numeral) + e(quantifier) # 表达方式1:大点声;小声点好吗; # $volume_case1 = $prefix<0-5> $change_direction $volume $postfix<0-3>; volume_case1 = prefix_0_5 + change_direction + volume + postfix_0_3 rule_volume_case1 = Rule( attach_perperty(volume_case1, { 'operation': 'change', 'rule': '1' })) # 表达方式2:声音再调大点;请你把声音调到最小可以吗;把声音调整更大一点; # $volume_case2 = $prefix<0-5> $volume [$infix] $change_direction $postfix<0-3>; volume_case2 = prefix_0_5 + volume + e( infix) + change_direction + postfix_0_3 rule_volume_case2 = Rule( attach_perperty(volume_case2, { 'operation': 'change', 'rule': '2' })) # 表达方式3:别那么大声; # $do_not = (不 | 不要 | 不想 | 不准 | 不想要 | 别); do_not = '(不要|不想|不准|不想要|不|别)' # $volume_case3 = $prefix<0-5> $do_not [$degree_words] $reverse_direction [$infix] $volume $postfix<0-3>; volume_case3 = prefix_0_5 + do_not + e(degree) + reverse_direction + e( infix) + volume + postfix_0_3 rule_case3 = Rule( attach_perperty(volume_case3, { 'operation': 'change', 'rule': 3 })) # 表达方式4-9:那么大声干嘛;声音这么大干啥;干啥这么大声; # $why = (干嘛 | 干吗 | 干啥 |干什么 | 做什么 | 怎么 | 怎的 | 咋 | 为啥 | 为什么); why = '(干嘛|干吗|干啥|干什么|做什么|怎么|怎的|咋|为啥|为什么)' # $volume_case4 = $prefix<0-5> $why [$infix] $reverse_direction [$infix] $volume $postfix<0-3>; volume_case4 = prefix_0_5 + why + e(infix) + reverse_direction + e( infix) + volume + postfix_0_3 rule_case4 = Rule( attach_perperty(volume_case4, { 'operation': 'change', 'rule': 4 })) # $volume_case5 = $prefix<0-5> $why [$infix] $volume [$infix] $reverse_direction $postfix<0-3>; volume_case5 = prefix_0_5 + why + e(infix) + volume + e( infix) + reverse_direction + postfix_0_3 rule_case5 = Rule( attach_perperty(volume_case5, { 'operation': 'change', 'rule': 5 })) # $volume_case6 = $prefix<0-5> $reverse_direction [$infix] $volume [$infix] $why $postfix<0-3>; volume_case6 = prefix_0_5 + reverse_direction + e(infix) + volume + e( infix) + why + postfix_0_3 rule_case6 = Rule( attach_perperty(volume_case6, { 'operation': 'change', 'rule': 6 })) # $volume_case7 = $prefix<0-5> $volume [$infix] $reverse_direction [$infix] $why $postfix<0-3>; volume_case7 = prefix_0_5 + volume + e(infix) + reverse_direction + e( infix) + why + postfix_0_3 rule_case7 = Rule( attach_perperty(volume_case7, { 'operation': 'change', 'rule': 7 })) # $volume_case8 = $prefix<0-5> $reverse_direction [$infix] $why [$infix] $volume $postfix<0-3>; volume_case8 = prefix_0_5 + reverse_direction + e(infix) + why + e( infix) + volume + postfix_0_3 rule_case8 = Rule( attach_perperty(volume_case8, { 'operation': 'change', 'rule': 8 })) # $volume_case9 = $prefix<0-5> $volume [$infix] $why[$infix] $reverse_direction $postfix<0-3>; volume_case9 = prefix_0_5 + volume + e(infix) + why + e( infix) + reverse_direction + postfix_0_3 rule_case9 = Rule( attach_perperty(volume_case9, { 'operation': 'change', 'rule': 9 })) # 表达方式10-11:声音太大了;你说话力气好小; # $too_much = (太 | 过 | 过于 | 好); too_much = '(太|过于|过|好)' # $volume_case10 = $prefix<0-5> $volume $too_much $reverse_direction $postfix<0-3>; volume_case10 = prefix_0_5 + volume + too_much + reverse_direction + postfix_0_3 rule_case10 = Rule( attach_perperty(volume_case10, { 'operation': 'change', 'rule': 10 })) # $volume_case11 = $prefix<0-5> $too_much $reverse_direction $volume $postfix<0-3>; volume_case11 = prefix_0_5 + too_much + reverse_direction + volume + postfix_0_3 rule_case11 = Rule( attach_perperty(volume_case11, { 'operation': 'change', 'rule': 11 })) # 表达方式12:听不清楚;吵死了;你没吃饭吗; # $can_not_hear{direction%up} = (听不清 | 听不清楚 | 听不见 | 听不到 | 听不着 | 没吃饭); can_not_hear = '(听不清楚|听不清|听不见|听不到|听不着|没吃饭)' can_not_hear = attach_perperty(can_not_hear, {'direction': "up"}) # $too_loud{direction%down} = (太吵 | 吵死 | 吵死人 | 吵到我 | 吃多); too_loud = '(太吵|吵死人|吵死|吵到我|吃多)' can_not_hear = attach_perperty(can_not_hear, {'direction': "down"}) # $volume_case12 = $prefix<0-5> ($can_not_hear | $too_loud) $postfix<0-3>; volume_case12 = prefix_0_5 + o(can_not_hear, too_loud) + postfix_0_3 rule_case12 = Rule( attach_perperty(volume_case12, { 'operation': 'change', 'rule': 12 })) # 表达方式13:嘘 # $volume_case13 = (嘘 | 需 | 旭 | 徐); volume_case13 = '(嘘|需|旭|徐)' rule_case13 = Rule( attach_perperty(volume_case13, { 'operation': 'change', 'rule': 13 }))
honorific = honorific.join_all interj = interj.join_all prefix_unsual = prefix_unsual.join_all 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 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'})
class Mode(object): # 标识是mode领域 service = 'mode' 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 = prefix_unsual.join_all auxiliary = auxiliary.join_all quantifier = quantifier.join_all numeral = numeral.join_all adjective = adjective.join_all adverb = adverb.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) # 动作 action_enter = "(进入|进|启动|开启)" + e(numeral) + e(quantifier) action_enter = attach_perperty(action_enter, {'operation': 'enter'}) action_quit = "(退出|退)" + e(numeral) + e(quantifier) action_quit = attach_perperty(action_quit, {'operation': 'quit'}) action = o(action_enter, action_quit) # 模式 mode_show = "(展会|展览|参展|展厅|展示)" mode_show = attach_perperty(mode_show, {'name': 'show'}) mode_dance = "(跳舞|舞蹈)" mode_dance = attach_perperty(mode_dance, {'name': 'dance'}) mode_emotion = "(表情|舞蹈)" mode_emotion = attach_perperty(mode_emotion, {'name': 'emotion'}) mode_attract = "(招揽|招来|招徕|揽客)" mode_attract = attach_perperty(mode_attract, {'name': 'attract'}) mode_term = '(运行|运新|运型)?' + '(模式|方式|形式|样式|招式|状态|情景|表演)' action_mode = '(把|将)?' + o(mode_show, mode_dance, mode_emotion, mode_attract) + mode_term # 查询 query = '(查询|查|显示)' + e(numeral) + e(quantifier) current = '(当前|现在|目前|眼下)' + e('的') what = e('是') + '(什么|哪个|多少|怎样|如何|什么样)' # 进入退出表达方式 action_case1 = prefix_0_5 + action + action_mode + postfix_0_3 # 启动 展会模式 action_case2 = prefix_0_5 + action_mode + action + postfix_0_3 # 展会模式 开启 action_case3 = prefix_0_5 + mode_term + action_quit + postfix_0_3 # 运行模式 退出 action_sentence = o(action_case1, action_case2, action_case3) rule_action_sentence = Rule(attach_perperty(action_sentence, {'rule': '1'})) # 查询表达方式 get_case1 = prefix_0_5 + query + e( current) + mode_term + postfix_0_3 # 显示 [当前] 模式 get_case2 = prefix_0_5 + current + what + mode_term + postfix_0_3 # 现在是哪个运行模式 get_case3 = prefix_0_5 + current + mode_term + what + postfix_0_3 # 现在的运行模式是哪个 get_sentence = o(get_case1, get_case2, get_case3) rule_get_sentence = Rule( attach_perperty(get_sentence, { 'attribute': 'name', 'operation': 'get', 'rule': '2' }))
class Sight(object): # 标识是sight领域 service = 'sight' 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 directional = directional.join_all sight_name = sight_name.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) infix_0_2 = r(infix, 0, 2) sight_name = attach_name(sight_name, 'name') sight = r('(把|将)', 0, 1) + sight_name shape = '(样子|形状|外表|图片)' what = '(什么|哪种|怎么)' look = '(看看|观看|查看|看|瞧|瞅|瞄|观赏|欣赏)' + e(numeral) + e(quantifier) show = '(显示|出现|演示|表演)' + e(directional) + e(numeral) + e(quantifier) # 查询表达方式1:雪山 sight_case1 = sight rule_sight_case1 = Rule( attach_perperty(sight_case1, { 'operation': 'query', 'rule': 1 })) # 查询表达方式2:我想看一下雪山 sight_case2 = prefix_0_5 + look + e(infix) + sight + postfix_0_3 rule_sight_case2 = Rule( attach_perperty(sight_case2, { 'operation': 'query', 'rule': 2 })) # 查询表达方式3:你把雪山显示给我看看;雪山显示出来给我看看;雪山显示一下看看; sight_case3 = prefix_0_5 + sight + e(show) + infix_0_2 + look + postfix_0_3 rule_sight_case3 = Rule( attach_perperty(sight_case3, { 'operation': 'query', 'rule': 3 })) # 查询表达方式4:显示雪山;显示出来雪山看看; sight_case4 = prefix_0_5 + show + e(infix) + sight + e(look) + postfix_0_3 rule_sight_case4 = Rule( attach_perperty(sight_case4, { 'operation': 'query', 'rule': 4 })) # 查询表达方式5:雪山是什么样子的 sight_case5 = prefix_0_5 + sight + '(是)?' + what + shape + postfix_0_3 rule_sight_case5 = Rule( attach_perperty(sight_case5, { 'operation': 'query', 'rule': 5 }))
class Display(object): # 标识是display领域 service = 'display' 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 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) # 调整特征词 change_up = "(增|加|升|扩)" + e(numeral) + e(quantifier) change_up = attach_perperty(change_up, {'direction': 'up'}) change_down = "(减|降|缩)" + e(numeral) + e(quantifier) change_down = attach_perperty(change_down, {'direction': 'down'}) change = "(调|调整|弄|搞|放|变|整)" # 方向-向上 up = "(亮|大|高|强|重)" + e(numeral) + e(quantifier) up = attach_perperty(up, {'direction': 'up'}) light_up = "(亮|白)" + e(numeral) + e(quantifier) light_up = attach_perperty(light_up, {'direction': 'up'}) size_up = "(大|高|宽|胖)" + e(numeral) + e(quantifier) size_up = attach_perperty(size_up, {'direction': 'up'}) # 方向-向下 down = "(暗|小|低|弱|轻|低沉)" + e(numeral) + e(quantifier) down = attach_perperty(down, {'direction': 'down'}) light_down = "(暗|黑)" + e(numeral) + e(quantifier) light_down = attach_perperty(light_down, {'direction': 'down'}) size_down = "(小|矮|窄|瘦)" + e(numeral) + e(quantifier) size_down = attach_perperty(size_down, {'direction': 'down'}) # 方向-最大 maximum = e("(到|至)") + "(最大|最高|最强|最重|最响|最亮)" maximum = attach_perperty(maximum, {'direction': 'up', 'step': 'toend'}) light_maximum = e("(到|至)") + "(最亮)" light_maximum = attach_perperty(light_maximum, { 'direction': 'up', 'step': 'toend' }) size_maximum = e("(到|至)") + "(最大)" size_maximum = attach_perperty(size_maximum, { 'direction': 'up', 'step': 'toend' }) # 方向-最小 minimum = e("(到|至)") + "(最小|最低|最弱|最轻)" minimum = attach_perperty(minimum, {'direction': 'down', 'step': 'toend'}) light_minimum = e("(到|至)") + "(最暗)" light_minimum = attach_perperty(light_minimum, { 'direction': 'down', 'step': 'toend' }) size_minimum = e("(到|至)") + "(最小)" size_minimum = attach_perperty(size_minimum, { 'direction': 'down', 'step': 'toend' }) # 方向-汇总 direction = o(up, down, maximum, minimum) # 强一点 light_direction = o(light_up, light_down, light_maximum, light_minimum) # 亮一点 size_direction = o(size_up, size_down, size_maximum, size_minimum) # 大一点 # 调整+方向 change_case1 = o(change_up, change_down) + e(degree) + e(direction) # 加[重] change_case2 = e(change) + e(degree) + e(degree) + direction # [调]大 change_case3 = "(往|向|朝)" + e(degree) + e(degree) + direction + e( change) # 往大[调] change_direction = o(change_case1, change_case2, change_case3) # 调整+亮度方向 change_light_case1 = e( o(change, change_up, change_down)) + e(degree) + e(degree) + light_direction # [调]暗 change_light_case2 = "(往|向|朝)" + e( degree) + e(degree) + light_direction + e( o(change, change_up, change_down)) # 往暗[调] change_light_direction = o(change_light_case1, change_light_case2) # 调整+大小方向 change_size_case1 = e( o(change, change_up, change_down)) + e(degree) + e(degree) + size_direction # [调]大 change_size_case2 = "(往|向|朝)" + e(degree) + e(degree) + size_direction + e( o(change, change_up, change_down)) # 往暗[调] change_size_direction = o(change_size_case1, change_size_case2) # 屏幕调节特征词 display = "(把|将)?" + "(显示|屏|屏幕|图像|图片|界面)" + e(numeral) + e(quantifier) light = "(把|将)?" + "(亮度)" + e(numeral) + e(quantifier) size = "(把|将)?" + "(大小|尺寸)" + e(numeral) + e(quantifier) # 亮度表达方式 display_light1 = prefix_0_5 + r( display, 0, 2) + light + e(infix) + change_direction + postfix_0_3 # [把屏幕] 亮度 调高 display_light2 = prefix_0_5 + r( display, 0, 2) + e(infix) + change_direction + light + postfix_0_3 # [把屏幕] 调高 亮度 display_light3 = prefix_0_5 + r( display, 0, 2) + e(infix) + change_light_direction + postfix_0_3 # [屏幕] 调亮 display_light4 = prefix_0_5 + change_direction + r( display, 0, 2) + light + postfix_0_3 # //调高 [屏幕] 亮度 display_light_sentence = o(display_light1, display_light2, display_light3, display_light4) display_light_sentence = attach_perperty(display_light_sentence, { 'operation': 'light', 'rule': 1 }) rule_display_light_sentence = Rule(r(display_light_sentence, 1, 3)) # 大小表达方式:屏幕再调大点;请你把屏幕调到最小可以吗;把屏幕调整更大一点; display_size1 = prefix_0_5 + r( display, 0, 2) + size + e(infix) + change_direction + postfix_0_3 # [把屏幕] 大小 调高 display_size2 = prefix_0_5 + r( display, 0, 2) + e(infix) + change_direction + size + postfix_0_3 # [把屏幕] 调高 大小 display_size3 = prefix_0_5 + r( display, 0, 2) + e(infix) + change_size_direction + postfix_0_3 # [屏幕] 调大 display_size4 = prefix_0_5 + change_direction + r( display, 0, 2) + size + postfix_0_3 # 调高 [屏幕] 亮度 display_size_sentence = o(display_size1, display_size2, display_size3, display_size4) display_size_sentence = attach_perperty(display_size_sentence, { 'operation': 'size', 'rule': 2 }) rule_display_size_sentence = Rule(r(display_size_sentence, 1, 3))
class Dance(object): # 标识是dance领域 service = 'dance' 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 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) infix_0_2 = r(infix, 0, 2) # 修饰动作的副词 hurry = '(快|快点|赶紧|赶快)' # 跳舞特征词,日志中有多个唱舞蹈的表述特此增加 move = e(hurry) + '(跳|来|唱)' + e(numeral) + e(quantifier) dance = e('把|将') + '(舞|舞蹈|跳舞)' see = '(看|看看|观看|查看|瞧|瞅|瞄|观赏|欣赏)' + e(quantifier) postures = e(adjective) + '(舞姿|舞蹈)' # 舞蹈名称、类型、标签 dance_name = '(杰克逊|小苹果|生日快乐)' dance_type1 = '机械舞' dance_type2 = '街舞' dance_type3 = '芭蕾舞' dance_type4 = '现代舞' dance_type5 = '国标舞' dance_type6 = '摩登舞' dance_type7 = '华尔兹' dance_type8 = '探戈' dance_type9 = '狐步' dance_type10 = '快步' dance_type11 = '维也纳华尔兹' dance_type12 = '拉丁舞' dance_type13 = '伦巴' dance_type14 = '恰恰恰' dance_type15 = '桑巴' dance_type16 = '斗牛' dance_type17 = '牛仔舞' dance_type18 = '民族舞' dance_type19 = '扇子舞' dance_type20 = '秧歌' dance_type21 = '手绢花' dance_type22 = '伞舞' dance_type23 = '孔雀舞' dance_type24 = '竹竿舞' dance_type25 = '儿童舞' dance_type26 = '丝带舞' dance_type27 = '踢踏舞' dance_type28 = '爵士舞' dance_type29 = '钢管舞' dance_type30 = '广场舞' dance_type1 = attach_perperty(dance_type1, {'type': 1}) dance_type2 = attach_perperty(dance_type2, {'type': 2}) dance_type3 = attach_perperty(dance_type3, {'type': 3}) dance_type4 = attach_perperty(dance_type4, {'type': 4}) dance_type5 = attach_perperty(dance_type5, {'type': 5}) dance_type6 = attach_perperty(dance_type6, {'type': 6}) dance_type7 = attach_perperty(dance_type7, {'type': 7}) dance_type8 = attach_perperty(dance_type8, {'type': 8}) dance_type9 = attach_perperty(dance_type9, {'type': 9}) dance_type10 = attach_perperty(dance_type10, {'type': 10}) dance_type11 = attach_perperty(dance_type11, {'type': 11}) dance_type12 = attach_perperty(dance_type12, {'type': 12}) dance_type13 = attach_perperty(dance_type13, {'type': 13}) dance_type14 = attach_perperty(dance_type14, {'type': 14}) dance_type15 = attach_perperty(dance_type15, {'type': 15}) dance_type16 = attach_perperty(dance_type16, {'type': 16}) dance_type17 = attach_perperty(dance_type17, {'type': 17}) dance_type18 = attach_perperty(dance_type18, {'type': 18}) dance_type19 = attach_perperty(dance_type19, {'type': 19}) dance_type20 = attach_perperty(dance_type20, {'type': 20}) dance_type21 = attach_perperty(dance_type21, {'type': 21}) dance_type22 = attach_perperty(dance_type22, {'type': 22}) dance_type23 = attach_perperty(dance_type23, {'type': 23}) dance_type24 = attach_perperty(dance_type24, {'type': 24}) dance_type25 = attach_perperty(dance_type25, {'type': 25}) dance_type26 = attach_perperty(dance_type26, {'type': 26}) dance_type27 = attach_perperty(dance_type27, {'type': 27}) dance_type28 = attach_perperty(dance_type28, {'type': 28}) dance_type29 = attach_perperty(dance_type29, {'type': 29}) dance_type30 = attach_perperty(dance_type30, {'type': 30}) dance_type = o(dance_type1, dance_type2, dance_type3, dance_type4, dance_type5, dance_type6, dance_type7, dance_type8, dance_type9, dance_type10, dance_type11, dance_type12, dance_type13, dance_type14, dance_type15, dance_type16, dance_type17, dance_type18, dance_type19, dance_type20, dance_type21, dance_type22, dance_type23, dance_type24, dance_type25, dance_type26, dance_type27, dance_type28, dance_type29, dance_type30) # 其他不好写规则的特征表达 dance_unusual = '(来到舞蹈)' # 舞蹈语义解析 dance_case1 = prefix_0_5 + move + dance + postfix_0_3 # 跳 舞 rule_dance_case1 = Rule( attach_perperty(r(dance_case1, 1, 3), { 'operation': 'action', 'rule': 1 })) dance_case2 = prefix_0_5 + dance + move + postfix_0_3 # 舞 来 rule_dance_case2 = Rule( attach_perperty(r(dance_case2, 1, 3), { 'operation': 'action', 'rule': 2 })) dance_case3 = prefix_0_5 + move + dance_name + '(的)?' + e( dance) + postfix_0_3 # 跳 小苹果 rule_dance_case3 = Rule( attach_perperty(r(dance_case3, 1, 3), { 'operation': 'action', 'rule': 3 })) dance_case4 = prefix_0_5 + dance_name + '(的)?' + e( dance) + move + postfix_0_3 # 小苹果 来 rule_dance_case4 = Rule( attach_perperty(r(dance_case4, 1, 3), { 'operation': 'action', 'rule': 4 })) dance_case5 = prefix_0_5 + move + dance_type + e( dance) + postfix_0_3 # 跳 机械舞 rule_dance_case5 = Rule( attach_perperty(r(dance_case5, 1, 3), { 'operation': 'action', 'rule': 5 })) dance_case6 = prefix_0_5 + dance_type + e( dance) + move + postfix_0_3 # 机械舞 来 rule_dance_case6 = Rule( attach_perperty(r(dance_case6, 1, 3), { 'operation': 'action', 'rule': 6 })) dance_case7 = prefix_0_5 + see + '(你(的)?)' + postures + postfix_0_3 # 看 你的 舞姿 rule_dance_case7 = Rule( attach_perperty(r(dance_case7, 1, 3), { 'operation': 'action', 'rule': 7 })) dance_case8 = prefix_0_5 + dance + '(你)?' + modals + move + postfix_0_3 # 舞 会不会 跳 rule_dance_case8 = Rule( attach_perperty(r(dance_case8, 1, 3), { 'operation': 'action', 'rule': 8 })) dance_case9 = postfix_0_3 + dance_unusual + postfix_0_3 # 特殊规则 rule_dance_case9 = Rule( attach_perperty(r(dance_case9, 1, 3), { 'operation': 'action', 'rule': 9 })) # 跳舞场景 dance_case10 = '(小忆)?你会跳舞吗' rule_dance_case10 = Rule( attach_perperty(dance_case10, { 'operation': 'action', 'rule': 10, 'scene': 'dance', 'node': 'query' })) # 跳舞场景 dance_case11 = '(小忆)?你会跳什么舞' rule_dance_case11 = Rule( attach_perperty(dance_case11, { 'operation': 'action', 'rule': 11, 'scene': 'dance', 'node': 'get' }))