def payment_process(ctx: rs.ContextWrapper): @rs.receptor(ctx_wrap=ctx, write=rawio.prop_out) def say(ctx_input, value: str): ctx_input[rawio.prop_out] = value payment_option = ctx[prop_payment_option] price = ctx[prop_price] amount_paid, error_message = payment_communication( price, payment_option, ctx[prop_flavor_scoop_tuple_list]) if amount_paid == 0: say(verbaliser.get_random_phrase("no_payment")) elif amount_paid < price: say( verbaliser.get_random_phrase("amount_left").format( amount_left_over=amount_in_euros_and_cents(price - amount_paid))) ctx[prop_price] = price - amount_paid elif amount_paid == price: say(verbaliser.get_random_phrase("perfect_amount")) ctx[prop_payment_success] = True elif amount_paid > price: say( verbaliser.get_random_phrase("better_amount").format( amount_too_much=amount_in_euros_and_cents(amount_paid - price))) ctx[prop_payment_success] = True elif error_message: say(verbaliser.get_random_phrase("error_payment")) return rs.Emit(wipe=True)
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'))
def start_payment(ctx: rs.ContextWrapper): payment_option = ctx[prop_payment_option] if payment_option == PaymentOptions.PAYPAL: ctx[rawio.prop_out] = verbaliser.get_random_phrase("paypal_option") return rs.Emit(wipe=True) elif payment_option == PaymentOptions.COIN: ctx[rawio.prop_out] = verbaliser.get_random_phrase("coin_option") return rs.Emit(wipe=True)
def analyse_finish_order_answer(ctx: rs.ContextWrapper): if ctx[nlp.prop_yesno].yes(): flavor_scoop_tuple_list = ctx[prop_flavor_scoop_tuple_list] complete_order, complete_cost = get_complete_order_and_cost( flavor_scoop_tuple_list) ctx[rawio.prop_out] = verbaliser.get_random_phrase( "preparing_order").format(order=complete_order) ctx[prop_price] = complete_cost * 100 # price is in cents return rs.Emit(wipe=True) elif ctx[nlp.prop_yesno].no(): ctx[rawio.prop_out] = verbaliser.get_random_phrase( "continue_order")
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'))
def ask_payment_method(ctx: rs.ContextWrapper): flavor_scoop_tuple_list = ctx[prop_flavor_scoop_tuple_list] complete_order, complete_cost = get_complete_order_and_cost( flavor_scoop_tuple_list) ctx[rawio.prop_out] = verbaliser.get_random_phrase("payment").format( cost=complete_cost, order=complete_order) return rs.Emit(wipe=True)
def check_scoops_flavor_combined(ctx: rs.ContextWrapper): if -1 in prop_scoops.read(): ctx[rawio.prop_out] = verbaliser.get_random_phrase("error_scoops") ctx[prop_flavors] = [] ctx[prop_scoops] = [] elif (prop_flavors.read() and prop_scoops.read() and len(prop_flavors.read()) == len(prop_scoops.read()))\ or (not prop_flavors.read() and not prop_scoops.read() and prop_flavor_scoop_tuple_list.read()): current_order = [ x for x in zip(prop_flavors.read(), prop_scoops.read()) ] add_orders_together(current_order, prop_flavor_scoop_tuple_list.read()) ctx[prop_flavor_scoop_tuple_list] = current_order ctx[prop_flavors] = [] ctx[prop_scoops] = [] possibly_complete_order, _ = get_complete_order_and_cost( prop_flavor_scoop_tuple_list.read()) ctx[rawio.prop_out] = verbaliser.get_random_phrase( "legit_order").format(order=possibly_complete_order) return rs.Emit(wipe=True) elif len(prop_flavors.read()) > len(prop_scoops.read()): current_order = [(prop_flavors.read()[i], prop_scoops.read()[i]) for i in range(0, len(prop_scoops.read()))] add_orders_together(current_order, prop_flavor_scoop_tuple_list.read()) ctx[prop_flavor_scoop_tuple_list] = current_order ctx[prop_flavors] = prop_flavors.read()[len(prop_scoops.read()):] ctx[prop_scoops] = [] ctx[rawio.prop_out] = verbaliser.get_random_phrase("need_scoop") \ .format(flavor=fix_pronunciation(prop_flavors.read()[0])) return rs.Emit(wipe=True) elif len(prop_flavors.read()) < len(prop_scoops.read()): current_order = [(prop_flavors.read()[i], prop_scoops.read()[i]) for i in range(0, len(prop_flavors.read()))] add_orders_together(current_order, prop_flavor_scoop_tuple_list.read()) ctx[prop_flavor_scoop_tuple_list] = current_order ctx[prop_scoops] = prop_scoops.read()[len(prop_flavors.read()):] ctx[prop_flavors] = [] if prop_scoops.read()[0] == 1: ctx[rawio.prop_out] = verbaliser.get_random_phrase( "need_flavor").format(scoop=prop_scoops.read()[0], s="") else: ctx[rawio.prop_out] = verbaliser.get_random_phrase( "need_flavor").format(scoop=prop_scoops.read()[0], s="s") return rs.Emit(wipe=True)
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)
def after_scooping(ctx: rs.ContextWrapper): if (ROS_AVAILABLE and client.gh and client.get_result() is None) \ or (not ROS_AVAILABLE and not scooping_communication.stop_feedback): return rs.Resign() if ROS_AVAILABLE and client.gh and client.get_result( ) is not None and not client.get_result().success: ctx[rawio.prop_out] = verbaliser.get_random_phrase("unexpected") else: return rs.Emit(wipe=True)
def feedback_state(ctx: rs.ContextWrapper): if ROS_AVAILABLE and client.gh and (client.get_result() is not None) \ or (not ROS_AVAILABLE and scooping_communication.stop_feedback): return rs.Emit(wipe=True) if ROS_AVAILABLE and scooping_communication.feedback is not None: finished_scoops, status_message = scooping_communication.feedback if not scooping_communication.last_scooping_feedback_array == finished_scoops: scooping_communication.last_scooping_feedback_array = finished_scoops if status_message == "more time": ctx[rawio.prop_out] = verbaliser.get_random_phrase("time") else: scoops_left = finished_scoops.count(False) if scoops_left == 1: ctx[rawio.prop_out] = verbaliser.get_random_phrase( "scoops_left").format(c=scoops_left, s="") elif scoops_left > 1: ctx[rawio.prop_out] = verbaliser.get_random_phrase( "scoops_left").format(c=scoops_left, s="s") return rs.Emit(wipe=True)
def react_to_intent(ctx): """ Looks for intents written to the verbaliser:intent property and writes a random phrase for that intent to rawio:out """ intent = ctx["verbaliser:intent"] phrase = verbaliser.get_random_phrase(intent) if phrase: ctx["rawio:out"] = phrase else: logging.error('No phrase for intent ' + intent + ' found.')
def waiting_for_complete_order(ctx: rs.ContextWrapper): asked_order_count = ctx[prop_asked_order_count] if asked_order_count < 3: ctx[prop_asked_order_count] = asked_order_count + 1 return rs.Emit(wipe=True) else: ctx[rawio.prop_out] = verbaliser.get_random_phrase("order_aborted") ctx[prop_flavor_scoop_tuple_list] = [] ctx[prop_flavors] = [] ctx[prop_scoops] = [] ctx[prop_suggested_ice_cream] = False ctx[prop_asked_order_count] = 1
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 Delete(resign=True) params = {'question': ctx["rawio:in"]} 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:out"] = verbaliser.get_random_phrase("question-answering-starting-phrases") + " " + \ response_json["answers"][0]["span"] # insane/unsure answer else: ctx["rawio: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."
def after_payment(ctx: rs.ContextWrapper): payment_success = ctx[prop_payment_success] if payment_success: ctx[rawio.prop_out] = verbaliser.get_random_phrase( "luigi_farewell") ctx[prop_flavor_scoop_tuple_list] = [] ctx[prop_flavors] = [] ctx[prop_scoops] = [] ctx[prop_suggested_ice_cream] = False ctx[prop_price] = -1 ctx[prop_payment_option] = -1 ctx[prop_payment_success] = False ctx[prop_asked_order_count] = 1 ctx[prop_asked_payment_count] = 1 else: return rs.Emit(wipe=True)
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")
def ask_location_if_not_busy(ctx: rs.ContextWrapper): communication_with_cloud(server=ws, connection_type="BUSY") if is_busy: ctx[rawio.prop_out] = verbaliser.get_random_phrase("telegram_busy").format(roboy_location=roboy_location) else: return rs.Emit(wipe=True)
def assert_nosection_file(): assert_list_and_random(verbaliser.get_phrase_list('nosection1'), ['a', 'b', 'c', 'd'], verbaliser.get_random_phrase('nosection1'))
def arrived_at_location(ctx: rs.ContextWrapper): if ctx[has_arrived]: ctx[rawio.prop_out] = verbaliser.get_random_phrase( "telegram_arrival") return rs.Emit(wipe=True)