Esempio n. 1
0
def test_run_qa():
    last_output = ""

    with rs.Module(name="persqa_test"):

        @rs.state(cond=rs.sig_startup, write=rawio.prop_in)
        def persqa_hi(ctx: rs.ContextWrapper):
            ctx[rawio.prop_in] = "hi"

        @rs.state(read=rawio.prop_out)
        def raw_out(ctx: rs.ContextWrapper):
            nonlocal last_output
            last_output = ctx[rawio.prop_out]
            logger.info(f"Output: {ctx[rawio.prop_out]}")

    ctx = rs.Context("rawio", "ontology", "idle", "interloc", "nlp", "persqa",
                     "persqa_test")

    @rs.receptor(ctx_wrap=ctx, write=rawio.prop_in)
    def say(ctx: rs.ContextWrapper, what: str):
        ctx[rawio.prop_in] = what

    ctx.emit(rs.sig_startup)
    while not persqa_hi.wait(.1):
        ctx.run_once(debug=True)
        ctx.test()

    # Wait for name being asked
    while not raw_out.wait(.1):
        ctx.run_once(debug=True)
        ctx.test()
    assert last_output in verbaliser.get_question_list("NAME")

    # Say name
    say("Herbert")

    # Wait for acknowledgement of name
    while not raw_out.wait(.1):
        ctx.run_once()

    assert persqa.inference.wait(0)
    assert persqa.react.wait(0)
    assert "herbert" in last_output.lower()

    # Wait for any other question via idle:bored
    while not raw_out.wait(.1):
        ctx.run_once()

    # Roboy now asked some predicate. Let's give some response.
    say("Big Brother")

    # Wait for Roboy's reaction.
    while not raw_out.wait(.1):
        ctx.run_once()

    assert persqa.inference.wait(0)
    assert persqa.react.wait(0)

    # Unfortunately needed until Context adopts Properties as clones.
    interloc.prop_all.children.clear()
Esempio n. 2
0
def test_decline_offer():
    last_output = ""

    with rs.Module(name="luigi_test"):

        @rs.state(cond=rs.sig_startup, read=interloc.prop_all)
        def luigi_hi(ctx: rs.ContextWrapper):
            ravestate_ontology.initialized.wait()
            interloc.handle_single_interlocutor_input(ctx, "hi")

        @rs.state(cond=rs.sig_shutdown, read=interloc.prop_all)
        def luigi_bye(ctx: rs.ContextWrapper):
            interloc.handle_single_interlocutor_input(ctx, "bye")

        @rs.state(read=rawio.prop_out)
        def raw_out(ctx: rs.ContextWrapper):
            nonlocal last_output
            last_output = ctx[rawio.prop_out]
            logger.info(f"Output: {ctx[rawio.prop_out]}")

    ctx = rs.Context("rawio", "ontology", "idle", "interloc", "nlp", "Luigi",
                     "luigi_test")

    @rs.receptor(ctx_wrap=ctx, write=rawio.prop_in)
    def say(ctx: rs.ContextWrapper, what: str):
        ctx[rawio.prop_in] = what

    ctx.emit(rs.sig_startup)
    ctx.run_once()

    assert luigi_hi.wait()

    # Wait for greeting

    while not raw_out.wait(.1):
        ctx.run_once()
    # Wait for greeting

    while not raw_out.wait(.1):
        ctx.run_once()
    assert last_output in verbaliser.get_question_list("greet_general")

    say("no")

    # Wait for acknowledgement of answer

    while not raw_out.wait(.1):
        ctx.run_once()
    assert last_output in verbaliser.get_failure_answer_list("greet_general")

    ctx.run_once()
    assert luigi.analyse_ice_cream_suggestion_answer.wait()

    ctx.emit(rs.sig_shutdown)
    ctx.run_once()
    assert luigi_bye.wait()

    ctx.run_once()
    assert luigi.customer_left.wait()
Esempio n. 3
0
def test_legit_order():
    last_output = ""

    with rs.Module(name="luigi_test"):

        @rs.state(cond=rs.sig_startup, read=interloc.prop_all)
        def luigi_hi(ctx: rs.ContextWrapper):
            ravestate_ontology.initialized.wait()
            interloc.handle_single_interlocutor_input(ctx, "hi")

        @rs.state(cond=rs.sig_shutdown, read=interloc.prop_all)
        def luigi_bye(ctx: rs.ContextWrapper):
            interloc.handle_single_interlocutor_input(ctx, "bye")

        @rs.state(read=rawio.prop_out)
        def raw_out(ctx: rs.ContextWrapper):
            nonlocal last_output
            last_output = ctx[rawio.prop_out]
            logger.info(f"Output: {ctx[rawio.prop_out]}")

    ctx = rs.Context("rawio", "ontology", "idle", "interloc", "nlp", "Luigi",
                     "luigi_test")

    @rs.receptor(ctx_wrap=ctx, write=rawio.prop_in)
    def say(ctx: rs.ContextWrapper, what: str):
        ctx[rawio.prop_in] = what

    ctx.emit(rs.sig_startup)
    ctx.run_once()

    assert luigi_hi.wait()

    # Wait for greeting

    while not raw_out.wait(.1):
        ctx.run_once()

    while not raw_out.wait(.1):
        ctx.run_once()
    assert last_output in verbaliser.get_question_list("greet_general")

    say("yes")

    # Wait for acknowledgement of answer

    while not raw_out.wait(.1):
        ctx.run_once()
    assert luigi.analyse_ice_cream_suggestion_answer.wait()
    assert last_output in verbaliser.get_successful_answer_list(
        "greet_general")

    say("three scoops of vanilla")

    # Wait for acknowledgement of answer

    while not raw_out.wait(.1):
        ctx.run_once()
    assert luigi.detect_flavors_and_scoops.wait()
    assert last_output.replace(
        "3 scoops of vanillla",
        "{order}") in verbaliser.get_phrase_list("legit_order")

    say("yes")

    # Wait for acknowledgement of answer
    while not raw_out.wait(0.1):
        ctx.run_once()

    assert luigi.analyse_finish_order_answer.wait()
    assert last_output.replace(
        "3 scoops of vanillla",
        "{order}") in verbaliser.get_phrase_list("preparing_order")

    ctx.emit(rs.sig_shutdown)
    ctx.run_once()
    assert luigi_bye.wait()

    ctx.run_once()
    assert luigi.customer_left.wait()
Esempio n. 4
0
def test_legit_order_need_flavor():
    last_output = ""

    with rs.Module(name="luigi_test"):

        @rs.state(cond=rs.sig_startup, read=interloc.prop_all)
        def luigi_hi(ctx: rs.ContextWrapper):
            ravestate_ontology.initialized.wait()
            interloc.handle_single_interlocutor_input(ctx, "hi")

        @rs.state(cond=rs.sig_shutdown, read=interloc.prop_all)
        def luigi_bye(ctx: rs.ContextWrapper):
            interloc.handle_single_interlocutor_input(ctx, "bye")

        @rs.state(read=rawio.prop_out)
        def raw_out(ctx: rs.ContextWrapper):
            nonlocal last_output
            last_output = ctx[rawio.prop_out]
            logger.info(f"Output: {ctx[rawio.prop_out]}")

    ctx = rs.Context("rawio", "ontology", "idle", "interloc", "nlp", "Luigi",
                     "luigi_test")

    @rs.receptor(ctx_wrap=ctx, write=rawio.prop_in)
    def say(ctx: rs.ContextWrapper, what: str):
        ctx[rawio.prop_in] = what

    ctx.emit(rs.sig_startup)
    ctx.run_once()

    assert luigi_hi.wait()

    # Wait for greeting

    while not raw_out.wait(.1):
        ctx.run_once()

    while not raw_out.wait(.1):
        ctx.run_once()
    assert last_output in verbaliser.get_question_list("greet_general")

    # Legit order

    say("chocolate two")

    # Wait for acknowledgement of order

    while not raw_out.wait(.1):
        ctx.run_once()

    assert luigi.detect_flavors_and_scoops.wait()
    assert luigi.check_scoops_flavor_combined.wait()
    assert last_output.replace(
        "2 scoops of choclate",
        "{order}") in verbaliser.get_phrase_list("legit_order")

    say("no")

    # Wait for acknowledgement of answer

    while not raw_out.wait(.1):
        ctx.run_once()
    assert luigi.analyse_finish_order_answer.wait()
    assert last_output in verbaliser.get_phrase_list("continue_order")
    # Only give flavor

    say("one")

    # Wait for acknowledgement of flavor

    while not raw_out.wait(.1):
        ctx.run_once()
    assert luigi.detect_flavors_and_scoops.wait()
    assert last_output.replace("scoop", "scoop{s}").replace(
        "1", "{scoop}") in verbaliser.get_phrase_list("need_flavor")

    # Only give scoops

    say("vanilla")

    # Wait for acknowledgement of scoop

    while not raw_out.wait(.1):
        ctx.run_once()
    assert luigi.detect_flavors_and_scoops.wait()
    assert luigi.check_scoops_flavor_combined.wait()
    assert last_output.replace("1 scoop of vanillla and 2 scoops of choclate", "{order}") in \
           verbaliser.get_phrase_list("legit_order")

    # Order is finished

    say("yes")

    # Wait for acknowledgement of answer

    while not raw_out.wait(.1):
        ctx.run_once()

    ctx.emit(rs.sig_shutdown)
    ctx.run_once()
    assert luigi_bye.wait()