def test_nlu_intents_are_converted(tmpdir: Path): converted_data_folder = tmpdir / "converted_data" os.mkdir(converted_data_folder) training_data_folder = tmpdir / "data/nlu" os.makedirs(training_data_folder, exist_ok=True) training_data_file = Path(training_data_folder / "nlu.md") simple_nlu_md = """ ## intent:greet - hey - hello """ with open(training_data_file, "w") as f: f.write(simple_nlu_md) NLUMarkdownToYamlConverter().convert_and_write(training_data_file, converted_data_folder) assert len(os.listdir(converted_data_folder)) == 1 with open(f"{converted_data_folder}/nlu_converted.yml", "r") as f: content = f.read() assert content == ( f'version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"\n' "nlu:\n" "- intent: greet\n" " examples: |\n" " - hey\n" " - hello\n")
def _convert_nlu_data(args: argparse.Namespace) -> None: from rasa.nlu.training_data.converters.nlu_markdown_to_yaml_converter import ( NLUMarkdownToYamlConverter, ) if args.format in ["json", "md"]: convert_training_data(args.data, args.out, args.format, args.language) elif args.format == "yaml": _convert_to_yaml(args, NLUMarkdownToYamlConverter()) else: print_error_and_exit( "Could not recognize output format. Supported output formats: 'json', " "'md', 'yaml'. Specify the desired output format with '--format'.")
def _convert_nlu_data(args: argparse.Namespace) -> None: from rasa.nlu.training_data.converters.nlu_markdown_to_yaml_converter import ( NLUMarkdownToYamlConverter, ) if args.format in ["json", "md"]: rasa.nlu.convert.convert_training_data(args.data, args.out, args.format, args.language) telemetry.track_data_convert(args.format, "nlu") elif args.format == "yaml": rasa.utils.common.run_in_loop( _convert_to_yaml(args, NLUMarkdownToYamlConverter())) telemetry.track_data_convert(args.format, "nlu") else: rasa.shared.utils.cli.print_error_and_exit( "Could not recognize output format. Supported output formats: 'json', " "'md', 'yaml'. Specify the desired output format with '--format'.")
def test_nlu_lookup_tables_are_converted(tmpdir: Path): converted_data_folder = tmpdir / "converted_data" os.mkdir(converted_data_folder) training_data_folder = tmpdir / "data/nlu" os.makedirs(training_data_folder, exist_ok=True) training_data_file = Path(training_data_folder / "nlu.md") simple_nlu_md = f""" ## lookup:products.txt {tmpdir / "data/nlu/lookups/products.txt"} """ with open(training_data_file, "w") as f: f.write(simple_nlu_md) lookup_data_folder = training_data_folder / "lookups" os.makedirs(lookup_data_folder, exist_ok=True) lookup_tables_file = lookup_data_folder / "products.txt" simple_lookup_table_txt = "core\n nlu\n x\n" with open(lookup_tables_file, "w") as f: f.write(simple_lookup_table_txt) NLUMarkdownToYamlConverter().convert_and_write(training_data_file, converted_data_folder) assert len(os.listdir(converted_data_folder)) == 1 with open(f"{converted_data_folder}/products_converted.yml", "r") as f: content = f.read() assert content == ( f'version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"\n' "nlu:\n" "- lookup: products\n" " examples: |\n" " - core\n" " - nlu\n" " - x\n")
def test_converter_filters_correct_files(training_data_file: Text, should_filter: bool): assert should_filter == NLUMarkdownToYamlConverter.filter( Path(training_data_file))