Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding yaml converter to nlu convert #191

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rasa/cli/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def _validate_story_structure(validator: "Validator", args: argparse.Namespace)
def _convert_nlu_data(args: argparse.Namespace) -> None:
import rasa.nlu.convert

if args.format == "json":
if args.format in ["json", "yaml"]:
rasa.nlu.convert.convert_training_data(
args.data, args.out, args.format, args.language
)
Expand Down
6 changes: 4 additions & 2 deletions rasa/nlu/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ def convert_training_data(
)
return

td = rasa.shared.nlu.training_data.loading.load_data(data_file, language)
if output_format == "json":
td = rasa.shared.nlu.training_data.loading.load_data(data_file, language)
output = td.nlu_as_json(indent=2)
elif output_format == "yaml":
output = td.nlu_as_yaml()
else:
print_error(
"Did not recognize output format. Supported output formats: 'json' and "
"'md'. Specify the desired output format with '--format'."
"'yaml'. Specify the desired output format with '--format'."
)
return

Expand Down
14 changes: 14 additions & 0 deletions tests/cli/test_rasa_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ def test_data_convert_nlu(run_in_simple_project: Callable[..., RunResult]):

assert os.path.exists("out_nlu_data.json")

run_in_simple_project(
"data",
"convert",
"nlu",
"--data",
"out_nlu_data.json",
"--out",
"out_nlu_data.yml",
"-f",
"yaml",
)

assert os.path.exists("out_nlu_data.yml")


def test_data_split_help(run: Callable[..., RunResult]):
output = run("data", "split", "nlu", "--help")
Expand Down