Beispiel #1
0
def assert_phrases_file():
    assert_list_and_random(verbaliser.get_phrase_list('test1'), ['a', 'b', 'c', 'd'],
                           verbaliser.get_random_phrase('test1'))
    assert_list_and_random(verbaliser.get_phrase_list('test2'), ['a'],
                           verbaliser.get_random_phrase('test2'))
    assert_list_and_random(verbaliser.get_phrase_list('test3'), ['a', 'b'],
                           verbaliser.get_random_phrase('test3'))
Beispiel #2
0
    def console_input(ctx: ContextWrapper):
        @receptor(ctx_wrap=ctx, write="rawio:in")
        def write_console_input(ctx_input, value: str):
            ctx_input["rawio:in"] = value

        @receptor(ctx_wrap=ctx, write="interloc:all")
        def push_console_interloc(ctx: ContextWrapper, console_node: Node):
            if ctx.push(parentpath="interloc:all",
                        child=PropertyBase(name=DEFAULT_INTERLOC_ID,
                                           default_value=console_node)):
                logger.debug(f"Pushed {console_node} to interloc:all")

        @receptor(ctx_wrap=ctx, write="interloc:all")
        def pop_console_interloc(ctx: ContextWrapper):
            if ctx.pop(f"interloc:all:{DEFAULT_INTERLOC_ID}"):
                logger.debug(f"Popped interloc:all:{DEFAULT_INTERLOC_ID}")

        while not ctx.shutting_down():
            input_value = input("> ")
            write_console_input(input_value)

            console_interloc_exists = f"interloc:all:{DEFAULT_INTERLOC_ID}" in ctx.enum(
                "interloc:all")
            # push Node if you got a greeting
            if input_value.strip() in get_phrase_list(
                    "greeting") and not console_interloc_exists:
                # set up scientio
                sess: Session = ravestate_ontology.get_session()
                onto: Ontology = ravestate_ontology.get_ontology()

                # create scientio Node of type Person
                query = Node(metatype=onto.get_type("Person"))
                query.set_name("x")
                console_node_list = sess.retrieve(query)
                if not console_node_list:
                    console_node = sess.create(query)
                    logger.info(
                        f"Created new Node in scientio session: {console_node}"
                    )
                elif len(console_node_list) == 1:
                    console_node = console_node_list[0]
                else:
                    logger.error(
                        f'Found multiple Persons with name {DEFAULT_INTERLOC_ID} in scientio session. Cannot push node to interloc:all!'
                    )
                    continue

                # push interloc-Node
                push_console_interloc(console_node)

            # pop Node if you got a farewell
            elif input_value.strip() in get_phrase_list(
                    "farewells") and console_interloc_exists:
                pop_console_interloc()
Beispiel #3
0
def assert_mixed_file():
    assert_list_and_random(verbaliser.get_phrase_list('mixed_phrases1'), ['a', 'b', 'c', 'd'],
                           verbaliser.get_random_phrase('mixed_phrases1'))
    assert_list_and_random(verbaliser.get_phrase_list('mixed_phrases2'), ['a'],
                           verbaliser.get_random_phrase('mixed_phrases2'))

    assert_list_and_random(verbaliser.get_question_list('mixed_INTENT'), ['Q1', 'Q2', 'Q3'],
                           verbaliser.get_random_question('mixed_INTENT'))
    assert_list_and_random(verbaliser.get_successful_answer_list('mixed_INTENT'), ['SA1', 'SA2'],
                           verbaliser.get_random_successful_answer('mixed_INTENT'))
    assert_list_and_random(verbaliser.get_failure_answer_list('mixed_INTENT'), ['FA1'],
                           verbaliser.get_random_failure_answer('mixed_INTENT'))
    assert_list_and_random(verbaliser.get_followup_question_list('mixed_INTENT'), ['FUPQ1'],
                           verbaliser.get_random_followup_question('mixed_INTENT'))
    assert_list_and_random(verbaliser.get_followup_answer_list('mixed_INTENT'), ['FUPA1'],
                           verbaliser.get_random_followup_answer('mixed_INTENT'))
Beispiel #4
0
 def detections_understood(ctx: rs.ContextWrapper):
     detections = [
         ctx[prop_yesno_detection], ctx[prop_payment_option_detection],
         ctx[prop_ice_cream_desire_detection],
         ctx[prop_flavors_and_scoops_detection]
     ]
     ctx[prop_yesno_detection] = DetectionStates.NOT_SET
     ctx[prop_payment_option_detection] = DetectionStates.NOT_SET
     ctx[prop_ice_cream_desire_detection] = DetectionStates.NOT_SET
     ctx[prop_flavors_and_scoops_detection] = DetectionStates.NOT_SET
     for detection in detections:
         if detection == DetectionStates.IN:
             return
     if not (ctx[rawio.prop_out] in verbaliser.get_phrase_list(
             lang.intent_greeting)):
         ctx[rawio.prop_out] = verbaliser.get_random_phrase(
             "error_understanding")
Beispiel #5
0
def assert_nosection_file():
    assert_list_and_random(verbaliser.get_phrase_list('nosection1'),
                           ['a', 'b', 'c', 'd'],
                           verbaliser.get_random_phrase('nosection1'))
Beispiel #6
0
def handle_single_interlocutor_input(ctx: ContextWrapper,
                                     input_value: str,
                                     id="anonymous_interlocutor") -> None:
    """
    Forwards input to `rawio:in` and manages creation/deletion of a singleton
     interlocutor. A new interlocutor node is pushed, when the input is a greeting,
     and there is no interlocutor present. The interlocutor is popped,
     if the input is a farewell, and there is an interlocutor present.

    * `ctx`: Context Wrapper of the calling state. Must have read permissions
     for `interloc:all`.

    * `input_value`: The string input value that should be written to `rawio:in`.

    * `id`: Name of the interlocutor context property, and initial name for
     the interlocutor's Neo4j node (until a proper name is set by persqa).
    """
    @receptor(ctx_wrap=ctx, write="rawio:in")
    def write_input(ctx_input, value: str):
        ctx_input["rawio:in"] = value

    @receptor(ctx_wrap=ctx, write="interloc:all")
    def push_interloc(ctx: ContextWrapper, interlocutor_node: Node):
        if ctx.push(parentpath="interloc:all",
                    child=PropertyBase(name=id,
                                       default_value=interlocutor_node)):
            logger.debug(f"Pushed {interlocutor_node} to interloc:all")

    @receptor(ctx_wrap=ctx, write="interloc:all")
    def pop_interloc(ctx: ContextWrapper):
        if ctx.pop(f"interloc:all:{id}"):
            logger.debug(f"Popped interloc:all:{id}")

    write_input(input_value)

    interloc_exists = f"interloc:all:{id}" in ctx.enum("interloc:all")

    # push Node if you got a greeting
    if input_value.strip() in get_phrase_list(
            "greeting") and not interloc_exists:
        # set up scientio
        sess: Session = ravestate_ontology.get_session()
        onto: Ontology = ravestate_ontology.get_ontology()

        # create scientio Node of type Person
        query = Node(metatype=onto.get_type("Person"))
        query.set_name(id)
        interlocutor_node_list = sess.retrieve(query)
        if not interlocutor_node_list:
            interlocutor_node = sess.create(query)
            logger.info(
                f"Created new Node in scientio session: {interlocutor_node}")
        else:
            interlocutor_node = interlocutor_node_list[0]

        # push interloc-node
        push_interloc(interlocutor_node)

    # pop Node if you got a farewell
    elif input_value.strip() in get_phrase_list(
            "farewells") and interloc_exists:
        pop_interloc()