Beispiel #1
0
def test_virtual_transitions():
    df = DialogueFlow('root')
    transitions = {
        'state': 'root',
        'hello': {
            'state': 'test',
            'a': {
                'something typical': 'nope'
            },
            '#VT(other)': 'blah'
        },
        'not taken': {
            'state': 'other',
            'score': 0,
            'x': {
                'you win': {
                    'state': 'success'
                }
            },
            'y': {
                'you win': {
                    'state': 'success'
                }
            }
        }
    }
    df.load_transitions(transitions)
    df.system_turn()
    assert df.state() == 'test'
    df.user_turn('x', debugging=True)
    assert df.system_turn() == 'you win'
    assert df.state() == 'success'
Beispiel #2
0
def test_virtual_transitions():
    df = DialogueFlow("root")
    transitions = {
        "state": "root",
        "hello": {
            "state": "test",
            "a": {
                "something typical": "nope"
            },
            "#VT(other)": "blah",
        },
        "not taken": {
            "state": "other",
            "score": 0,
            "x": {
                "you win": {
                    "state": "success"
                }
            },
            "y": {
                "you win": {
                    "state": "success"
                }
            },
        },
    }
    df.load_transitions(transitions)
    df.system_turn()
    assert df.state() == "test"
    df.user_turn("x", debugging=True)
    assert df.system_turn() == "you win"
    assert df.state() == "success"
Beispiel #3
0
def test_reset():
    df = DialogueFlow(States.A, initial_speaker=Speaker.SYSTEM)
    df.add_state(States.B, error_successor=States.E)
    df.add_state(States.C, error_successor=States.E)
    df.add_system_transition(States.A, States.B, "B")
    df.add_system_transition(States.A, States.C, "C")
    df.add_system_transition(States.E, States.E, "E")

    # response = df.system_turn()
    df.system_turn()
    df.user_turn("")
    assert df.state() == States.E

    df.reset()
    assert df.state() == "States.A"
    assert df.speaker() == Speaker.SYSTEM
    # response = df.system_turn()
    df.system_turn()
    df.user_turn("")
    assert df.state() == States.E
    df.system_turn()
    assert df.state() == States.E

    df.reset()
    assert df.state() == States.A
    assert df.speaker() == Speaker.SYSTEM
    # response = df.system_turn()
    df.system_turn()
    df.user_turn("")
    assert df.state() == States.E
    df.system_turn()
    assert df.state() == States.E
Beispiel #4
0
def test_gate_none():
    df = DialogueFlow('root')
    transitions = {
        'state': 'root',

        '#GATE(var:None) hello': {
            'state': 'greet',
            'score': 2.0,

            'hi': {
                '#SET($var=True) how are ya': {'error': 'root'}
            },
            'error': {
                'how are you': {'error': 'root'}
            }
        },
        'hi': 'greet'
    }
    df.load_transitions(transitions)
    assert df.system_turn().strip() == 'hello'
    df.user_turn('hi')
    assert df.system_turn().strip() == 'how are ya'
    df.user_turn('fine')
    assert df.system_turn().strip() == 'hi'
    df.user_turn('oh')
    assert df.system_turn().strip() == 'how are you'
Beispiel #5
0
def test_enter_natex():
    df = DialogueFlow('root')
    transitions = {
        'state': 'root',

        'hello': {
            'state': 'one',
            'score': 2.0,
            'enter': '#GATE',

            'error': 'root'
        },
        'hi': {
            'state': 'two',
            'score': 1.0,
            'enter': '#GATE',

            'error': 'root'
        },
        'bye': {
            'state': 'one',
            'score': 1.0,
        },
        'goodbye': {
            'state': 'three',
            'score': 0.0,
            'error': 'end'
        }
    }
    df.load_transitions(transitions)
    assert df.system_turn() == 'hello'
    df.user_turn('hello')
    assert df.system_turn() == 'hi'
    df.user_turn('hi')
    assert df.system_turn() == 'goodbye'
Beispiel #6
0
def test_information_state_state_set():
    df = DialogueFlow('root', initial_speaker=Speaker.USER)
    transitions = {
        'state': 'root',
        'error': {
            'state': 'one',
            'okay': {
                'state': 'two',
                'error': {
                    'state': 'three',
                    'sure': 'root'
                }
            }
        },
        'something': {
            'state': 'special',
            'that is great': 'root'
        }
    }
    df.add_update_rule('[{read, watched}]', '#TRANSITION(special, 2.0)')
    df.load_transitions(transitions, speaker=Speaker.USER)
    df.user_turn('hi')
    assert df.system_turn() == 'okay'
    df.user_turn('i read a book')
    assert df.state() == 'special'
    assert df.system_turn() == 'that is great'
    assert df.state() == 'root'
Beispiel #7
0
def test_transitions_to_transitions():
    df = DialogueFlow("root", initial_speaker=Speaker.SYSTEM)
    transitions = {
        "state": "root",
        '"Hello World!"': {"state": "state_2", "error": {'"Hi,"': "root->state_2"}},
    }
    df.load_transitions(transitions, speaker=Speaker.SYSTEM)
    assert df.system_turn() == "Hello World!"
    df.user_turn("blah")
    assert df.system_turn() == "Hi, Hello World!"
Beispiel #8
0
def test_global_transition_list_disjunction():
    df = DialogueFlow("root", initial_speaker=Speaker.USER)
    nlu = ["hi", "hello"]
    df.add_state("root", "x")
    df.add_system_transition("x", "y", "hello")
    df.add_global_nlu("x", nlu)
    df.user_turn("ok")
    df.system_turn()
    df.user_turn("hi")
    assert df.state() == "x"
Beispiel #9
0
def test_global_transition_list_disjunction():
    df = DialogueFlow('root', initial_speaker=Speaker.USER)
    nlu = [
        'hi',
        'hello'
    ]
    df.add_state('root', 'x')
    df.add_system_transition('x', 'y', 'hello')
    df.add_global_nlu('x', nlu)
    df.user_turn('ok')
    df.system_turn()
    df.user_turn('hi')
    assert df.state() == 'x'
Beispiel #10
0
def test_global_transition_priority():
    df = DialogueFlow("root")
    transitions = {
        "state": "root",
        "hello": {
            "[oh]": {"score": 0.6, "okay": {}},
            "[wow]": {"score": 2.0, "alright": {}},
        },
    }
    df.add_global_nlu("root", "/.*/", score=0.7)
    df.load_transitions(transitions)
    df.system_turn()
    df.user_turn("oh wow")
    assert df.system_turn() == "alright"
Beispiel #11
0
def test_unexpected_input_macro():
    df = DialogueFlow("root", initial_speaker=Speaker.USER)
    df.add_user_transition("root", "x", "#UNX")
    df.add_system_transition("x", "y", '"So, whats for dinner?"')
    df.user_turn("blah blah blah blah blah blah")
    tokens = df.system_turn().split()
    assert len(tokens) > 4 and "So, whats for dinner?" == " ".join(tokens[-4:])
Beispiel #12
0
def test_unexpected_input_macro():
    df = DialogueFlow('root', initial_speaker=Speaker.USER)
    df.add_user_transition('root', 'x', '#UNX')
    df.add_system_transition('x', 'y', '"So, whats for dinner?"')
    df.user_turn('blah blah blah blah blah blah')
    tokens = df.system_turn().split()
    assert len(tokens) > 4 and 'So, whats for dinner?' == ' '.join(tokens[-4:])
Beispiel #13
0
def test_transitions_to_transitions():
    df = DialogueFlow('root', initial_speaker=Speaker.SYSTEM)
    transitions = {
        'state': 'root',

        '"Hello World!"': {
            'state': 'state_2',

            'error': {
                '"Hi,"': 'root->state_2'
            }
        }
    }
    df.load_transitions(transitions, speaker=Speaker.SYSTEM)
    assert df.system_turn() == 'Hello World!'
    df.user_turn('blah')
    assert df.system_turn() == 'Hi, Hello World!'
Beispiel #14
0
def test_reset():
    df = DialogueFlow(States.A, initial_speaker=Speaker.SYSTEM)
    df.add_state(States.B, error_successor=States.E)
    df.add_state(States.C, error_successor=States.E)
    df.add_system_transition(States.A, States.B, 'B')
    df.add_system_transition(States.A, States.C, 'C')
    df.add_system_transition(States.E, States.E, 'E')

    response = df.system_turn()
    df.user_turn("")
    assert df.state() == States.E

    df.reset()
    assert df.state() == 'States.A'
    assert df.speaker() == Speaker.SYSTEM
    response = df.system_turn()
    df.user_turn("")
    assert df.state() == States.E
    df.system_turn()
    assert df.state() == States.E

    df.reset()
    assert df.state() == States.A
    assert df.speaker() == Speaker.SYSTEM
    response = df.system_turn()
    df.user_turn("")
    assert df.state() == States.E
    df.system_turn()
    assert df.state() == States.E
Beispiel #15
0
def test_information_state_state_set():
    df = DialogueFlow("root", initial_speaker=Speaker.USER)
    transitions = {
        "state": "root",
        "error": {
            "state": "one",
            "okay": {"state": "two", "error": {"state": "three", "sure": "root"}},
        },
        "something": {"state": "special", "that is great": "root"},
    }
    df.add_update_rule("[{read, watched}]", "#TRANSITION(special, 2.0)")
    df.load_transitions(transitions, speaker=Speaker.USER)
    df.user_turn("hi")
    assert df.system_turn() == "okay"
    df.user_turn("i read a book")
    assert df.state() == "special"
    assert df.system_turn() == "that is great"
    assert df.state() == "root"
Beispiel #16
0
def test_enter_natex():
    df = DialogueFlow("root")
    transitions = {
        "state": "root",
        "hello": {"state": "one", "score": 2.0, "enter": "#GATE", "error": "root"},
        "hi": {"state": "two", "score": 1.0, "enter": "#GATE", "error": "root"},
        "bye": {
            "state": "one",
            "score": 1.0,
        },
        "goodbye": {"state": "three", "score": 0.0, "error": "end"},
    }
    df.load_transitions(transitions)
    assert df.system_turn() == "hello"
    df.user_turn("hello")
    assert df.system_turn() == "hi"
    df.user_turn("hi")
    assert df.system_turn() == "goodbye"
Beispiel #17
0
def test_information_state_based_dialogue():
    df = DialogueFlow("root", initial_speaker=Speaker.USER)
    df.add_user_transition("root", "one", "$x=[{cat, dog}]")
    df.set_error_successor("root", "one")
    df.add_system_transition("one", "root", "i am a stupid state machine")
    df.add_update_rule("[$x={ice cream, candy}]")
    df.add_update_rule("#ANY($x=candy)", "$y=blah")
    df.add_update_rule("#ANY($x=ice cream)", "$y=None")
    df.add_update_rule("#ANY($y=blah)", "i am a smart info state manager (2.0)")

    df.user_turn("candy", debugging=True)
    assert df.system_turn().strip() == "i am a smart info state manager"
    df.user_turn("ice cream", debugging=True)
    assert df.system_turn(debugging=True).strip() == "i am a stupid state machine"
    df.user_turn("ice cream", debugging=True)
    assert df.system_turn(debugging=True).strip() == "i am a stupid state machine"
    df.user_turn("ice cream", debugging=True)
    assert df.system_turn(debugging=True).strip() == "i am a stupid state machine"
    df.user_turn("ice cream", debugging=True)
    assert df.system_turn(debugging=True).strip() == "i am a stupid state machine"
Beispiel #18
0
def test_global_transition_priority():
    df = DialogueFlow('root')
    transitions = {
        'state': 'root',
        'hello':{
            '[oh]':{
                'score': 0.6,
                'okay':{}
            },
            '[wow]':{
                'score': 2.0,
                'alright': {}
            }
        }
    }
    df.add_global_nlu('root', '/.*/', score=0.7)
    df.load_transitions(transitions)
    df.system_turn()
    df.user_turn('oh wow')
    assert df.system_turn() == 'alright'
Beispiel #19
0
def test_information_state_based_dialogue():
    df = DialogueFlow('root', initial_speaker=Speaker.USER)
    df.add_user_transition('root', 'one', '$x=[{cat, dog}]')
    df.set_error_successor('root', 'one')
    df.add_system_transition('one', 'root', 'i am a stupid state machine')
    df.add_update_rule('[$x={ice cream, candy}]')
    df.add_update_rule('#ANY($x=candy)', '$y=blah')
    df.add_update_rule('#ANY($x=ice cream)', '$y=None')
    df.add_update_rule('#ANY($y=blah)', 'i am a smart info state manager (2.0)')

    df.user_turn('candy', debugging=True)
    assert df.system_turn().strip() == 'i am a smart info state manager'
    df.user_turn('ice cream', debugging=True)
    assert df.system_turn(debugging=True).strip() == 'i am a stupid state machine'
    df.user_turn('ice cream', debugging=True)
    assert df.system_turn(debugging=True).strip() == 'i am a stupid state machine'
    df.user_turn('ice cream', debugging=True)
    assert df.system_turn(debugging=True).strip() == 'i am a stupid state machine'
    df.user_turn('ice cream', debugging=True)
    assert df.system_turn(debugging=True).strip() == 'i am a stupid state machine'
Beispiel #20
0
def test_gate_none():
    df = DialogueFlow("root")
    transitions = {
        "state": "root",
        "#GATE(var:None) hello": {
            "state": "greet",
            "score": 2.0,
            "hi": {"#SET($var=True) how are ya": {"error": "root"}},
            "error": {"how are you": {"error": "root"}},
        },
        "hi": "greet",
    }
    df.load_transitions(transitions)
    assert df.system_turn().strip() == "hello"
    df.user_turn("hi")
    assert df.system_turn().strip() == "how are ya"
    df.user_turn("fine")
    assert df.system_turn().strip() == "hi"
    df.user_turn("oh")
    assert df.system_turn().strip() == "how are you"
Beispiel #21
0
def test_ontology():
    kb = KnowledgeBase()
    ontology = {
        "ontology": {
            "season": [
                "fall",
                "spring",
                "summer",
                "winter"
            ],
            "month": [
                "january",
                "february",
                "march",
                "april",
                "may",
                "june",
                "july",
                "august",
                "september",
                "october",
                "november",
                "december"
            ]
        }
    }
    kb.load_json(ontology)
    df = DialogueFlow(States.A, Speaker.USER, kb=kb)
    df.add_state(States.A)
    df.add_state(States.B)
    df.add_state(States.C)
    df.add_state(States.D)
    df.add_state(States.E)
    df.set_error_successor(States.A, States.E)
    df.set_error_successor(States.B, States.E)
    df.set_error_successor(States.C, States.E)
    df.set_error_successor(States.D, States.E)
    df.add_user_transition(States.A, States.B, "[#ONT(month)]")
    df.add_system_transition(States.B, States.C, "B to C")
    df.add_user_transition(States.C, States.D, "[$m=#ONT(month), $s=#ONT(season)]")

    df.user_turn("january")
    assert df.state() == States.B
    assert df.system_turn() == "B to C"
    df.user_turn("october is in the fall season")
    assert df.state() == States.D
    assert df._vars["m"] == "october"
    assert df._vars["s"] == "fall"

    df.set_state(States.A)
    df.set_speaker(Speaker.USER)
    df.user_turn("hello there", debugging=False)
    assert df.state() == States.E
Beispiel #22
0
def test_serialization():
    df = DialogueFlow(States.A, initial_speaker=Speaker.SYSTEM)
    df.add_state(States.B, error_successor=States.E)
    df.add_state(States.C, error_successor=States.E)
    df.add_system_transition(States.A, States.B, '#GATE $spoken=B')
    df.add_system_transition(States.A, States.C, '#GATE(spoken) $spoken=C')
    df.add_system_transition(States.E, States.E, '$spoken=E')
    df.add_user_transition(States.B, States.A, '$heard=b')
    df.add_user_transition(States.E, States.A, '$heard=e')

    df.system_turn()
    assert df.state() == States.B
    assert df.vars()["spoken"] == "B"
    df.user_turn('b')
    df.system_turn()
    assert df.state() == States.C
    assert df.vars()["spoken"] == "C"
    expected_gates = {'States.B': [{}], 'States.C': [{'spoken': 'B'}]}
    assert df.gates() == expected_gates
    df.vars()["testing_none"] = None
    d = df.serialize()

    df2 = DialogueFlow(States.A, initial_speaker=Speaker.SYSTEM)
    df2.add_state(States.B, error_successor=States.E)
    df2.add_state(States.C, error_successor=States.E)
    df2.add_system_transition(States.A, States.B, '#GATE $spoken=B')
    df2.add_system_transition(States.A, States.C, '#GATE(spoken) $spoken=C')
    df2.add_system_transition(States.E, States.E, '$spoken=E')
    df2.add_user_transition(States.B, States.A, '$heard=b')
    df2.add_user_transition(States.E, States.A, '$heard=e')
    assert df2.state() == States.A
    assert 'spoken' not in df2.vars() and 'heard' not in df2.vars()
    assert len(df2.gates()) == 0

    df2.deserialize(d)

    assert df.vars() == df2.vars()
    assert df.gates() == df2.gates()
    assert df.state() == df2.state()
    assert df2.vars()["testing_none"] is None
Beispiel #23
0
def test_serialization():
    df = DialogueFlow(States.A, initial_speaker=Speaker.SYSTEM)
    df.add_state(States.B, error_successor=States.E)
    df.add_state(States.C, error_successor=States.E)
    df.add_system_transition(States.A, States.B, "#GATE $spoken=B")
    df.add_system_transition(States.A, States.C, "#GATE(spoken) $spoken=C")
    df.add_system_transition(States.E, States.E, "$spoken=E")
    df.add_user_transition(States.B, States.A, "$heard=b")
    df.add_user_transition(States.E, States.A, "$heard=e")

    df.system_turn()
    assert df.state() == States.B
    assert df.vars()["spoken"] == "B"
    df.user_turn("b")
    df.system_turn()
    assert df.state() == States.C
    assert df.vars()["spoken"] == "C"
    expected_gates = {"States.B": [{}], "States.C": [{"spoken": "B"}]}
    assert df.gates() == expected_gates
    df.vars()["testing_none"] = None
    d = df.serialize()

    df2 = DialogueFlow(States.A, initial_speaker=Speaker.SYSTEM)
    df2.add_state(States.B, error_successor=States.E)
    df2.add_state(States.C, error_successor=States.E)
    df2.add_system_transition(States.A, States.B, "#GATE $spoken=B")
    df2.add_system_transition(States.A, States.C, "#GATE(spoken) $spoken=C")
    df2.add_system_transition(States.E, States.E, "$spoken=E")
    df2.add_user_transition(States.B, States.A, "$heard=b")
    df2.add_user_transition(States.E, States.A, "$heard=e")
    assert df2.state() == States.A
    assert "spoken" not in df2.vars() and "heard" not in df2.vars()
    assert len(df2.gates()) == 0

    df2.deserialize(d)

    assert df.vars() == df2.vars()
    assert df.gates() == df2.gates()
    assert df.state() == df2.state()
    assert df2.vars()["testing_none"] is None
Beispiel #24
0
def test_system_multi_hop():
    df = DialogueFlow(States.A, initial_speaker=Speaker.SYSTEM)
    df.add_state(States.B, error_successor=States.B, system_multi_hop=True)
    df.add_state(States.C, error_successor=States.A, system_multi_hop=True)
    df.add_state(States.D, error_successor=States.A)
    df.add_state(States.E, error_successor=States.A)
    df.add_system_transition(States.A, States.B, "{hey, hello}")
    df.add_system_transition(States.A, States.C, "excuse me")
    df.add_system_transition(States.B, States.D, "how are you")
    df.add_system_transition(States.C, States.E, "what")
    for _ in range(100):
        df.set_state(States.A)
        df.set_speaker(Speaker.SYSTEM)
        response = df.system_turn()
        assert response in {"hey how are you", "hello how are you", "excuse me what"}
Beispiel #25
0
def test_system_multi_hop():
    df = DialogueFlow(States.A, initial_speaker=Speaker.SYSTEM)
    df.add_state(States.B, error_successor=States.B, system_multi_hop=True)
    df.add_state(States.C, error_successor=States.A, system_multi_hop=True)
    df.add_state(States.D, error_successor=States.A)
    df.add_state(States.E, error_successor=States.A)
    df.add_system_transition(States.A, States.B, '{hey, hello}')
    df.add_system_transition(States.A, States.C, 'excuse me')
    df.add_system_transition(States.B, States.D, 'how are you')
    df.add_system_transition(States.C, States.E, 'what')
    for _ in range(100):
        df.set_state(States.A)
        df.set_speaker(Speaker.SYSTEM)
        response = df.system_turn()
        assert response in {'hey how are you', 'hello how are you',
                            'excuse me what'}
Beispiel #26
0
def test_stack():
    df = DialogueFlow("root")
    transitions = {
        "state": "root",
        "`What should I do?`": "gma_hospital",
        "#GOAL(grandma_hospital) #GATE"
        "`I cannot concentrate on a lot of things right now. "
        "My grandma is in the hospital. "
        "What should I do?`": {
            "state": "gma_hospital",
            "score": 2.0,
            "[{[{dont,shouldnt,not},worry],calm,relax,distract,[mind,off]}]": {
                "state": "dont_worry",
                "#GATE "
                "\"Okay, I will try my best not to worry. It's hard because she lives by "
                "herself and won't let anyone help her very much, so I feel like this "
                'will just happen again."': {
                    "state": "happen_again",
                    "[{sorry,sucks,hard}]": {
                        '"yeah, thanks."': {}
                    },
                    "[will,better]": {
                        '"I really hope you are right."': {}
                    },
                    "error": {
                        "state": "feel_better",
                        '"I actually feel a little bit better after talking with you. Thanks for listening. "':
                        {},
                    },
                },
                "#DEFAULT": "feel_better",
            },
            "#IDK": {
                '"yeah, i dont know either. Its so tough."': {}
            },
        },
    }

    gma = {
        "#GOAL(why_grandma_hospital) "
        "[{[why,hospital],wrong,happened}]": {
            "state": "why_grandma_hospital",
            '"She is just so frail. I can hardly believe it. '
            'She fell off of a stool in the kitchen and broke her hip."': {
                "[dont worry]": {"#GRET(grandma_hospital,dont_worry)"},
                "error": {
                    "#GRET": "return"
                },
            },
        },
        "#GOAL(grandma_hospital_before) "
        "[{has,was},{she,grandma},hospital,{before,earlier,previously}]": {
            "state": "grandma_hospital_before",
            '"No, this is the first time, thank goodness."': {
                "error": {
                    "#GRET": "return"
                }
            },
        },
    }

    df.load_transitions(transitions)
    df.load_transitions(gma, speaker=DialogueFlow.Speaker.USER)
    df.add_global_nlu(
        "why_grandma_hospital",
        "#GOAL(why_grandma_hospital) [{[why,hospital],wrong,happened}]",
        score=0.7,
    )
    df.add_global_nlu(
        "grandma_hospital_before",
        "#GOAL(grandma_hospital_before) [{has,was},{she,grandma},hospital,{before,earlier,previously}]",
        score=0.7,
    )

    # r = df.system_turn()
    df.system_turn()
    assert df.vars()["__goal__"] == "grandma_hospital"
    assert len(df.vars()["__stack__"]) == 0
    assert df.state() == "gma_hospital"

    df.user_turn("what happened")
    assert df.state() == "why_grandma_hospital"
    assert df.vars()["__goal_return_state__"] == "None"
    assert df.vars()["__goal__"] == "why_grandma_hospital"
    assert len(df.vars()["__stack__"]) == 1
    assert df.vars()["__stack__"][0][0] == "grandma_hospital"

    assert "fell off of a stool" in df.system_turn()
    df.user_turn("oh no", debugging=True)

    assert "What should I do" in df.system_turn(debugging=True)
    assert df.state() == "gma_hospital"
    assert df.vars()["__goal__"] == "grandma_hospital"
    assert len(df.vars()["__stack__"]) == 0

    df.user_turn("dont worry")
    assert df.state() == "dont_worry"
    assert "she lives by herself" in df.system_turn()

    df.user_turn("has your grandma been in the hospital before this")
    assert df.state() == "grandma_hospital_before"
    assert df.vars()["__goal__"] == "grandma_hospital_before"
    assert len(df.vars()["__stack__"]) == 1
    assert df.vars()["__stack__"][0][0] == "grandma_hospital"

    assert "this is the first time" in df.system_turn()

    df.user_turn("ok that is good")
    assert "feel a little bit better" in df.system_turn()
    assert df.vars()["__goal__"] == "grandma_hospital"
    assert len(df.vars()["__stack__"]) == 0
Beispiel #27
0
def test_stack():
    df = DialogueFlow('root')
    transitions = {
        'state': 'root',
        '`What should I do?`': 'gma_hospital',
        '#GOAL(grandma_hospital) #GATE'
        '`I cannot concentrate on a lot of things right now. '
        'My grandma is in the hospital. '
        'What should I do?`': {
            'state': 'gma_hospital',
            'score': 2.0,
            '[{[{dont,shouldnt,not},worry],calm,relax,distract,[mind,off]}]': {
                'state': 'dont_worry',
                '#GATE '
                '"Okay, I will try my best not to worry. It\'s hard because she lives by '
                'herself and won\'t let anyone help her very much, so I feel like this '
                'will just happen again."': {
                    'state': 'happen_again',
                    '[{sorry,sucks,hard}]': {
                        '"yeah, thanks."': {}
                    },
                    '[will,better]': {
                        '"I really hope you are right."': {}
                    },
                    'error': {
                        'state': 'feel_better',
                        '"I actually feel a little bit better after talking with you. Thanks for listening. "':
                        {}
                    }
                },
                '#DEFAULT': 'feel_better'
            },
            '#IDK': {
                '"yeah, i dont know either. Its so tough."': {}
            }
        }
    }

    gma = {
        '#GOAL(why_grandma_hospital) '
        '[{[why,hospital],wrong,happened}]': {
            'state': 'why_grandma_hospital',
            '"She is just so frail. I can hardly believe it. '
            'She fell off of a stool in the kitchen and broke her hip."': {
                '[dont worry]': {'#GRET(grandma_hospital,dont_worry)'},
                'error': {
                    '#GRET': 'return'
                }
            }
        },
        '#GOAL(grandma_hospital_before) '
        '[{has,was},{she,grandma},hospital,{before,earlier,previously}]': {
            'state': 'grandma_hospital_before',
            '"No, this is the first time, thank goodness."': {
                'error': {
                    '#GRET': 'return'
                }
            }
        }
    }

    df.load_transitions(transitions)
    df.load_transitions(gma, speaker=DialogueFlow.Speaker.USER)
    df.add_global_nlu(
        'why_grandma_hospital',
        '#GOAL(why_grandma_hospital) [{[why,hospital],wrong,happened}]',
        score=0.7)
    df.add_global_nlu(
        'grandma_hospital_before',
        '#GOAL(grandma_hospital_before) [{has,was},{she,grandma},hospital,{before,earlier,previously}]',
        score=0.7)

    r = df.system_turn()
    assert df.vars()['__goal__'] == 'grandma_hospital'
    assert len(df.vars()['__stack__']) == 0
    assert df.state() == 'gma_hospital'

    df.user_turn("what happened")
    assert df.state() == "why_grandma_hospital"
    assert df.vars()['__goal_return_state__'] == 'None'
    assert df.vars()['__goal__'] == 'why_grandma_hospital'
    assert len(df.vars()['__stack__']) == 1
    assert df.vars()['__stack__'][0][0] == 'grandma_hospital'

    assert "fell off of a stool" in df.system_turn()
    df.user_turn("oh no", debugging=True)

    assert "What should I do" in df.system_turn(debugging=True)
    assert df.state() == 'gma_hospital'
    assert df.vars()['__goal__'] == 'grandma_hospital'
    assert len(df.vars()['__stack__']) == 0

    df.user_turn("dont worry")
    assert df.state() == 'dont_worry'
    assert "she lives by herself" in df.system_turn()

    df.user_turn("has your grandma been in the hospital before this")
    assert df.state() == 'grandma_hospital_before'
    assert df.vars()['__goal__'] == 'grandma_hospital_before'
    assert len(df.vars()['__stack__']) == 1
    assert df.vars()['__stack__'][0][0] == 'grandma_hospital'

    assert "this is the first time" in df.system_turn()

    df.user_turn("ok that is good")
    assert "feel a little bit better" in df.system_turn()
    assert df.vars()['__goal__'] == 'grandma_hospital'
    assert len(df.vars()['__stack__']) == 0