예제 #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
    ("lion", "sound", "roar"),
    ("roar", "quality", "loud"),
    ("panther", "sound", "growl"),
    ("growl", "quality", "scary"),
    ("also", "type", "also_syns"),
    ("too", "type", "also_syns"),
    ("basketball", "type", "unknown_hobby"),
    ("basketball", "expr", "bball"),
    ("john", "type", "male"),
    ("mary", "type", "female"),
    ("male", "type", "person"),
    ("female", "type", "person"),
    ("friend", "type", "person"),
])
ont = {"ontology": {"person": ["mom", "dad", "sister", "brother"]}}
kb.load_json(ont)

df = DialogueFlow(initial_state="start")
df.add_state("start", "start")
df.add_system_transition("start", "start", "hello")

macros = {
    # "ONT": ONTE(kb),
    # "KBQ": KBE(kb),
    # "EXP": EXP(kb),
    # "U": UnionMacro(),
    # "I": Intersection(),
    # "DIF": Difference(),
    # "SET": SetVars(),
    # "ALL": CheckVarsConjunction(),
    # "ANY": CheckVarsDisjunction(),