Exemplo n.º 1
0
 def react_to_feedback(ctx: rs.ContextWrapper):
     if ctx[prop_game_in_progress]:
         rand = random.random()
         if ctx[nlp.prop_yesno].yes():
             ctx[rawio.prop_out] = verbaliser.get_random_phrase(
                 "charades_winning_exclamations")
             if rand < 0.5:
                 emotion = SUNGLASSES_ON_EMOTION
                 ctx[prop_sunglasses_on] = True
             else:
                 emotion = HEARTS_EMOTION
             if ctx.conf(key=USE_EMOTIONS):
                 emo_client(emotion)
             ctx[prop_feedback_received] = True
             logger.info("correct")
         elif ctx[nlp.prop_yesno].no():
             if ctx[prop_guess_attempt_count] < 3:
                 ctx[rawio.prop_out] = verbaliser.get_random_phrase(
                     "charades_new_guess_attempt")
                 ctx[prop_another_attempt] = True
                 logger.info("wrong guess")
             else:
                 ctx[rawio.prop_out] = verbaliser.get_random_phrase(
                     "charades_losing_exclamations")
                 if ctx.conf(key=USE_EMOTIONS):
                     emo_client(SHY_EMOTION)
                 ctx[prop_feedback_received] = True
         else:
             ctx[prop_feedback_received] = False
             return rs.Emit()
     else:
         return rs.Resign()
Exemplo n.º 2
0
 def name_the_label(ctx: rs.ContextWrapper):
     if (ctx[prop_waiting_for_label]
             or (ctx[prop_guess_attempt_count] > 0
                 and ctx[prop_guess_attempt_count] < 3)):
         message = ctx[prop_label_subscriber]
         if message:
             confidence = message.confidence[
                 ctx[prop_guess_attempt_count]]
             label = message.label[ctx[prop_guess_attempt_count]]
             if confidence < 0.5:
                 conf_expr = verbaliser.get_random_phrase(
                     "charades_lower_confidence_prediction")
             elif confidence < 0.9:
                 conf_expr = verbaliser.get_random_phrase(
                     "charades_higher_confidence_prediction")
             else:
                 conf_expr = verbaliser.get_random_phrase(
                     "charades_highest_confidence_prediction")
             ctx[rawio.prop_out] = conf_expr + " " + str(label) +\
                 " " + verbaliser.get_random_phrase(
                 "charades_ask_for_feedback")
             logger.info(
                 f"Label named {label}, attempt {ctx[prop_guess_attempt_count]}"
             )
             ctx[prop_waiting_for_label] = False
             ctx[prop_feedback_received] = False
             ctx[prop_guess_attempt_count] = ctx[
                 prop_guess_attempt_count] + 1
             return rs.Emit()
         else:
             ctx[rawio.prop_out] = BROKEN_MESSAGE
     else:
         return rs.Resign()
Exemplo n.º 3
0
 def clarify_feedback(ctx: rs.ContextWrapper):
     if ctx[prop_game_in_progress] and not ctx[prop_feedback_received]:
         ctx[rawio.prop_out] = verbaliser.get_random_phrase(
             "charades_misunderstanding") + " " + \
             verbaliser.get_random_phrase("charades_ask_for_feedback")
         return rs.Emit()
     else:
         return rs.Resign()
Exemplo n.º 4
0
 def greeting(ctx: rs.ContextWrapper):
     pushed_node_path: str = ctx[interloc.prop_all.pushed()]
     interloc_node: Node = ctx[pushed_node_path]
     if interloc_node and interloc_node.get_id() >= 0:
         phrase = verbaliser.get_random_phrase('greeting-with-name')
         ctx[rawio.prop_out] = phrase.format(name=interloc_node.get_name())
     else:
         ctx[rawio.prop_out] = verbaliser.get_random_phrase(lang.intent_greeting)
Exemplo n.º 5
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()
Exemplo n.º 6
0
 def offer_game(ctx: rs.ContextWrapper):
     if not ctx[prop_game_in_progress]:
         ctx[rawio.prop_out] = verbaliser.get_random_phrase(
             "charades_offer_game")
         ctx[prop_game_stopped] = False
         return rs.Emit()
     else:
         rs.Resign()
Exemplo n.º 7
0
 def react_to_continue_decision(ctx: rs.ContextWrapper):
     rand = random.random()
     if ctx[nlp.prop_yesno].yes():
         ctx[rawio.prop_out] = verbaliser.get_random_phrase(
             "charades_positive_expressions") + " Let's continue then"
         if rand < 0.7 and ctx.conf(key=USE_EMOTIONS):
             emo_client(LUCKY_EMOTION)
         return rs.Emit()
     elif ctx[nlp.prop_yesno].no():
         ctx[rawio.prop_out] = verbaliser.get_random_phrase(
             "charades_no_continuation")
         if ctx.conf(key=USE_EMOTIONS):
             emo_client(KISS_EMOTION)
         ctx[prop_stop_game] = True
     else:
         ctx[rawio.prop_out] = verbaliser.get_random_phrase(
             "charades_misunderstanding")
         ctx[prop_continuation_unclear] = True
Exemplo n.º 8
0
 def ask_to_continue(ctx: rs.ContextWrapper):
     if ctx[prop_feedback_received]:
         ctx[rawio.prop_out] = verbaliser.get_random_phrase(
             "charades_offer_another_round")
         if ctx[prop_sunglasses_on] and ctx.conf(key=USE_EMOTIONS):
             emo_client(SUNGLASSES_ON_EMOTION)
             ctx[prop_sunglasses_on] = False
         return rs.Emit()
     else:
         return rs.Resign()
Exemplo n.º 9
0
 def process_play_decision(ctx: rs.ContextWrapper):
     if not ctx[prop_game_in_progress]:
         if ctx[nlp.prop_yesno].yes():
             ctx[rawio.prop_out] = verbaliser.get_random_phrase(
                 "charades_positive_expressions") + \
                 " Do you want to hear the rules?"
             if ctx.conf(key=USE_EMOTIONS):
                 emo_client(SMILEBLINK_EMOTION)
             return rs.Emit()
         elif ctx[nlp.prop_yesno].no():
             if random.random() < 0.5 and ctx.conf(key=USE_EMOTIONS):
                 emo_client(ROLL_EYES_EMOTION)
             ctx[rawio.prop_out] = verbaliser.get_random_phrase(
                 "charades_refuse_offer")
             ctx[prop_stop_game] = True
         else:
             ctx[prop_decision_unclear] = True
             ctx[rawio.prop_out] = verbaliser.get_random_phrase(
                 "charades_misunderstanding")
     else:
         return rs.Resign()
Exemplo n.º 10
0
 def drqa_module(ctx):
     """
     general question answering using DrQA through a HTTP server
     connection check to server
     post input question and get DrQA answer through the HTTP interface
     depending on the answer score the answer is introduced as sane or insane/unsure :)
     """
     server = ctx.conf(key=DRQA_SERVER_ADDRESS)
     if not server_up(server):
         return rs.Delete(resign=True)
     params = {'question': str(ctx[rawio.prop_in]).lower()}
     response = requests.get(server, params=params)
     response_json = response.json()
     certainty = response_json["answers"][0]["span_score"]
     # sane answer
     if certainty > ctx.conf(key=ROBOY_ANSWER_SANITY):
         ctx[rawio.prop_out] = verbaliser.get_random_phrase("question-answering-starting-phrases") + " " + \
                            response_json["answers"][0]["span"]
     # insane/unsure answer
     else:
         ctx[rawio.prop_out] = verbaliser.get_random_phrase("unsure-question-answering-phrases") \
                            % response_json["answers"][0]["span"] \
                            + "\n" + "Maybe I can find out more if your rephrase the question for me."
Exemplo n.º 11
0
 def ping_activity_choice(ctx: rs.ContextWrapper):
     if ctx[prop_game_in_progress]:
         rand = random.random()
         pinged_times = ctx[prop_ping_choice_count]
         if pinged_times < 5:
             if rand < 0.4 and ctx.conf(key=USE_EMOTIONS):
                 emo_client(LOOK_RIGHT_EMOTION)
             elif (rand > 0.4 and rand < 0.8
                   and ctx.conf(key=USE_EMOTIONS)):
                 emo_client(LOOK_LEFT_EMOTION)
             ctx[rawio.prop_out] = verbaliser.get_random_phrase(
                 "charades_ping_activity_choice")
             ctx[prop_ping_choice_count] = pinged_times + 1
             return rs.Emit()
         else:
             ctx[prop_stop_game] = True
Exemplo n.º 12
0
 def react_to_choice(ctx: rs.ContextWrapper):
     if ctx[prop_game_in_progress]:
         if ("ready" in ctx[nlp.prop_lemmas]
                 or "already" in ctx[nlp.prop_lemmas]
                 or "reading" in ctx[nlp.prop_lemmas]
                 or "reddit" in ctx[nlp.prop_lemmas]
                 or "reggie" in ctx[nlp.prop_lemmas]
                 or "meridian" in ctx[nlp.prop_lemmas]
                 or "radio" in ctx[nlp.prop_lemmas]):
             ctx[rawio.prop_out] = verbaliser.get_random_phrase(
                 "charades_countdown")
             ctx[prop_ping_choice_count] = 0
             return rs.Emit()
         else:
             ctx[prop_choice_unclear] = True
     else:
         return rs.Resign()
Exemplo n.º 13
0
 def clarify_activity_choice(ctx: rs.ContextWrapper):
     ctx[rawio.prop_out] = verbaliser.get_random_phrase(
         "charades_misunderstanding") + " " + \
         "Say 'ready' when you're ready"
     return rs.Emit()
Exemplo n.º 14
0
 def hello_world_roboyqa(ctx):
     ctx[rawio.prop_out] = verbaliser.get_random_phrase("roboyqa-prompt")
Exemplo n.º 15
0
 def prompt_send(ctx):
     ctx[rawio.prop_out] = verbaliser.get_random_phrase("sendpics-prompt")
Exemplo n.º 16
0
 def prompt(ctx):
     ctx[rawio.prop_out] = verbaliser.get_random_phrase("question-answering-prompt")
Exemplo n.º 17
0
 def offer_activity_choice(ctx: rs.ContextWrapper):
     ctx[rawio.prop_out] = verbaliser.get_random_phrase(
         "charades_offer_activity_choice")
     return rs.Emit(wipe=True)