Example #1
0
    def convert_and_write(cls, source_path: Path, output_path: Path) -> None:
        """Converts the given training data file and saves it to the output directory.

        Args:
            source_path: Path to the training data file.
            output_path: Path to the output directory.
        """
        from rasa.shared.core.training_data.story_reader.yaml_story_reader import (
            KEY_ACTIVE_LOOP, )

        output_core_path = cls.generate_path_for_converted_training_data_file(
            source_path, output_path)

        reader = MarkdownStoryReader(unfold_or_utterances=False)
        writer = YAMLStoryWriter()

        loop = asyncio.get_event_loop()
        steps = loop.run_until_complete(reader.read_from_file(source_path))

        if YAMLStoryWriter.stories_contain_loops(steps):
            print_warning(
                f"Training data file '{source_path}' contains forms. "
                f"Any 'form' events will be converted to '{KEY_ACTIVE_LOOP}' events. "
                f"Please note that in order for these stories to work you still "
                f"need the 'FormPolicy' to be active. However the 'FormPolicy' is "
                f"deprecated, please consider switching to the new 'RulePolicy', "
                f"for which you can find the documentation here: {DOCS_URL_RULES}."
            )

        writer.dump(output_core_path, steps)

        print_success(
            f"Converted Core file: '{source_path}' >> '{output_core_path}'.")
Example #2
0
async def test_simple_story(tmpdir: Path, default_domain: Domain,
                            input_md_file: Text, input_yaml_file: Text):

    original_md_reader = MarkdownStoryReader(default_domain,
                                             None,
                                             False,
                                             input_md_file,
                                             is_used_for_training=False)
    original_md_story_steps = original_md_reader.read_from_file(input_md_file)

    assert not YAMLStoryWriter.stories_contain_loops(original_md_story_steps)

    original_yaml_reader = YAMLStoryReader(default_domain, None, False)
    original_yaml_story_steps = original_yaml_reader.read_from_file(
        input_yaml_file)

    target_story_filename = tmpdir / "test.yml"
    writer = YAMLStoryWriter()
    writer.dump(target_story_filename, original_md_story_steps)

    processed_yaml_reader = YAMLStoryReader(default_domain, None, False)
    processed_yaml_story_steps = processed_yaml_reader.read_from_file(
        target_story_filename)

    assert len(processed_yaml_story_steps) == len(original_yaml_story_steps)
    for processed_step, original_step in zip(processed_yaml_story_steps,
                                             original_yaml_story_steps):
        assert len(processed_step.events) == len(original_step.events)
Example #3
0
async def test_forms_are_converted(domain: Domain):
    original_yaml_reader = YAMLStoryReader(domain, None)
    original_yaml_story_steps = original_yaml_reader.read_from_file(
        "data/test_yaml_stories/stories_form.yml")

    assert YAMLStoryWriter.stories_contain_loops(original_yaml_story_steps)

    writer = YAMLStoryWriter()

    with pytest.warns(None) as record:
        writer.dumps(original_yaml_story_steps)

    assert len(record) == 0
Example #4
0
    async def convert_and_write(cls, source_path: Path,
                                output_path: Path) -> None:
        """Converts the given training data file and saves it to the output directory.

        Args:
            source_path: Path to the training data file.
            output_path: Path to the output directory.
        """
        from rasa.shared.core.training_data.story_reader.yaml_story_reader import (
            KEY_ACTIVE_LOOP, )

        # check if source file is test stories file
        if MarkdownStoryReader.is_test_stories_file(source_path):
            reader = MarkdownStoryReader(
                is_used_for_training=False,
                use_e2e=True,
                ignore_deprecation_warning=True,
            )
            output_core_path = cls._generate_path_for_converted_test_data_file(
                source_path, output_path)
        else:
            reader = MarkdownStoryReader(is_used_for_training=False,
                                         ignore_deprecation_warning=True)
            output_core_path = cls.generate_path_for_converted_training_data_file(
                source_path, output_path)

        steps = reader.read_from_file(source_path)

        if YAMLStoryWriter.stories_contain_loops(steps):
            print_warning(
                f"Training data file '{source_path}' contains forms. "
                f"Any 'form' events will be converted to '{KEY_ACTIVE_LOOP}' events. "
                f"Please note that in order for these stories to work you still "
                f"need the 'FormPolicy' to be active. However the 'FormPolicy' is "
                f"deprecated, please consider switching to the new 'RulePolicy', "
                f"for which you can find the documentation here: "
                f"{rasa.shared.constants.DOCS_URL_RULES}.")

        writer = YAMLStoryWriter()
        writer.dump(
            output_core_path,
            steps,
            is_test_story=MarkdownStoryReader.is_test_stories_file(
                source_path),
        )

        print_success(
            f"Converted Core file: '{source_path}' >> '{output_core_path}'.")
Example #5
0
async def test_forms_are_converted(default_domain: Domain):
    original_md_reader = MarkdownStoryReader(default_domain,
                                             None,
                                             False,
                                             is_used_for_training=False)
    original_md_story_steps = original_md_reader.read_from_file(
        "data/test_stories/stories_form.md")

    assert YAMLStoryWriter.stories_contain_loops(original_md_story_steps)

    writer = YAMLStoryWriter()

    with pytest.warns(None) as record:
        writer.dumps(original_md_story_steps)

    assert len(record) == 0