Skip to content

Commit

Permalink
Strip example text for both rendering variants
Browse files Browse the repository at this point in the history
  • Loading branch information
chdorner committed Jan 22, 2021
1 parent 2119479 commit c19dc43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 6 additions & 4 deletions rasa/shared/nlu/training_data/formats/rasa_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]))
11 changes: 11 additions & 0 deletions tests/shared/nlu/training_data/formats/test_rasa_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c19dc43

Please sign in to comment.