예제 #1
0
def test_serialization():
    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.new_turn()
    cdf.user_turn('hello')
    assert cdf.system_turn() == 'hello'
    s = cdf.serialize()

    cdf.new_turn()
    cdf.deserialize(s)
    cdf.user_turn('bark')
    assert cdf.controller_name() == 'two'
    assert cdf.system_turn().strip() == 'what do you want to discuss'
    s = cdf.serialize()

    cdf.new_turn()
    cdf.deserialize(s)
    cdf.user_turn('catfish')
    assert cdf.controller_name() == 'one'
예제 #2
0
def test_serialization_gates():
    cdf = CompositeDialogueFlow('start',
                                'topic_err',
                                'topic',
                                initial_speaker=DialogueFlow.Speaker.USER)
    cdf.add_user_transition('start', 'one', 'hello')
    cdf.add_system_transition('one', 'two', '`one to two` #GATE', score=10)
    cdf.add_user_transition('two', 'one', 'hello')
    cdf.add_system_transition('one', 'three', '`one to three`')

    cdf.new_turn()
    cdf.user_turn('hello')
    assert cdf.system_turn().strip() == 'one to two'
    s = cdf.serialize()

    cdf.new_turn()
    cdf.deserialize(s)
    cdf.user_turn('hello')
    assert cdf.system_turn().strip() == 'one to three'

    cdf = CompositeDialogueFlow('start',
                                'topic_err',
                                'topic',
                                initial_speaker=DialogueFlow.Speaker.USER)
    cdf.controller().add_state('one', enter='#GATE')
    cdf.add_user_transition('start', 'one', 'hello')
    cdf.add_system_transition('one', 'two', '`one to two`')
    cdf.add_user_transition('two', 'one', 'hello', score=10)
    cdf.add_user_transition('two', 'three', 'hello')
    cdf.add_system_transition('three', 'four', '`three to four`')

    cdf.new_turn()
    cdf.user_turn('hello')
    assert cdf.system_turn().strip() == 'one to two'
    s = cdf.serialize()
    print(s)

    cdf.new_turn()
    cdf.deserialize(s)
    cdf.user_turn('hello')
    assert cdf.system_turn().strip() == 'three to four'
def test_serialization():
    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.new_turn()
    cdf.user_turn("hello")
    assert cdf.system_turn() == "hello"
    s = cdf.serialize()

    cdf.new_turn()
    cdf.deserialize(s)
    cdf.user_turn("bark")
    assert cdf.controller_name() == "two"
    assert cdf.system_turn().strip() == "what do you want to discuss"
    s = cdf.serialize()

    cdf.new_turn()
    cdf.deserialize(s)
    cdf.user_turn("catfish")
    assert cdf.controller_name() == "one"
def test_serialization_gates():
    cdf = CompositeDialogueFlow(
        "start", "topic_err", "topic", initial_speaker=DialogueFlow.Speaker.USER
    )
    cdf.add_user_transition("start", "one", "hello")
    cdf.add_system_transition("one", "two", "`one to two` #GATE", score=10)
    cdf.add_user_transition("two", "one", "hello")
    cdf.add_system_transition("one", "three", "`one to three`")

    cdf.new_turn()
    cdf.user_turn("hello")
    assert cdf.system_turn().strip() == "one to two"
    s = cdf.serialize()

    cdf.new_turn()
    cdf.deserialize(s)
    cdf.user_turn("hello")
    assert cdf.system_turn().strip() == "one to three"

    cdf = CompositeDialogueFlow(
        "start", "topic_err", "topic", initial_speaker=DialogueFlow.Speaker.USER
    )
    cdf.controller().add_state("one", enter="#GATE")
    cdf.add_user_transition("start", "one", "hello")
    cdf.add_system_transition("one", "two", "`one to two`")
    cdf.add_user_transition("two", "one", "hello", score=10)
    cdf.add_user_transition("two", "three", "hello")
    cdf.add_system_transition("three", "four", "`three to four`")

    cdf.new_turn()
    cdf.user_turn("hello")
    assert cdf.system_turn().strip() == "one to two"
    s = cdf.serialize()
    print(s)

    cdf.new_turn()
    cdf.deserialize(s)
    cdf.user_turn("hello")
    assert cdf.system_turn().strip() == "three to four"
예제 #5
0
def test_composite_df_with_error_in_composite():
    #NOT A VALID TEST: MODIFY TO MAKE ERROR IN COMPOSITE DIALOGUE FLOW

    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_with_error_in_composite():
    # NOT A VALID TEST: MODIFY TO MAKE ERROR IN COMPOSITE DIALOGUE FLOW

    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"
예제 #7
0
def test_virtual_transitions_cross_module():
    df = DialogueFlow("root")
    transitions = {
        "state": "root",
        "hello": {
            "state": "test",
            "a": {"something typical"},
            "#VT(two:other)": "blah",
        },
    }
    df.load_transitions(transitions)
    df2 = DialogueFlow("r2")
    transitions2 = {
        "not taken": {
            "state": "other",
            "score": 0,
            "x": {
                "you win": {
                    "state": "success"
                }
            },
            "y": {
                "you win": {
                    "state": "success"
                }
            },
        }
    }
    df2.load_transitions(transitions2)
    cdf = CompositeDialogueFlow("one:root", "e", "e")
    cdf.add_component(df, "one")
    cdf.add_component(df2, "two")
    cdf.set_state("one:root")

    cdf.system_turn()
    assert cdf.state() == ("one", "test")
    cdf.user_turn("x", debugging=True)
    assert cdf.system_turn() == "you win"
    assert cdf.state() == ("two", "success")
예제 #8
0
def test_virtual_transitions_cross_module():
    df = DialogueFlow('root')
    transitions = {
        'state': 'root',
        'hello': {
            'state': 'test',
            'a': {'something typical'},
            '#VT(two:other)': 'blah'
        }
    }
    df.load_transitions(transitions)
    df2 = DialogueFlow('r2')
    transitions2 = {
        'not taken': {
            'state': 'other',
            'score': 0,
            'x': {
                'you win': {
                    'state': 'success'
                }
            },
            'y': {
                'you win': {
                    'state': 'success'
                }
            }
        }
    }
    df2.load_transitions(transitions2)
    cdf = CompositeDialogueFlow('one:root', 'e', 'e')
    cdf.add_component(df, 'one')
    cdf.add_component(df2, 'two')
    cdf.set_state('one:root')

    cdf.system_turn()
    assert cdf.state() == ('one', 'test')
    cdf.user_turn('x', debugging=True)
    assert cdf.system_turn() == 'you win'
    assert cdf.state() == ('two', 'success')
예제 #9
0
    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(
        "start",
        initial_speaker=DialogueFlow.Speaker.USER,
        system_error_state="topic_err",
        user_error_state="topic_err",
    )
    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", 6), "$animal={catfish, dog}")
    cdf.add_user_transition("topic", ("two", 6), "$item={alaska, bark, down}")
    cdf.add_user_transition(("one", "A"), ("SYSTEM", "topic_err"), "back")