def _convert_to_yaml(args: argparse.Namespace, is_nlu: bool) -> None: output = Path(args.out) if not os.path.exists(output): print_error_and_exit( f"The output path '{output}' doesn't exist. Please make sure to specify " f"an existing directory and try again." ) training_data = Path(args.data) if not os.path.exists(training_data): print_error_and_exit( f"The training data path {training_data} doesn't exist " f"and will be skipped." ) num_of_files_converted = 0 for file in os.listdir(training_data): source_path = training_data / file output_path = output / f"{source_path.stem}{CONVERTED_FILE_SUFFIX}" if MarkdownReader.is_markdown_nlu_file(source_path): if not is_nlu: continue _write_nlu_yaml(source_path, output_path, source_path) num_of_files_converted += 1 elif not is_nlu and MarkdownStoryReader.is_markdown_story_file(source_path): _write_core_yaml(source_path, output_path, source_path) num_of_files_converted += 1 else: print_warning(f"Skipped file: '{source_path}'.") print_info(f"Converted {num_of_files_converted} file(s), saved in '{output}'.")
def filter(cls, source_path: Path) -> bool: """Checks if the given training data file contains Core data in `Markdown` format and can be converted to `YAML`. Args: source_path: Path to the training data file. Returns: `True` if the given file can be converted, `False` otherwise """ return MarkdownStoryReader.is_markdown_story_file(source_path)
def is_story_file(file_path: Text) -> bool: from rasa.core.training.story_reader.markdown_story_reader import ( MarkdownStoryReader, ) from rasa.core.training.story_reader.yaml_story_reader import YAMLStoryReader """Checks if a file is a Rasa story file. Args: file_path: Path of the file which should be checked. Returns: `True` if it's a story file, otherwise `False`. """ return YAMLStoryReader.is_yaml_story_file( file_path) or MarkdownStoryReader.is_markdown_story_file(file_path)
def _guess_reader( filename: Text, domain: Domain, template_variables: Optional[Dict] = None, use_e2e: bool = False, ) -> StoryReader: if YAMLStoryReader.is_yaml_story_file(filename): return YAMLStoryReader(domain, template_variables, use_e2e, filename) elif MarkdownStoryReader.is_markdown_story_file(filename): return MarkdownStoryReader(domain, template_variables, use_e2e, filename) raise ValueError( f"Failed to find a reader class for the story file `{filename}`. " f"Supported formats are " f"{', '.join(MARKDOWN_FILE_EXTENSIONS.union(YAML_FILE_EXTENSIONS))}.")
def _guess_reader( filename: Text, domain: Domain, interpreter: NaturalLanguageInterpreter = RegexInterpreter(), template_variables: Optional[Dict] = None, use_e2e: bool = False, ) -> StoryReader: if YAMLStoryReader.is_yaml_story_file(filename): return YAMLStoryReader(interpreter, domain, template_variables, use_e2e, filename) elif MarkdownStoryReader.is_markdown_story_file(filename): return MarkdownStoryReader(interpreter, domain, template_variables, use_e2e, filename) raise ValueError( f"Failed to find a reader class for the story file `{filename}`. " f"Supported formats are {MARKDOWN_FILE_EXTENSION}, {YAML_FILE_EXTENSIONS}." )