コード例 #1
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
コード例 #2
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"}
コード例 #3
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'}
コード例 #4
0
def test_user_multi_hop():
    df = DialogueFlow(States.A, initial_speaker=Speaker.USER)
    df.add_state(States.B, error_successor=States.B, user_multi_hop=True)
    df.add_state(States.C, error_successor=States.A, user_multi_hop=True)
    df.add_state(States.D, error_successor=States.A)
    df.add_state(States.E, error_successor=States.A)
    df.add_user_transition(States.A, States.B, "[{hey, hello}]")
    df.add_user_transition(States.A, States.C, "[{excuse, pardon}]")
    df.add_user_transition(States.B, States.D, "[how, you]")
    df.add_user_transition(States.C, States.E, "[{where, how, what}]")
    df.set_state(States.A)
    df.user_turn("hey", debugging=False)
    assert df.state() == States.B
    df.set_state(States.A)
    df.set_speaker(Speaker.USER)
    df.user_turn("hey how are you")
    assert df.state() == States.D
    df.set_state(States.A)
    df.set_speaker(Speaker.USER)
    df.user_turn("excuse me where do i go")
    assert df.state() == States.E
    df.set_state(States.A)
    df.set_speaker(Speaker.USER)
    df.user_turn("excuse me")
    assert df.state() == States.A