Beispiel #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()
Beispiel #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()
Beispiel #3
0
def test_unknown_person():
    last_output = ""

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

        @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", "verbaliser", "idle", "interloc",
                     "nlp", "persqa", "hibye", "visionio", "visionio_test",
                     "-d", "ontology", "neo4j_pw", "test")

    @rs.receptor(ctx_wrap=ctx, write=visionio.prop_subscribe_faces)
    def unknown_person_approaches(ctx: rs.ContextWrapper):
        faces = Faces()
        faces.confidence = [0.5]
        faces.ids = [42]

        facial_features = FacialFeatures()
        facial_features.ff = np.zeros(128)
        faces.face_encodings = [facial_features]

        ctx[visionio.prop_subscribe_faces] = faces

    mem.initialized.clear()
    ctx.emit(rs.sig_startup)
    ctx.run_once()
    assert mem.initialized.wait()

    # Vision io is started
    assert visionio.reset.wait()

    unknown_person_approaches()

    # Wait until greeted
    counter = 0
    while not raw_out.wait(.1) and counter < 100:
        ctx.run_once()
        counter += 1
    assert last_output in verbaliser.get_phrase_list("greeting")

    assert visionio.recognize_faces.wait(0)

    ctx.shutdown()
    # Unfortunately needed until Context adopts Properties as clones.
    interloc.prop_all.children.clear()
Beispiel #4
0
def test_roboyqa():
    phrases = (
        "who are you?",
        "what is your name?",
        "how old are you?",
        "what is your age?",
        "what is your hobby?",
        "what are your hobbies?",
        "what do you like?",
        "where are you from?",
        "where do you live?",
        "who is your father/dad?",
        "who is your brother/sibling?",
        "who is your friend?",
        "what do you want to become?",
        # "what are you a member of?",
        "what can you do?",
        "what are your skills?",
        "what have you learned?",
        "what are your abilities?")

    last_output = ""

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

        @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", "nlp", "idle", "verbaliser",
                     "roboyqa", "roboyqa_test", "-d", "ontology", "neo4j_pw",
                     "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()

    for phrase in phrases:
        say(phrase)
        while not raw_out.wait(.1):
            ctx.run_once()
Beispiel #5
0
def test_known_person():
    last_output = ""

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

        @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]}")

    # Unfortunately needed until Context adopts Properties as clones.
    interloc.prop_all.children.clear()
    ctx = rs.Context("rawio", "ontology", "verbaliser", "idle", "interloc",
                     "nlp", "hibye", "visionio", "visionio_test", "-d",
                     "ontology", "neo4j_pw", "test")

    def register_dummy_known_person_to_db():
        onto: Ontology = mem.get_ontology()
        sess: Session = mem.get_session()
        person_node = Node(metatype=onto.get_type("Person"))
        person_node.set_properties({'name': 'visionio_test_person'})
        person_node = sess.create(person_node)
        return person_node

    def delete_dummy_people():
        onto: Ontology = mem.get_ontology()
        sess: Session = mem.get_session()
        person_node = Node(metatype=onto.get_type("Person"))
        person_node.set_properties({'name': 'visionio_test_person'})
        # TODO: Delete method is not working!
        sess.delete(person_node)

    @rs.receptor(ctx_wrap=ctx, write=visionio.prop_subscribe_faces)
    def known_person_approaches(ctx: rs.ContextWrapper):
        person = register_dummy_known_person_to_db()

        faces = Faces()
        faces.confidence = [0.85]
        faces.ids = [person.get_id()]

        facial_features = FacialFeatures()
        facial_features.ff = np.zeros(128)
        faces.face_encodings = [facial_features]

        ctx[visionio.prop_subscribe_faces] = faces

    mem.initialized.clear()
    ctx.emit(rs.sig_startup)
    ctx.run_once()
    assert mem.initialized.wait()

    # Vision io is started
    assert visionio.reset.wait()

    known_person_approaches()

    # Wait until greeted
    counter = 0
    while not raw_out.wait(.1) and counter < 100:
        ctx.run_once()
        counter += 1
    greeting_phrases = [
        phrase.replace('{name}', 'visionio_test_person')
        for phrase in verbaliser.get_phrase_list("greeting-with-name")
    ]
    assert last_output in greeting_phrases

    assert visionio.recognize_faces.wait(0)

    ctx.shutdown()
    delete_dummy_people()
    # Unfortunately needed until Context adopts Properties as clones.
    interloc.prop_all.children.clear()
Beispiel #6
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()
Beispiel #7
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()