From 56dd1c84a1f73c99ece52b773dfbff242343fe66 Mon Sep 17 00:00:00 2001 From: Christof Dorner Date: Wed, 20 Jan 2021 13:54:42 +0100 Subject: [PATCH 1/8] Extend test case for example metadata --- .../training_data/formats/test_rasa_yaml.py | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) 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 7369d86c58fc..842e504b9ba4 100644 --- a/tests/shared/nlu/training_data/formats/test_rasa_yaml.py +++ b/tests/shared/nlu/training_data/formats/test_rasa_yaml.py @@ -19,13 +19,15 @@ ) -MULTILINE_INTENT_EXAMPLES = f""" -version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}" +MULTILINE_INTENT_EXAMPLES = f"""version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}" nlu: - intent: intent_name examples: | - how much CO2 will that use? - how much carbon will a one way flight from [new york]{{"entity": "city", "role": "from"}} to california produce? + - what's the carbon footprint of a flight from london to new york? + - how much co2 to new york? + - how much co2 is produced on a return flight from london to new york? """ MULTILINE_INTENT_EXAMPLE_WITH_SYNONYM = """ @@ -43,7 +45,7 @@ - how much carbon will a one way flight from [new york]{"entity": "city", "role": "from"} to california produce? """ -INTENT_EXAMPLES_WITH_METADATA = """ +INTENT_EXAMPLES_WITH_METADATA = f"""version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}" nlu: - intent: intent_name metadata: @@ -54,7 +56,14 @@ metadata: sentiment: positive - text: | - how much carbon will a one way flight from [new york]{"entity": "city", "role": "from"} to california produce? + how much carbon will a one way flight from [new york]{{"entity": "city", "role": "from"}} to california produce? + metadata: co2-trip-calculation + - text: | + how much CO2 to [new york]{{"entity": "city", "role": "to"}}? +- intent: greet + examples: | + - Hi + - Hello """ MINIMAL_VALID_EXAMPLE = """ @@ -141,7 +150,7 @@ def test_multiline_intent_is_parsed(example: Text): assert not len(record) - assert len(training_data.training_examples) == 2 + assert len(training_data.training_examples) == 5 assert training_data.training_examples[0].get( INTENT ) == training_data.training_examples[1].get(INTENT) @@ -156,13 +165,16 @@ def test_intent_with_metadata_is_parsed(): assert not len(record) - assert len(training_data.training_examples) == 2 - example_1, example_2 = training_data.training_examples + assert len(training_data.training_examples) == 5 + example_1, example_2, *other_examples = training_data.training_examples assert example_1.get(METADATA) == { METADATA_INTENT: ["johnny"], METADATA_EXAMPLE: {"sentiment": "positive"}, } - assert example_2.get(METADATA) == {METADATA_INTENT: ["johnny"]} + assert example_2.get(METADATA) == { + METADATA_INTENT: ["johnny"], + METADATA_EXAMPLE: "co2-trip-calculation", + } # This test would work only with examples that have a `version` key specified From 59334cc9064fceb1cde43898b9c8bd74f3480985 Mon Sep 17 00:00:00 2001 From: Christof Dorner Date: Wed, 20 Jan 2021 14:15:55 +0100 Subject: [PATCH 2/8] Render NLU example metadata back into YAML files This preserves the YAML structure of the input as much as possible. --- .../nlu/training_data/formats/rasa_yaml.py | 60 +++++++++++++++---- .../nlu/training_data/formats/readerwriter.py | 6 +- .../training_data/formats/test_rasa_yaml.py | 35 +++++++++++ 3 files changed, 90 insertions(+), 11 deletions(-) diff --git a/rasa/shared/nlu/training_data/formats/rasa_yaml.py b/rasa/shared/nlu/training_data/formats/rasa_yaml.py index ce254b109b01..5d63a9f0c53a 100644 --- a/rasa/shared/nlu/training_data/formats/rasa_yaml.py +++ b/rasa/shared/nlu/training_data/formats/rasa_yaml.py @@ -8,6 +8,7 @@ from rasa.shared.exceptions import YamlException from rasa.shared.utils import validation from ruamel.yaml import StringIO +from ruamel.yaml.scalarstring import LiteralScalarString from rasa.shared.constants import ( DOCS_URL_TRAINING_DATA, @@ -36,6 +37,7 @@ KEY_LOOKUP = "lookup" KEY_LOOKUP_EXAMPLES = "examples" KEY_METADATA = "metadata" +KEY_METADATA_EXAMPLE = "example" MULTILINE_TRAINING_EXAMPLE_LEADING_SYMBOL = "-" @@ -470,21 +472,59 @@ def process_training_examples_by_key( key_examples: Text, example_extraction_predicate=lambda x: x, ) -> List[OrderedDict]: - from ruamel.yaml.scalarstring import LiteralScalarString - result = [] - for entity_key, examples in training_examples.items(): - converted_examples = [ - TrainingDataWriter.generate_list_item( - example_extraction_predicate(example).strip(STRIP_SYMBOLS) - ) - for example in examples - ] + for entity_key, examples in training_examples.items(): + converted_examples = [] + render_as_objects = False + for example in examples: + converted_example = { + KEY_INTENT_TEXT: example_extraction_predicate(example) + } + + if isinstance(example, dict) and KEY_METADATA_EXAMPLE in example.get( + KEY_METADATA, {} + ): + render_as_objects = True + converted_example[KEY_METADATA] = example[KEY_METADATA][ + KEY_METADATA_EXAMPLE + ] + + converted_examples.append(converted_example) next_item = OrderedDict() next_item[key_name] = entity_key - next_item[key_examples] = LiteralScalarString("".join(converted_examples)) + + if render_as_objects: + rendered_examples = RasaYAMLWriter._render_training_examples_as_objects( + converted_examples + ) + else: + rendered_examples = RasaYAMLWriter._render_training_examples_as_text( + converted_examples + ) + next_item[key_examples] = rendered_examples + result.append(next_item) return result + + @staticmethod + def _render_training_examples_as_objects(examples: List[Dict]) -> List[Dict]: + def render(example: Dict) -> Dict: + value = example[KEY_INTENT_TEXT] + example[KEY_INTENT_TEXT] = LiteralScalarString( + TrainingDataWriter.generate_string_item(value) + ) + return example + + return [render(ex) for ex in examples] + + @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 LiteralScalarString("".join([render(example) for example in examples])) diff --git a/rasa/shared/nlu/training_data/formats/readerwriter.py b/rasa/shared/nlu/training_data/formats/readerwriter.py index 2a538833b929..5e2bba93fe89 100644 --- a/rasa/shared/nlu/training_data/formats/readerwriter.py +++ b/rasa/shared/nlu/training_data/formats/readerwriter.py @@ -69,8 +69,12 @@ def prepare_training_examples(training_data: "TrainingData") -> OrderedDict: @staticmethod def generate_list_item(text: Text) -> Text: """Generates text for a list item.""" + return f"- {TrainingDataWriter.generate_string_item(text)}" - return f"- {rasa.shared.nlu.training_data.util.encode_string(text)}\n" + @staticmethod + def generate_string_item(text: Text) -> Text: + """Generates text for a string item.""" + return f"{rasa.shared.nlu.training_data.util.encode_string(text)}\n" @staticmethod def generate_message(message: Dict[Text, Any]) -> Text: 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 842e504b9ba4..383036b4d43f 100644 --- a/tests/shared/nlu/training_data/formats/test_rasa_yaml.py +++ b/tests/shared/nlu/training_data/formats/test_rasa_yaml.py @@ -66,6 +66,25 @@ - Hello """ +INTENT_EXAMPLES_WITH_METADATA_ROUNDTRIP = f"""version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}" +nlu: +- intent: intent_name + examples: + - text: | + how much CO2 will that use? + metadata: + sentiment: positive + - text: | + how much carbon will a one way flight from [new york]{{"entity": "city", "role": "from"}} to california produce? + metadata: co2-trip-calculation + - text: | + how much CO2 to [new york]{{"entity": "city", "role": "to"}}? +- intent: greet + examples: | + - Hi + - Hello +""" + MINIMAL_VALID_EXAMPLE = """ nlu:\n stories: @@ -177,6 +196,22 @@ def test_intent_with_metadata_is_parsed(): } +def test_metadata_roundtrip(): + reader = RasaYAMLReader() + result = reader.reads(INTENT_EXAMPLES_WITH_METADATA_ROUNDTRIP) + + dumped = RasaYAMLWriter().dumps(result) + assert dumped == INTENT_EXAMPLES_WITH_METADATA_ROUNDTRIP + + validation_reader = RasaYAMLReader() + dumped_result = validation_reader.reads(dumped) + + assert dumped_result.training_examples == result.training_examples + + # dumping again should also not change the format + assert dumped == RasaYAMLWriter().dumps(dumped_result) + + # This test would work only with examples that have a `version` key specified @pytest.mark.parametrize( "example", From cb8b1abe83b5349c9385037f283981f2d53a0bf9 Mon Sep 17 00:00:00 2001 From: Christof Dorner Date: Wed, 20 Jan 2021 15:59:43 +0100 Subject: [PATCH 3/8] Render NLU intent metadata back into YAML files --- .../nlu/training_data/formats/rasa_yaml.py | 57 ++++++++++++------- .../training_data/formats/test_rasa_yaml.py | 23 +------- 2 files changed, 38 insertions(+), 42 deletions(-) diff --git a/rasa/shared/nlu/training_data/formats/rasa_yaml.py b/rasa/shared/nlu/training_data/formats/rasa_yaml.py index 5d63a9f0c53a..221fe63b4c64 100644 --- a/rasa/shared/nlu/training_data/formats/rasa_yaml.py +++ b/rasa/shared/nlu/training_data/formats/rasa_yaml.py @@ -37,6 +37,7 @@ KEY_LOOKUP = "lookup" KEY_LOOKUP_EXAMPLES = "examples" KEY_METADATA = "metadata" +KEY_METADATA_INTENT = "intent" KEY_METADATA_EXAMPLE = "example" MULTILINE_TRAINING_EXAMPLE_LEADING_SYMBOL = "-" @@ -475,40 +476,52 @@ def process_training_examples_by_key( result = [] for entity_key, examples in training_examples.items(): - converted_examples = [] - render_as_objects = False - for example in examples: - converted_example = { - KEY_INTENT_TEXT: example_extraction_predicate(example) - } - - if isinstance(example, dict) and KEY_METADATA_EXAMPLE in example.get( - KEY_METADATA, {} - ): - render_as_objects = True - converted_example[KEY_METADATA] = example[KEY_METADATA][ - KEY_METADATA_EXAMPLE - ] - - converted_examples.append(converted_example) + converted, intent_metadata = RasaYAMLWriter._convert_training_examples( + examples, example_extraction_predicate + ) next_item = OrderedDict() next_item[key_name] = entity_key + if intent_metadata: + next_item[KEY_METADATA] = intent_metadata + render_as_objects = True in [KEY_METADATA in ex for ex in converted] if render_as_objects: - rendered_examples = RasaYAMLWriter._render_training_examples_as_objects( - converted_examples + rendered = RasaYAMLWriter._render_training_examples_as_objects( + converted ) else: - rendered_examples = RasaYAMLWriter._render_training_examples_as_text( - converted_examples - ) - next_item[key_examples] = rendered_examples + rendered = RasaYAMLWriter._render_training_examples_as_text(converted) + next_item[key_examples] = rendered result.append(next_item) return result + @staticmethod + def _convert_training_examples( + training_examples: List[Dict], example_extraction_predicate=lambda x: x + ) -> Tuple[List[Dict], Optional[Dict]]: + """Returns converted training examples and potential intent metadata.""" + result = [] + intent_metadata = None + + for example in training_examples: + converted = {KEY_INTENT_TEXT: example_extraction_predicate(example)} + + if isinstance(example, dict) and KEY_METADATA in example: + metadata = example[KEY_METADATA] + + if KEY_METADATA_EXAMPLE in metadata: + converted[KEY_METADATA] = metadata[KEY_METADATA_EXAMPLE] + + if intent_metadata is None and KEY_METADATA_INTENT in metadata: + intent_metadata = metadata[KEY_METADATA_INTENT] + + result.append(converted) + + return result, intent_metadata + @staticmethod def _render_training_examples_as_objects(examples: List[Dict]) -> List[Dict]: def render(example: Dict) -> Dict: 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 383036b4d43f..829195e92a6f 100644 --- a/tests/shared/nlu/training_data/formats/test_rasa_yaml.py +++ b/tests/shared/nlu/training_data/formats/test_rasa_yaml.py @@ -61,29 +61,12 @@ - text: | how much CO2 to [new york]{{"entity": "city", "role": "to"}}? - intent: greet + metadata: initiate-conversation examples: | - Hi - Hello """ -INTENT_EXAMPLES_WITH_METADATA_ROUNDTRIP = f"""version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}" -nlu: -- intent: intent_name - examples: - - text: | - how much CO2 will that use? - metadata: - sentiment: positive - - text: | - how much carbon will a one way flight from [new york]{{"entity": "city", "role": "from"}} to california produce? - metadata: co2-trip-calculation - - text: | - how much CO2 to [new york]{{"entity": "city", "role": "to"}}? -- intent: greet - examples: | - - Hi - - Hello -""" MINIMAL_VALID_EXAMPLE = """ nlu:\n @@ -198,10 +181,10 @@ def test_intent_with_metadata_is_parsed(): def test_metadata_roundtrip(): reader = RasaYAMLReader() - result = reader.reads(INTENT_EXAMPLES_WITH_METADATA_ROUNDTRIP) + result = reader.reads(INTENT_EXAMPLES_WITH_METADATA) dumped = RasaYAMLWriter().dumps(result) - assert dumped == INTENT_EXAMPLES_WITH_METADATA_ROUNDTRIP + assert dumped == INTENT_EXAMPLES_WITH_METADATA validation_reader = RasaYAMLReader() dumped_result = validation_reader.reads(dumped) From d0b5956e1bd9358d3e6b5cd9ae193a4d6b035212 Mon Sep 17 00:00:00 2001 From: Christof Dorner Date: Wed, 20 Jan 2021 17:37:34 +0100 Subject: [PATCH 4/8] Add changelog item --- changelog/7731.improvement.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelog/7731.improvement.md diff --git a/changelog/7731.improvement.md b/changelog/7731.improvement.md new file mode 100644 index 000000000000..b0f2bca89db2 --- /dev/null +++ b/changelog/7731.improvement.md @@ -0,0 +1,2 @@ +Add support for in `RasaYAMLWriter` for writing intent and example metadata back +into NLU YAML files. From ff0e37fd45cbc5271512c2a267be90df87fa5d0f Mon Sep 17 00:00:00 2001 From: Christof Dorner Date: Fri, 22 Jan 2021 10:42:13 +0100 Subject: [PATCH 5/8] Strip example text for both rendering variants --- rasa/shared/nlu/training_data/formats/rasa_yaml.py | 10 ++++++---- .../nlu/training_data/formats/test_rasa_yaml.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) 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", From b63a05f9cb801bbf355dbb749933606bcc435a38 Mon Sep 17 00:00:00 2001 From: Christof Dorner Date: Fri, 22 Jan 2021 10:46:12 +0100 Subject: [PATCH 6/8] Use metadata constants from `shared.nlu.constants` --- rasa/shared/nlu/training_data/formats/rasa_yaml.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/rasa/shared/nlu/training_data/formats/rasa_yaml.py b/rasa/shared/nlu/training_data/formats/rasa_yaml.py index 8bac2301583a..d4d2cd7798cb 100644 --- a/rasa/shared/nlu/training_data/formats/rasa_yaml.py +++ b/rasa/shared/nlu/training_data/formats/rasa_yaml.py @@ -14,6 +14,7 @@ DOCS_URL_TRAINING_DATA, LATEST_TRAINING_DATA_FORMAT_VERSION, ) +from rasa.shared.nlu.constants import METADATA_INTENT, METADATA_EXAMPLE from rasa.shared.nlu.training_data.formats.readerwriter import ( TrainingDataReader, TrainingDataWriter, @@ -37,8 +38,6 @@ KEY_LOOKUP = "lookup" KEY_LOOKUP_EXAMPLES = "examples" KEY_METADATA = "metadata" -KEY_METADATA_INTENT = "intent" -KEY_METADATA_EXAMPLE = "example" MULTILINE_TRAINING_EXAMPLE_LEADING_SYMBOL = "-" @@ -516,11 +515,11 @@ def _convert_training_examples( if isinstance(example, dict) and KEY_METADATA in example: metadata = example[KEY_METADATA] - if KEY_METADATA_EXAMPLE in metadata: - converted[KEY_METADATA] = metadata[KEY_METADATA_EXAMPLE] + if METADATA_EXAMPLE in metadata: + converted[KEY_METADATA] = metadata[METADATA_EXAMPLE] - if intent_metadata is None and KEY_METADATA_INTENT in metadata: - intent_metadata = metadata[KEY_METADATA_INTENT] + if intent_metadata is None and METADATA_INTENT in metadata: + intent_metadata = metadata[METADATA_INTENT] result.append(converted) From cb4ba62715342fae9b5946f643452290d975a9bf Mon Sep 17 00:00:00 2001 From: Christof Dorner Date: Fri, 22 Jan 2021 11:18:45 +0100 Subject: [PATCH 7/8] Address PR comments --- .../nlu/training_data/formats/rasa_yaml.py | 46 ++++++++++++------- .../training_data/formats/test_rasa_yaml.py | 14 +++++- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/rasa/shared/nlu/training_data/formats/rasa_yaml.py b/rasa/shared/nlu/training_data/formats/rasa_yaml.py index d4d2cd7798cb..d8d6f480e5a2 100644 --- a/rasa/shared/nlu/training_data/formats/rasa_yaml.py +++ b/rasa/shared/nlu/training_data/formats/rasa_yaml.py @@ -1,7 +1,7 @@ import logging from collections import OrderedDict from pathlib import Path -from typing import Text, Any, List, Dict, Tuple, Union, Iterator, Optional +from typing import Text, Any, List, Dict, Tuple, Union, Iterator, Optional, Callable import rasa.shared.data from rasa.shared.core.domain import Domain @@ -470,39 +470,40 @@ def process_training_examples_by_key( training_examples: Dict, key_name: Text, key_examples: Text, - example_extraction_predicate=lambda x: x, + example_extraction_predicate: Callable[[Dict[Text, Any]], Text] = lambda x: x, ) -> List[OrderedDict]: - result = [] + intents = [] - for entity_key, examples in training_examples.items(): + for intent_name, examples in training_examples.items(): converted, intent_metadata = RasaYAMLWriter._convert_training_examples( examples, example_extraction_predicate ) - next_item = OrderedDict() - next_item[key_name] = entity_key + intent = OrderedDict() + intent[key_name] = intent_name if intent_metadata: - next_item[KEY_METADATA] = intent_metadata + intent[KEY_METADATA] = intent_metadata - render_as_objects = True in [KEY_METADATA in ex for ex in converted] + render_as_objects = any(KEY_METADATA in ex for ex in converted) if render_as_objects: rendered = RasaYAMLWriter._render_training_examples_as_objects( converted ) else: rendered = RasaYAMLWriter._render_training_examples_as_text(converted) - next_item[key_examples] = rendered + intent[key_examples] = rendered - result.append(next_item) + intents.append(intent) - return result + return intents @staticmethod def _convert_training_examples( - training_examples: List[Dict], example_extraction_predicate=lambda x: x + training_examples: List[Dict], + example_extraction_predicate: Callable[[Dict[Text, Any]], Text] = lambda x: x, ) -> Tuple[List[Dict], Optional[Dict]]: """Returns converted training examples and potential intent metadata.""" - result = [] + converted_examples = [] intent_metadata = None for example in training_examples: @@ -521,16 +522,27 @@ def _convert_training_examples( if intent_metadata is None and METADATA_INTENT in metadata: intent_metadata = metadata[METADATA_INTENT] - result.append(converted) + converted_examples.append(converted) - return result, intent_metadata + return converted_examples, intent_metadata @staticmethod def _render_training_examples_as_objects(examples: List[Dict]) -> List[Dict]: + """Renders training examples as objects with its `text` item as a literal scalar string. + + Given the input of a single example: + {'text': 'how much CO2 will that use?'} + Its return value is a dictionary that will be rendered in YAML as: + ``` + text: | + how much CO2 will that use? + ``` + """ + def render(example: Dict) -> Dict: - value = example[KEY_INTENT_TEXT] + text = example[KEY_INTENT_TEXT] example[KEY_INTENT_TEXT] = LiteralScalarString( - TrainingDataWriter.generate_string_item(value) + TrainingDataWriter.generate_string_item(text) ) return example 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 9386a7ec5394..4e85cd77d0f2 100644 --- a/tests/shared/nlu/training_data/formats/test_rasa_yaml.py +++ b/tests/shared/nlu/training_data/formats/test_rasa_yaml.py @@ -28,6 +28,8 @@ - what's the carbon footprint of a flight from london to new york? - how much co2 to new york? - how much co2 is produced on a return flight from london to new york? + - what's the co2 usage of a return flight to new york? + - can you calculate the co2 footprint of a flight to london? """ MULTILINE_INTENT_EXAMPLE_WITH_SYNONYM = """ @@ -65,6 +67,14 @@ examples: | - Hi - Hello +- intent: goodbye + examples: + - text: | + bye + metadata: positive-sentiment + - text: | + goodbye + metadata: positive-sentiment """ @@ -152,7 +162,7 @@ def test_multiline_intent_is_parsed(example: Text): assert not len(record) - assert len(training_data.training_examples) == 5 + assert len(training_data.training_examples) == 7 assert training_data.training_examples[0].get( INTENT ) == training_data.training_examples[1].get(INTENT) @@ -167,7 +177,7 @@ def test_intent_with_metadata_is_parsed(): assert not len(record) - assert len(training_data.training_examples) == 5 + assert len(training_data.training_examples) == 7 example_1, example_2, *other_examples = training_data.training_examples assert example_1.get(METADATA) == { METADATA_INTENT: ["johnny"], From ca52ad80cbf8df77bf7676ef81e07c9fc21b6e51 Mon Sep 17 00:00:00 2001 From: Christof Dorner Date: Fri, 22 Jan 2021 11:23:08 +0100 Subject: [PATCH 8/8] Remove superfluous test assertion --- tests/shared/nlu/training_data/formats/test_rasa_yaml.py | 3 --- 1 file changed, 3 deletions(-) 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 4e85cd77d0f2..6749f82a4a88 100644 --- a/tests/shared/nlu/training_data/formats/test_rasa_yaml.py +++ b/tests/shared/nlu/training_data/formats/test_rasa_yaml.py @@ -201,9 +201,6 @@ def test_metadata_roundtrip(): assert dumped_result.training_examples == result.training_examples - # dumping again should also not change the format - assert dumped == RasaYAMLWriter().dumps(dumped_result) - def test_write_metadata_stripped(): reader = RasaYAMLReader()