示例#1
0
        "polite": ["polite", "manners", "decent"],
        "conceited": [
            "conceited", "overconfident", "arrogant", "full of",
            "narcissistic", "egotistic", "egotistical", "selfish"
        ],
        "beautiful": ["gorgeous", "pretty", "hot", "sexy"]
    }
}

kb = KnowledgeBase()
kb.load_json(kb_dict)
df = DialogueFlow(initial_state="root", kb=kb)

root = 'root'
end = 'end'
df.add_state(root, error_successor=root, memory=0)
df.add_state(end, error_successor=end)
df.add_system_transition(root, end, 'I have no nonrepetitive options', score=0)

# S: Who do you live with?
root = 'root'
df.add_state('opening live with', error_successor=root)
df.add_system_transition(root, 'opening live with',
                         '[!#GATE() "So, who do you live with?"]')

df.add_user_transition(
    'opening live with', root,
    '[!#NOT(#EXP(negation)) [{$related_type={#ONT(person),#EXP(roommate),family},people, someone, anyone, guys, girls}]]'
)

df.add_user_transition(
                    'sorry to hear that':{
                        'error': 'root'
                    }
                }
            }
        },
        '[how, you]': {
            'good': {
                'error': 'root'
            }
        }
    }
}
df.load_transitions(flow, DialogueFlow.Speaker.SYSTEM)

df.state_settings('root').update(system_multi_hop=True)
df.add_state('recovery_question', global_nlu='[!{do, who, what, when, where, why, how, is, can, should}, /.*/]')
df.add_system_transition('recovery_question', 'root', '"Hmm.. I\'m not sure."')

df.add_user_transition('x', 'y', '#ANY($myvar=something, $other=somethingelse) [hello]')

while True:
    df.system_turn()
    v = input()
    var, val = v.split('=')
    df.vars().update({var: val})
    df.user_turn(input())


if __name__ == '__main__':
    df.run(debugging=True)
                },
            },
        },
        "[how, you]": {
            "good": {
                "error": "root"
            }
        },
    },
}
df.load_transitions(flow, DialogueFlow.Speaker.SYSTEM)

df.state_settings("root").update(system_multi_hop=True)
df.add_state(
    "recovery_question",
    global_nlu=
    "[!{do, who, what, when, where, why, how, is, can, should}, /.*/]",
)
df.add_system_transition("recovery_question", "root", '"Hmm.. I\'m not sure."')

df.add_user_transition("x", "y",
                       "#ANY($myvar=something, $other=somethingelse) [hello]")

while True:
    df.system_turn()
    v = input()
    var, val = v.split("=")
    df.vars().update({var: val})
    df.user_turn(input())

if __name__ == "__main__":
示例#4
0
def test_composite_df_with_error_in_component():
    df1 = DialogueFlow('A', initial_speaker=DialogueFlow.Speaker.USER)
    df1.add_state('A', 'X')
    df1.add_state('X')
    df1.add_state('C', 'D')
    df1.add_state('D')
    df1.add_user_transition('A', 'D', '$fruit=apple dog')
    df1.add_system_transition('X', 'C', 'banana catfish')
    df1.add_system_transition('D', 'A', 'dog apple')
    #df1.add_system_transition('X', ('movie', 'Y'), 'movie')
    #df1.run(debugging=True)

    df2 = DialogueFlow('A', initial_speaker=DialogueFlow.Speaker.USER)
    df2.add_state('A', 'X')
    df2.add_state('X')
    df2.add_state('C', 'D')
    df2.add_state('D')
    df2.add_user_transition('A', 'D', '$state=alaska down')

    df2.add_state(('SYSTEM', 'topic_err'), global_nlu='back')
    df2.add_state(('one', 'X'), global_nlu='dog')

    cdf = CompositeDialogueFlow('start',
                                'topic_err',
                                'topic',
                                initial_speaker=DialogueFlow.Speaker.USER)
    cdf.add_component(df1, 'one')
    cdf.add_component(df2, 'two')
    cdf.add_state('start', 'greet')
    cdf.add_state('greet')
    cdf.add_state('topic', 'topic_err')
    cdf.add_state('topic_err')
    cdf.add_system_transition('topic_err', 'topic',
                              'what do you want to discuss')
    cdf.add_system_transition('greet', 'topic', 'hello')
    cdf.add_user_transition('topic', ('one', 'X'), '$animal={catfish, dog}')
    cdf.add_user_transition('topic', ('two', 'X'),
                            '$item={alaska, bark, down}')
    cdf.add_user_transition(('one', 'A'), ('SYSTEM', 'topic_err'), 'back')

    cdf.user_turn('hello')
    assert cdf.system_turn() == 'hello'
    cdf.user_turn('bark')
    assert cdf.controller_name() == 'two'
    assert cdf.system_turn().strip() == 'what do you want to discuss'
    cdf.user_turn('catfish')
    assert cdf.controller_name() == 'one'
def test_composite_df_working():
    df1 = DialogueFlow("A", initial_speaker=DialogueFlow.Speaker.USER)
    df1.add_state("A", "X")
    df1.add_state("X")
    df1.add_state("C", "D")
    df1.add_state("D")
    df1.add_user_transition("A", "D", "$fruit=apple dog")
    df1.add_system_transition("X", "C", "banana catfish")
    df1.add_system_transition("D", "A", "dog apple")
    # df1.add_system_transition('X', ('movie', 'Y'), 'movie')
    # df1.run(debugging=True)

    df2 = DialogueFlow("A", initial_speaker=DialogueFlow.Speaker.USER)
    df2.add_state("A", "X")
    df2.add_state("X")
    df2.add_state("C", "D")
    df2.add_state("D")
    df2.add_user_transition("A", "D", "$state=alaska down")
    df2.add_system_transition("X", "C", "bark call")
    df2.add_system_transition("D", "A", "down alaska")
    # df2.run(debugging=True)

    df2.add_state(("SYSTEM", "topic_err"), global_nlu="back")
    df2.add_state(("one", "X"), global_nlu="dog")

    cdf = CompositeDialogueFlow(
        "start", "topic_err", "topic", initial_speaker=DialogueFlow.Speaker.USER
    )
    cdf.add_component(df1, "one")
    cdf.add_component(df2, "two")
    cdf.add_state("start", "greet")
    cdf.add_state("greet")
    cdf.add_state("topic", "topic_err")
    cdf.add_state("topic_err")
    cdf.add_system_transition("topic_err", "topic", "what do you want to discuss")
    cdf.add_system_transition("greet", "topic", "hello")
    cdf.add_user_transition("topic", ("one", "X"), "$animal={catfish, dog}")
    cdf.add_user_transition("topic", ("two", "X"), "$item={alaska, bark, down}")
    cdf.add_user_transition(("one", "A"), ("SYSTEM", "topic_err"), "back")

    cdf.user_turn("hello")
    assert cdf.system_turn() == "hello"
    cdf.user_turn("bark")
    assert cdf.controller_name() == "two"
    assert cdf.system_turn() == "bark call"
    cdf.user_turn("back")
    assert cdf.controller_name() == "SYSTEM"
示例#6
0
# import pytest
from emora_stdm import DialogueFlow
from emora_stdm.state_transition_dialogue_manager.composite_dialogue_flow import (
    CompositeDialogueFlow, )

if __name__ == "__main__":
    df1 = DialogueFlow("A", initial_speaker=DialogueFlow.Speaker.USER)
    df1.add_state("A", 6)
    df1.add_state(6)
    df1.add_state("C", "D")
    df1.add_state("D")
    df1.add_user_transition("A", "D", "$fruit=apple dog")
    df1.add_system_transition(6, "C", "banana catfish")
    df1.add_system_transition("D", "A", "dog apple")
    # df1.add_system_transition(6, ('movie', 'Y'), 'movie')
    # df1.run(debugging=True)

    df2 = DialogueFlow("A", initial_speaker=DialogueFlow.Speaker.USER)
    df2.add_state("A", 6)
    df2.add_state(6)
    df2.add_state("C", "D")
    df2.add_state("D")
    df2.add_user_transition("A", "D", "$state=alaska down")
    df2.add_system_transition(6, "C", "bark call")
    df2.add_system_transition("D", "A", "down alaska")
    # df2.run(debugging=True)

    df2.add_state(("SYSTEM", "topic_err"), global_nlu="back")
    df2.add_state(("one", 6), global_nlu="dog")

    cdf = CompositeDialogueFlow(