Beispiel #1
0
 def _bootstrap_telegram_child():
     """
     Handle TelegramIO as a Child Process.
     Listen to Pipe and handle incoming texts and photos.
     """
     try:
         while not ctx.shutting_down():
             # receive Bot,Update for telegram chat
             bot, update = child_conn.recv()  # blocking
             if update.effective_message.photo:
                 handle_photo(bot, update)
             elif update.effective_message.text:
                 if update.effective_message.text.strip().lower(
                 ) in verbaliser.get_phrase_list("farewells"):
                     send_on_telegram(
                         ctx, verbaliser.get_random_phrase("farewells"))
                     logger.info("Shutting down child process")
                     ctx.shutdown()
                 handle_text(bot, update)
             else:
                 logger.error(
                     f"{MODULE_NAME} received an update it cannot handle.")
     except EOFError:
         # Pipe was closed -> Parent was killed or parent has closed the pipe
         logger.info(
             "Pipe was closed, therefore the telegram-child will shut down."
         )
         ctx.shutdown()
Beispiel #2
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 #3
0
 def recognize_intent_bye(ctx):
     input_value = (ctx[rawio.prop_in] or "").strip().lower()
     if input_value in verbaliser.get_phrase_list(lang.intent_farewells):
         return rs.Emit()
Beispiel #4
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 #5
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 #6
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()