Beispiel #1
0
def assert_qa_file():
    # section INTENT
    assert_list_and_random(verbaliser.get_question_list('INTENT'),
                           ['Q1', 'Q2', 'Q3'],
                           verbaliser.get_random_question('INTENT'))
    assert_list_and_random(verbaliser.get_successful_answer_list('INTENT'),
                           ['SA1', 'SA2'],
                           verbaliser.get_random_successful_answer('INTENT'))
    assert_list_and_random(verbaliser.get_failure_answer_list('INTENT'),
                           ['FA1'],
                           verbaliser.get_random_failure_answer('INTENT'))
    assert_list_and_random(verbaliser.get_followup_question_list('INTENT'),
                           ['FUPQ1'],
                           verbaliser.get_random_followup_question('INTENT'))
    assert_list_and_random(verbaliser.get_followup_answer_list('INTENT'),
                           ['FUPA1'],
                           verbaliser.get_random_followup_answer('INTENT'))

    # section INTENT2
    assert_list_and_random(verbaliser.get_question_list('INTENT2'), ['Q1'],
                           verbaliser.get_random_question('INTENT2'))
    assert not verbaliser.get_successful_answer_list('INTENT2')
    assert not verbaliser.get_random_successful_answer('INTENT2')
    assert_list_and_random(verbaliser.get_failure_answer_list('INTENT2'),
                           ['FA1', 'FA2'],
                           verbaliser.get_random_failure_answer('INTENT2'))
    assert_list_and_random(verbaliser.get_followup_question_list('INTENT2'),
                           ['FUPQ1', 'FUPQ2'],
                           verbaliser.get_random_followup_question('INTENT2'))
    assert_list_and_random(verbaliser.get_followup_answer_list('INTENT2'),
                           ['FUPA1'],
                           verbaliser.get_random_followup_answer('INTENT2'))
Beispiel #2
0
 def analyse_ice_cream_suggestion_answer(ctx: rs.ContextWrapper):
     if ctx[prop_scoops] or ctx[prop_flavors]:
         return rs.Resign()
     elif ctx[nlp.prop_yesno].yes():
         ctx[rawio.prop_out] = verbaliser.get_random_successful_answer(
             "greet_general")
     elif ctx[nlp.prop_yesno].no():
         ctx[rawio.prop_out] = verbaliser.get_random_failure_answer(
             "greet_general")
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 known_location(ctx: rs.ContextWrapper):
        ctx[prop_suggested_ice_cream] = True
        location = ctx[prop_location]
        communication_with_cloud(server=ws, connection_type="BUSY")
        if not is_busy:
            if location == "unknown":
                ctx[rawio.prop_out] = verbaliser.get_random_failure_answer("location_qa")

            else:
                communication_with_cloud(ws, "LOCATION_ETA", location)
                if path_found:
                    ctx[rawio.prop_out] = verbaliser.get_random_successful_answer("location_qa") \
                        .format(location=location, min=eta)
                else:
                    ctx[rawio.prop_out] = verbaliser.get_random_phrase("no_path")
        else:
            ctx[rawio.prop_out] = verbaliser.get_random_phrase("telegram_busy").format(roboy_location=roboy_location)
Beispiel #5
0
 def wait_for_telegram_customer(ctx: rs.ContextWrapper):
     time.sleep(
         3
     )  # Adjust to how much time Roboy should give a Telegram customer to come up
     ctx[rawio.prop_out] = verbaliser.get_random_successful_answer(
         "greet_general")
Beispiel #6
0
 def react_to_ice_cream_desire(ctx: rs.ContextWrapper):
     ctx[rawio.prop_out] = verbaliser.get_random_successful_answer(
         "greet_general")
Beispiel #7
0
    def roboyqa(ctx):
        """
        answers question regarding roboy by retrieving the information out of the neo4j roboy memory graph
        state gets triggered when nlp extracts a new triple: subject, predicate, object
        by analysing the triple the content of the question can be ascertained
        the necessary information is gathered using the neo4j memory session
        if the triple combination is known and the information could be retrieved an answer will be given

        list of questions that can be answered:
        - 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?
        """
        sess = ravestate_ontology.get_session()
        roboy = sess.retrieve(node_id=ctx.conf(key=ROBOY_NODE_CONF_KEY))[0]
        triple = ctx["nlp:triples"][0]

        category = None
        memory_info = None

        # question word: What?
        if triple.is_question(QuestionWord.OBJECT):
            if triple.match_either_lemma(pred={"like"}, subj={"hobby"}):
                category = "HAS_HOBBY"
            elif triple.match_either_lemma(pred={"learn"}, subj={"skill"}):
                category = "skills"
            elif triple.match_either_lemma(pred={"can"}, subj={"ability"}):
                category = "abilities"
            elif triple.match_either_lemma(subj={"age"}):
                category = "age"
                memory_info = roboy_age(roboy.get_properties(key="birthdate"))
            elif triple.match_either_lemma(subj={"name"}):
                category = "full_name"
                memory_info = roboy.get_properties(key=category)
            elif triple.match_either_lemma(pred={"become"}):
                category = "future"
        # question word: Where?
        elif triple.is_question(QuestionWord.PLACE):
            if triple.match_either_lemma(pred={"be"}):
                category = "FROM"
            elif triple.match_either_lemma(pred={"live"}):
                category = "LIVE_IN"
        # question word: Who?
        elif triple.is_question(QuestionWord.PERSON):
            if triple.match_either_lemma(obj={"father", "dad"}):
                category = "CHILD_OF"
            elif triple.match_either_lemma(obj={"brother", "sibling"}):
                category = "SIBLING_OF"
            elif triple.match_either_lemma(obj={"friend", "girlfriend"}):
                category = "FRIEND_OF"
            else:
                category = "full_name"
                memory_info = roboy.get_properties(key=category)
        elif triple.match_either_lemma(obj={"part", "member"}):
            category = "MEMBER_OF"
        # question word: How?
        elif triple.is_question(QuestionWord.FORM):
            if triple.match_either_lemma(pred={"old"}):
                category = "age"
                memory_info = roboy_age(roboy.get_properties(key="birthdate"))
            elif triple.match_either_lemma(pred={"be"}):
                category = "well_being"
        elif triple.match_either_lemma(obj={"skill"}):
            category = "skills"
        elif triple.match_either_lemma(obj={"ability"}):
            category = "abilities"

        if category and category.isupper() and not isinstance(
                roboy.get_relationships(key=category), dict):
            node_id = random.sample(roboy.get_relationships(key=category),
                                    1)[0]
            memory_info = sess.retrieve(node_id=int(node_id))[0].get_name()

        elif category and category.islower() and not isinstance(
                roboy.get_properties(key=category), dict):
            property_list = [
                x.strip()
                for x in roboy.get_properties(key=category).split(',')
            ]
            memory_info = random.sample(property_list, 1)[0]

        if memory_info:
            ctx["rawio:out"] = verbaliser.get_random_successful_answer(
                category) % memory_info
        elif category == "well_being":
            ctx["rawio:out"] = verbaliser.get_random_successful_answer(
                category)
        else:
            return Resign()
Beispiel #8
0
 def analyse_ice_cream_suggestion_answer(ctx: rs.ContextWrapper):
     if ctx[nlp.prop_yesno].yes():
         ctx[rawio.prop_out] = verbaliser.get_random_successful_answer("greet_general")
         return rs.Emit(wipe=True)
     elif ctx[nlp.prop_yesno].no():
         ctx[rawio.prop_out] = verbaliser.get_random_failure_answer("greet_general")