def write_stories_file(df_directory = "dialogflow", stories_file = "data/stories.md"): intents = get_intent(df_directory).intents parameters = get_examples_for_entities(df_directory).entity_eg out_string = "" story_count = 0 for intent in intents: # *Story name story_count += 1 out_string += ("## Generated Story {}\n".format(story_count)) out_string += ("* {}".format(intent.name)) slots = [] entities = [] # Handling required parameters for entity in intent.entities: if entity.required == False or str(entity.name) not in parameters: continue slot = "" slot += "\"" + entity.name + "\": \"" slot += random.choice(parameters[str(entity.name)]) + "\"" slots.append(slot) entities.append(slot) # Handling contexts for in_context in intent.context_in: slot = "" slot += "\"" + in_context + "\": \"" # Ideally, this should be a number b/w 0 and lifespan slot += "1" + "\"" slots.append(slot) if len(slots)>0: out_string += "{" for slot in slots: out_string += slot if not(slot == slots[-1]): out_string += "," out_string += "}" out_string += "\n" # Slot setting if len(entities)>0: for slot in entities: out_string += "\t- slot{" + ("{}".format(slot)) + "}\n" a_name = command_sanitizer(intent.action) out_string += ("\t- {}\n".format(a_name)) story_count += 1 out_string += ("## Generated Story {}\n".format(story_count)) out_string += ("* {}".format(intent.name)) out_string += "\n" out_string += ("\t- {}\n".format(a_name)) #print("\tIn Contexts: {}".format(len(intent.context_in))) with open(stories_file,'w') as outfile: outfile.write(out_string)
def write_to_string(self): string = "" for action in self.action: a_name = command_sanitizer(action) if "_follow_up_" not in a_name: string += (" - action.{}\n".format(a_name)) string += (" - utter_{}\n".format(a_name)) return string
def build(df_directory): intents = get_intent(df_directory).intent_list with open("action_header.txt", "r") as infile: header = infile.read() with open("action.py", "w") as outfile: outfile.write(header) with open("replicate_action.txt", "r") as infile: action_data = infile.read() with open("action.py", "a") as outfile: for intent in intents: data = "\n" data += action_data data = data.replace("<action_name>", command_sanitizer(intent.action)) data = data.replace("<index_name>", command_sanitizer(intent.name)) data += "\n" outfile.write(data)
def run(self, dispatcher, tracker, domain): index = "works_by_instrument" template = dispatcher.retrieve_template("utter_" + "works_by_instrument") # use contexts to influence predicted action use_contexts_to_predict_next_action(self.name(), tracker) # reset slots if necessary events = contexts_reset(self.name(), tracker) # standardize the slots events.extend(transform_slots_to_standard(tracker)) # Checking required parameters intent = contain.index[index] for entity in intent.entities: if entity.required == True: slot = entity.name if slot != None: slot_val = tracker.get_slot(slot) if slot_val is None: logger.info("Uttering the required parameter") dispatcher.utter_template( command_sanitizer("utter_{}_follow_up_{}".format( self.name(), slot))) events.append(SlotSet("requested_slot", slot)) return events text = template["text"] modified_text = "" i = 0 while i < (len(text)): if text[i] == '{': j = i + 1 slot = "" while (text[j] != '}' and j < len(text)): slot += text[j] j += 1 modified_text += tracker.get_slot(slot) i = j else: modified_text += text[i] i += 1 dispatcher.utter_message(modified_text) contexts = out_context_set(self.name) for c in contexts: events.append(SlotSet(c, 1)) events.append(SlotSet("requested_slot", None)) return events
def write_to_string(self): string = "" for template in self.template: t_name = command_sanitizer(template.name) string += (" {}:\n".format(t_name)) for text in template.text: if type(text) == list: for t in text: t = sanitize_text(t) string += (" - \"{}\"\n".format(t)) else: text = sanitize_text(text) string += (" - \"{}\"\n".format(text)) return string
def run(self, dispatcher, tracker, domain): index = "transfer_money___yes" template = dispatcher.retrieve_template("utter_" + "transfer_money_yes") # Checking required parameters intent = contain.index[index] for entity in intent.entities: if entity.required == True: slot = entity.name if slot != None: slot_val = tracker.get_slot(slot) if slot_val is None: logger.info("Uttering the required parameter") dispatcher.utter_template( command_sanitizer("utter_{}_follow_up_{}".format( self.name(), slot))) events = [] events.append(SlotSet("requested_slot", slot)) return events text = template["text"] modified_text = "" i = 0 while i < (len(text)): if text[i] == '{': j = i + 1 slot = "" while (text[j] != '}' and j < len(text)): slot += text[j] j += 1 modified_text += tracker.get_slot(slot) i = j else: modified_text += text[i] i += 1 dispatcher.utter_message(modified_text) events = [] contexts = out_context_set(self.name) for c in contexts: events.append(SlotSet(c, 1)) events.append(SlotSet("requested_slot", None)) return events