Example #1
0
    def persist_clean(self, filename: Text) -> None:
        """Write domain to a file.

         Strips redundant keys with default values."""

        data = self.as_dict()

        for idx, intent_info in enumerate(data["intents"]):
            for name, intent in intent_info.items():
                if intent.get("use_entities"):
                    data["intents"][idx] = name

        for slot in data["slots"].values():
            if slot["initial_value"] is None:
                del slot["initial_value"]
            if slot["auto_fill"]:
                del slot["auto_fill"]
            if slot["type"].startswith('rasa_core.slots'):
                slot["type"] = Slot.resolve_by_type(slot["type"]).type_name

        if data["config"]["store_entities_as_slots"]:
            del data["config"]["store_entities_as_slots"]

        # clean empty keys
        data = {
            k: v
            for k, v in data.items() if v != {} and v != [] and v is not None
        }

        utils.dump_obj_as_yaml_to_file(filename, data)
Example #2
0
 def collect_slots(slot_dict):
     # it is super important to sort the slots here!!!
     # otherwise state ordering is not consistent
     slots = []
     for slot_name in sorted(slot_dict):
         slot_class = Slot.resolve_by_type(slot_dict[slot_name].get("type"))
         if "type" in slot_dict[slot_name]:
             del slot_dict[slot_name]["type"]
         slot = slot_class(slot_name, **slot_dict[slot_name])
         slots.append(slot)
     return slots
Example #3
0
 def collect_slots(slot_dict):
     # it is super important to sort the slots here!!!
     # otherwise state ordering is not consistent
     slots = []
     for slot_name in sorted(slot_dict):
         slot_class = Slot.resolve_by_type(slot_dict[slot_name].get("type"))
         if "type" in slot_dict[slot_name]:
             del slot_dict[slot_name]["type"]
         slot = slot_class(slot_name, **slot_dict[slot_name])
         slots.append(slot)
     return slots