def persist_nlg(self, filename: Text) -> None: if data.is_likely_yaml_file(filename): rasa.nlu.utils.write_to_file(filename, self.nlg_as_yaml()) elif data.is_likely_markdown_file(filename): nlg_serialized_data = self.nlg_as_markdown() if nlg_serialized_data: rasa.nlu.utils.write_to_file(filename, nlg_serialized_data) else: ValueError( "Unsupported file format detected. Supported file formats are 'md' " "and 'yml'.")
def persist_nlu(self, filename: Text = DEFAULT_TRAINING_DATA_OUTPUT_PATH) -> None: if data.is_likely_json_file(filename): rasa.nlu.utils.write_to_file(filename, self.nlu_as_json(indent=2)) elif data.is_likely_markdown_file(filename): rasa.nlu.utils.write_to_file(filename, self.nlu_as_markdown()) elif data.is_likely_yaml_file(filename): rasa.nlu.utils.write_to_file(filename, self.nlu_as_yaml()) else: ValueError( "Unsupported file format detected. Supported file formats are 'json' " "and 'md'." )
def _get_reader( filename: Text, domain: Domain, template_variables: Optional[Dict] = None, use_e2e: bool = False, ) -> StoryReader: if data.is_likely_markdown_file(filename): return MarkdownStoryReader(domain, template_variables, use_e2e, filename) elif data.is_likely_yaml_file(filename): return YAMLStoryReader(domain, template_variables, use_e2e, filename) else: # This is a use case for uploading the story over REST API. # The source file has a random name. return _guess_reader(filename, domain, template_variables, use_e2e)
def test_is_md_file(path, is_md): assert data.is_likely_markdown_file(path) == is_md