diff --git a/rasa/shared/nlu/training_data/formats/rasa_yaml.py b/rasa/shared/nlu/training_data/formats/rasa_yaml.py index 221fe63b4c64..8bac2301583a 100644 --- a/rasa/shared/nlu/training_data/formats/rasa_yaml.py +++ b/rasa/shared/nlu/training_data/formats/rasa_yaml.py @@ -507,7 +507,11 @@ def _convert_training_examples( intent_metadata = None for example in training_examples: - converted = {KEY_INTENT_TEXT: example_extraction_predicate(example)} + converted = { + KEY_INTENT_TEXT: example_extraction_predicate(example).strip( + STRIP_SYMBOLS + ) + } if isinstance(example, dict) and KEY_METADATA in example: metadata = example[KEY_METADATA] @@ -536,8 +540,6 @@ def render(example: Dict) -> Dict: @staticmethod def _render_training_examples_as_text(examples: List[Dict]) -> List[Text]: def render(example: Dict) -> Text: - return TrainingDataWriter.generate_list_item( - example[KEY_INTENT_TEXT].strip(STRIP_SYMBOLS) - ) + return TrainingDataWriter.generate_list_item(example[KEY_INTENT_TEXT]) return LiteralScalarString("".join([render(example) for example in examples])) diff --git a/tests/shared/nlu/training_data/formats/test_rasa_yaml.py b/tests/shared/nlu/training_data/formats/test_rasa_yaml.py index 829195e92a6f..9386a7ec5394 100644 --- a/tests/shared/nlu/training_data/formats/test_rasa_yaml.py +++ b/tests/shared/nlu/training_data/formats/test_rasa_yaml.py @@ -195,6 +195,17 @@ def test_metadata_roundtrip(): assert dumped == RasaYAMLWriter().dumps(dumped_result) +def test_write_metadata_stripped(): + reader = RasaYAMLReader() + result = reader.reads(INTENT_EXAMPLES_WITH_METADATA) + + # Add strippable characters to first example text + result.training_examples[0].data["text"] += " \r\n " + + dumped = RasaYAMLWriter().dumps(result) + assert dumped == INTENT_EXAMPLES_WITH_METADATA + + # This test would work only with examples that have a `version` key specified @pytest.mark.parametrize( "example",