Skip to content

Commit 3185a23

Browse files
committed
Revert "dump NLU data in original order"
This reverts commit 53c7b02.
1 parent 53c7b02 commit 3185a23

File tree

3 files changed

+15
-41
lines changed

3 files changed

+15
-41
lines changed

CHANGELOG.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ Added
1515

1616
Changed
1717
-------
18-
- When NLU training data is dumped as Markdown file the intents are not longer ordered
19-
alphabetically, but in the original order of given training data
2018

2119
Removed
2220
-------

rasa/nlu/training_data/formats/markdown.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -211,31 +211,23 @@ def dumps(self, training_data: "TrainingData") -> Text:
211211
def _generate_training_examples_md(self, training_data: "TrainingData") -> Text:
212212
"""Generates markdown training examples."""
213213

214-
from collections import defaultdict
215-
216-
training_examples = defaultdict(list)
217-
218-
# Sort by intent while keeping basic intent order
219-
for example in [e.as_dict_nlu() for e in training_data.training_examples]:
220-
intent = example[MESSAGE_INTENT_ATTRIBUTE]
221-
training_examples[intent].append(example)
222-
214+
# Sort training data by intent
215+
training_examples = sorted(
216+
[e.as_dict_nlu() for e in training_data.training_examples],
217+
key=lambda k: k[MESSAGE_INTENT_ATTRIBUTE],
218+
)
223219
md = ""
220+
for i, example in enumerate(training_examples):
221+
intent = training_examples[i - 1][MESSAGE_INTENT_ATTRIBUTE]
222+
if i == 0 or intent != example[MESSAGE_INTENT_ATTRIBUTE]:
223+
md += self._generate_section_header_md(
224+
INTENT,
225+
example[MESSAGE_INTENT_ATTRIBUTE],
226+
example.get(MESSAGE_RESPONSE_KEY_ATTRIBUTE, None),
227+
i != 0,
228+
)
224229

225-
for intent, examples in training_examples.items():
226-
for i, example in enumerate(examples):
227-
did_intent_change = i == 0
228-
is_first_line = md == ""
229-
230-
if did_intent_change:
231-
md += self._generate_section_header_md(
232-
INTENT,
233-
intent,
234-
example.get(MESSAGE_RESPONSE_KEY_ATTRIBUTE, None),
235-
not is_first_line,
236-
)
237-
238-
md += self._generate_item_md(self._generate_message_md(example))
230+
md += self._generate_item_md(self._generate_message_md(example))
239231

240232
return md
241233

tests/nlu/base/test_training_data.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -595,19 +595,3 @@ def test_section_value_with_delimiter():
595595
"data/test/markdown_single_sections/section_with_delimiter.md"
596596
)
597597
assert td_section_with_delimiter.entity_synonyms == {"10:00 am": "10:00"}
598-
599-
600-
def test_markdown_order():
601-
r = MarkdownReader()
602-
603-
md = """## intent:z
604-
- i'm looking for a place to eat
605-
- i'm looking for a place in the [north](loc-direction) of town
606-
607-
## intent:a
608-
- intent a
609-
- also very important
610-
"""
611-
612-
training_data = r.reads(md)
613-
assert training_data.nlu_as_markdown() == md

0 commit comments

Comments
 (0)