Esempio n. 1
0
class Cartoon(object):
    """
    卡通语义
    """
    # 标识是cartoon领域
    service = 'cartoon'

    show_obj = '(动画片|动画|卡通片|卡通|儿童动画)'

    # 我想听XX
    case_1 = e(me) + e(want) + e(again) + e(adverb) + see + e(tag) + e('的') + show_obj + any_w
    rule_1 = Rule(attach_perperty(case_1, {'operation': 'play', 'rule': 1}))

    # 请给我播放XX
    case_2 = e(ask) + e(give) + e(me) + tell + e(tag) + e('的') + show_obj + any_w
    rule_2 = Rule(attach_perperty(case_2, {'operation': 'play', 'rule': 2}))

    # 小忆你可以给我播放XX吗
    case_3 = e(robot) + can + e(give) + e(me) + tell + e(tag) + e('的') + show_obj + e(stop_words)
    rule_3 = Rule(attach_perperty(case_3, {'operation': 'play', 'rule': 3}))

    # 我能请你帮我打开XX吗
    case_4 = e(me) + can + e(ask) + e(robot) + e(give) + e(me) + tell + e(tag) + e('的') + show_obj + e(stop_words)
    rule_4 = Rule(attach_perperty(case_4, {'operation': 'play', 'rule': 4}))

    # 请你帮我打开XX
    case_5 = ask + robot + give + me + tell + e(tag) + e('的') + show_obj + e(stop_words)
    rule_5 = Rule(attach_perperty(case_5, {'operation': 'play', 'rule': 5}))
Esempio n. 2
0
class PictureBook(object):
    """
    绘本语义
    """
    # 标识是mode领域
    service = 'picturebook'

    # 绘本的说法
    show_obj = '(绘本|会呗|会吧|快本|会呢|会的|会吧|会吗)'

    # 我想听XX
    case_1 = e(me) + e(want) + e(again) + e(adverb) + see + e(tag) + e('的') + show_obj + any_w
    rule_1 = Rule(attach_perperty(case_1, {'operation': 'play', 'rule': 1}))

    # 请给我播放XX
    case_2 = e(ask) + e(give) + e(me) + tell + e(tag) + e('的') + show_obj + any_w
    rule_2 = Rule(attach_perperty(case_2, {'operation': 'play', 'rule': 2}))

    # 小忆你可以给我播放绘本吗
    case_3 = e(robot) + can + e(give) + e(me) + tell + e(tag) + e('的') + show_obj + e(stop_words)
    rule_3 = Rule(attach_perperty(case_3, {'operation': 'play', 'rule': 3}))

    # 我能请你帮我打开绘本吗
    case_4 = e(me) + can + e(ask) + e(robot) + e(give) + e(me) + tell + e(tag) + e('的') + show_obj + e(stop_words)
    rule_4 = Rule(attach_perperty(case_4, {'operation': 'play', 'rule': 4}))

    # 请你帮我打开绘本
    case_5 = ask + robot + give + me + tell + e(tag) + e('的') + show_obj + e(stop_words)
    rule_5 = Rule(attach_perperty(case_5, {'operation': 'play', 'rule': 5}))
Esempio n. 3
0
class Comic(object):
    """
    相声语义
    """
    # 标识是mode领域
    service = 'comic'

    show_obj = '(相声|段子)'

    # 我想听XX
    case_1 = e(me) + e(want) + e(again) + e(adverb) + see + e(tag) + e(
        '的') + show_obj + any_w
    rule_1 = Rule(attach_perperty(case_1, {'operation': 'play', 'rule': 1}))

    # 请给我播放XX
    case_2 = e(ask) + e(give) + e(me) + tell + e(tag) + e(
        '的') + show_obj + any_w
    rule_2 = Rule(attach_perperty(case_2, {'operation': 'play', 'rule': 2}))

    # 小忆你可以给我播放相声吗
    case_3 = e(robot) + can + e(give) + e(me) + tell + e(tag) + e(
        '的') + show_obj + e(stop_words)
    rule_3 = Rule(attach_perperty(case_3, {'operation': 'play', 'rule': 3}))

    # 我能请你帮我打开相声吗
    case_4 = e(me) + can + e(ask) + e(robot) + e(give) + e(me) + tell + e(
        tag) + e('的') + show_obj + e(stop_words)
    rule_4 = Rule(attach_perperty(case_4, {'operation': 'play', 'rule': 4}))

    # 请你帮我打开相声
    case_5 = ask + robot + give + me + tell + e(tag) + e('的') + show_obj + e(
        stop_words)
    rule_5 = Rule(attach_perperty(case_5, {'operation': 'play', 'rule': 5}))
Esempio n. 4
0
class Recognition(object):
    # 标识recognition领域
    service = 'recognition'

    stop_words = stop_words.join_all
    pronoun = pronoun.join_all
    modals = modals.join_all
    adverb = adverb.join_all

    look = '(看|猜|说|查看|瞅|瞧|观察|鉴别|望|瞟|问|告诉我)'
    location = '(这|那|这边|那边|这里|那里|这个)'
    what = '(什么|啥)'
    robot = '(你|机器人|小忆)'

    color = '(颜色|彩色|色|色泽|红|黄|蓝|绿|黑|白|紫|桔|橙|青)'
    color = attach_perperty(color, {'attribute': 'color'})

    thing = '(东西|物品|水果)'
    thing = attach_perperty(thing, {'attribute': 'name'})

    # 这是什么颜色
    color_case = '(请|那)?' + e(robot) + e(look) + e(location) + '是' + what + color + any_w
    rule_color_case = Rule(attach_perperty(color_case, {'operation': 'get', 'attribute': 'color'}))

    # 这是什么
    thing_case = '(请|那)?' + e(robot) + e(look) + location + '是' + what + e(thing) + any_w
    rule_thing_case = Rule(attach_perperty(thing_case, {'operation': 'get', 'attribute': 'name'}))
Esempio n. 5
0
class Curtain(object):
    # 标识是mode领域
    service = 'smart_home_airconditioner'

    # 动作特征词
    turn = o(turn_on, turn_off, turn_up, turn_down)
    airconditioner = e(desc) + e('的') + o('空调机', '空调') + e('的')

    temperature = '(温度)'
    cool = attach_perperty('(制冷|冷风)', {'parameter': 'cool'})
    heat = attach_perperty('(制热|热风)', {'parameter': 'heat'})
    parameter = o(temperature, cool, heat) + e('调到')
    parameter = attach_perperty(parameter, {'operation': 'set'})

    degree = range_tag(2, 'degree') + '(度)'

    # [空调]控制语义解析
    airconditioner_case1 = prefix_0_3 + turn + e(
        position) + airconditioner + e(parameter) + postfix_0_3  # 关空调
    rule_conditioner_case_1 = Rule(
        attach_perperty(airconditioner_case1, {'rule': 1}))

    airconditioner_case2 = prefix_0_3 + e('把') + e(
        position) + airconditioner + e(parameter) + turn + postfix_0_3  # 把空调打开
    rule_conditioner_case_2 = Rule(
        attach_perperty(airconditioner_case2, {'rule': 2}))

    airconditioner_case3 = prefix_0_5 + '(把)' + e(
        position) + airconditioner + parameter + e(
            turn) + degree + postfix_0_3  # 空调冷风16度
    rule_conditioner_case_3 = Rule(
        attach_perperty(airconditioner_case3, {'rule': 3}))
Esempio n. 6
0
class Trick(object):
    # 标识是trick领域
    service = 'trick'

    pronoun = pronoun.join_all
    can_words = modals.join_all
    adverb = adverb.join_all
    ask = honorific.join_all
    want = '(要|想|想要|需要)'

    # 语义意图,仅支持一种,听
    listen = '(听)(一)?(个)?'

    # 语义意图
    tell = '(讲|来)(一)?(个)?'

    # 脑筋急转弯
    trick = '(脑筋急转弯|急转弯)'

    # robot
    robot = '(你|机器人|小忆)'

    # me
    me = '(我|我们|咱|咱们|俺)'

    # 再,又
    again = '(再|又|多)'

    # 个
    an = '(个|一个)'

    # 给
    give = '(给|为)'

    # 我要听个急转弯
    case_1 = e(robot) + e(me) + e(want) + e(again) + listen + e(
        an) + trick + e(stop_words)
    rule_1 = Rule(
        attach_perperty(case_1, {
            'scene': 'trick',
            'operation': 'trick',
            'rule': 1
        }))

    # 给我讲个急转弯
    case_2 = e(robot) + e(give) + e(me) + tell + e(an) + trick + e(stop_words)
    rule_2 = Rule(
        attach_perperty(case_2, {
            'scene': 'trick',
            'operation': 'trick',
            'rule': 2
        }))

    # 再来一个
    case_3 = attach_perperty('(再来一个)', {
        'scene': 'trick',
        'operation': 'trick',
        'rule': 3
    })
    rule_3 = Rule(case_3, {'status': 'trick'})
Esempio n. 7
0
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 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
        }))
Esempio n. 9
0
class Light(object):

    # 标识是Light领域
    service = 'smart_home_light'

    # 动作特征词
    turn = o(turn_on, turn_off)
    light = e(desc) + e('的') + o('灯', '灯光')

    # [灯]控制语义解析
    light_case1 = prefix_0_3 + turn + e(position) + light + postfix_0_3  # 关灯
    rule_comic_case_1 = Rule(attach_perperty(light_case1, {'rule': 1}))

    light_case2 = prefix_0_3 + e('把') + e(
        'position') + light + turn + postfix_0_3  # 把灯打开
    rule_comic_case_2 = Rule(attach_perperty(light_case2, {'rule': 2}))
Esempio n. 10
0
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}))
Esempio n. 11
0
class Phone(object):
    # 标识是phone领域
    service = 'phone'

    pronoun = pronoun.join_all
    can_words = modals.join_all
    adverb = adverb.join_all
    ask = honorific.join_all
    want = '(要|想要|想|需要)'

    # 语义意图,仅支持一种,打
    dial = '(打|挂|拨)(一)?(个)?'

    # 电话
    phone = '(电话)'

    # robot
    robot = '(你|机器人|小忆)'

    # me
    me = '(我|我们|咱|咱们|俺)'

    # 再,又
    again = '(再|又|多)'

    # 关系
    relation = '(爸爸|妈妈|爷爷|奶奶)'
    relation = attach_name(relation, 'relation')

    # 个
    an = '(个|一个)'

    # 给
    give = '(给)'

    # 我要打电话
    case_1 = e(robot) + e(me) + e(want) + e(again) + dial + e(an) + phone + e(stop_words)
    rule_1 = Rule(attach_perperty(case_1, {'scene': 'phone_call', 'operation': 'phone', 'rule': 1}))

    # 给爸爸打电话
    case_2 = give + relation + dial + phone
    rule_2 = Rule(attach_perperty(case_2, {'operation': 'phone', 'rule': 2}))
Esempio n. 12
0
class TV(object):
    # 标识是mode领域
    service = 'smart_home_tv'

    # 动作特征词
    turn = o(turn_on, turn_off, turn_up, turn_down)
    tv = e(desc) + e('的') + o('电视机', '电视') + e('的')

    volume = attach_perperty('音量', {'parameter': 'volume'})
    channel = attach_perperty('频道', {'parameter': 'channel'})
    rack = attach_perperty('架', {'parameter': 'rack'})
    parameter = o(volume, channel, rack)

    # [电视]控制语义解析
    tv_case1 = prefix_0_3 + turn + e(position) + tv + e(
        parameter) + postfix_0_3  # 关灯
    rule_tv_case_1 = Rule(attach_perperty(tv_case1, {'rule': 1}))

    tv_case2 = prefix_0_3 + e('把') + e('position') + tv + e(
        parameter) + turn + postfix_0_3  # 把灯打开
    rule_tv_case_2 = Rule(attach_perperty(tv_case2, {'rule': 2}))
Esempio n. 13
0
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
        }))
Esempio n. 14
0
class Aircleaner(object):
    # 标识是smart_home_aircleaner领域
    service = 'smart_home_aircleaner'

    # 动作特征词
    turn = o(turn_on, turn_off)
    query = attach_perperty(o('查一下', '查询', '查查', '怎么样'),
                            {'operation': 'query'})
    aircleaner = e(desc) + e('的') + o('空气净化器', '空净') + e('的')
    airquality = e(aircleaner) + o('空气质量', '空气')

    volume = attach_perperty('音量', {'parameter': 'volume'})
    channel = attach_perperty('频道', {'parameter': 'channel'})
    rack = attach_perperty('架', {'parameter': 'rack'})
    parameter = o(volume, channel, rack)

    # [空净]控制语义解析
    aircleaner_case1 = prefix_0_3 + turn + e(position) + aircleaner + e(
        parameter) + postfix_0_3  # 关空气净化器
    rule_aircleaner_case1 = Rule(attach_perperty(aircleaner_case1,
                                                 {'rule': 1}))

    aircleaner_case2 = prefix_0_3 + e('把') + e('position') + aircleaner + e(
        parameter) + turn + postfix_0_3  # 把空气净化器打开
    rule_aircleaner_case2 = Rule(attach_perperty(aircleaner_case2,
                                                 {'rule': 2}))

    aircleaner_case3 = prefix_0_3 + e('把') + e(
        'position') + aircleaner + query + postfix_0_3  # 卧室的空气质量查一下
    rule_aircleaner_case3 = Rule(attach_perperty(aircleaner_case3,
                                                 {'rule': 2}))

    aircleaner_case4 = prefix_0_5 + e('把') + query + e(
        'position') + aircleaner + postfix_0_3  # 卧室的空气质量查一下
    rule_aircleaner_case4 = Rule(attach_perperty(aircleaner_case4,
                                                 {'rule': 2}))
Esempio n. 15
0
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
        }))
Esempio n. 16
0
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
        }))
Esempio n. 17
0
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
        }))
Esempio n. 18
0
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'
        }))
Esempio n. 19
0
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
        }))
Esempio n. 20
0
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
        }))
Esempio n. 21
0
class Motion(object):
    # 标识是motion领域
    service = 'motion'

    pronoun = pronoun.join_all
    stop_words = stop_words.join_all
    modals = modals.join_all

    robot = '(你|机器人|小忆)'
    ask = '(请|让|要|要求|麻烦)'
    word1 = '(将|把)'

    up = '(抬头|抬起头|看|抬起来)'
    up = attach_perperty(up, {'code': 'lookUp', 'emotion': 12})
    down = '(低头|低下头|低个头|向下|低下去)'
    down = attach_perperty(down, {'code': 'lookDown', 'emotion': 10})
    shake = '(摇头|摇下头|摇个头|转头)'
    shake = attach_perperty(shake, {'code': 'shakeHead', 'emotion': 8})
    nod = '(点(下|个)?头)'
    nod = attach_perperty(nod, {'code': 'nod', 'emotion': 21})
    twist = '(扭下|扭个|动下|动个)'
    twist = attach_perperty(twist, {'code': 'twist', 'emotion': 12})
    stand = "站(直|好|稳|住|定)"
    stand = attach_perperty(stand, {'code': 'stand', 'emotion': 12})

    run = '跑{1,2}'
    run = attach_perperty(run, {'operation': 'run'})
    fly = '飞{1,2}'
    fly = attach_perperty(fly, {'operation': 'fly'})
    jump = '跳{1,2}'
    jump = attach_perperty(jump, {'operation': 'jump'})
    swim = '游{1,2}'
    swim = attach_perperty(swim, {'operation': 'swim'})
    turn = '转{1,2}'
    turn = attach_perperty(turn, {'operation': 'turn'})

    move = o(run, fly, jump, swim, turn)

    fast = '(全速|快点|快)'
    fast = attach_perperty(fast, {'speed': 'fast'})
    slow = '(慢速|慢点|缓慢|慢)'
    slow = attach_perperty(slow, {'speed': 'slow'})
    speed = o(fast, slow)

    will = '(向|朝)'

    dirction_1 = '上'
    dirction_1 = attach_perperty(dirction_1, {'direction': 'up'})
    dirction_2 = '下'
    dirction_2 = attach_perperty(dirction_2, {'direction': 'down'})
    dirction_3 = '前'
    dirction_3 = attach_perperty(dirction_3, {'direction': 'forth'})
    dirction_4 = '后'
    dirction_4 = attach_perperty(dirction_4, {'direction': 'back'})
    dirction_5 = '左'
    dirction_5 = attach_perperty(dirction_5, {'direction': 'left'})
    dirction_6 = '右'
    dirction_6 = attach_perperty(dirction_6, {'direction': 'right'})
    dirction = o(dirction_1, dirction_2, dirction_3, dirction_4, dirction_5,
                 dirction_6)
    dirction = e(will) + dirction

    # 快向上看
    action_sentence1 = e(robot) + e(speed) + e(dirction) + o(
        up, down, shake, nod, twist) + e(stop_words)
    action_sentence1 = attach_perperty(action_sentence1, {
        'operation': 'action',
        'rule': 1
    })

    # 请将头抬起来
    action_sentence2 = e(robot) + e(ask) + e(robot) + e(word1) + e('头') + o(
        up, down, shake, nod, twist) + e(stop_words)
    action_sentence2 = attach_perperty(action_sentence2, {
        'operation': 'action',
        'rule': 2
    })

    # 快X呀
    move_sentence1 = e(speed) + move + e(stop_words)
    move_sentence1 = attach_perperty(move_sentence1, {'rule': 3})

    # 你X
    move_sentence2 = e(modals) + e(pronoun) + move + e(stop_words)
    move_sentence2 = attach_perperty(move_sentence2, {'rule': 4})

    # 快点向左转
    action = o(run, fly, jump, swim, turn)
    action_sentence3 = e(ask) + e(robot) + e(speed) + e(will) + e(
        stop_words) + dirction + e(stop_words) + action + e(stop_words)
    action_sentence3 = attach_perperty(action_sentence3, {'rule': 5})

    # 转快点
    action_sentence4 = e(ask) + e(robot) + action + e(speed) + e(stop_words)
    action_sentence4 = attach_perperty(action_sentence4, {'rule': 6})

    # 站直了
    action_sentence5 = e(ask) + e(robot) + stand + e(speed) + e(stop_words)
    action_sentence5 = attach_perperty(action_sentence5, {'rule': 7})

    rule_case1 = Rule(o(action_sentence1, action_sentence2))
    rule_case2 = Rule(action_sentence3)
    rule_case3 = Rule(action_sentence4)
    rule_case4 = Rule(o(move_sentence1, move_sentence2))
    rule_case5 = Rule(action_sentence5)
Esempio n. 22
0
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
        }))
Esempio n. 23
0
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
        }))
Esempio n. 24
0
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'}))
Esempio n. 25
0
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))
Esempio n. 26
0
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'
        }))
Esempio n. 27
0
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}))
Esempio n. 28
0
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}")