Skip to content

Commit

Permalink
Merge 05378e5 into f699717
Browse files Browse the repository at this point in the history
  • Loading branch information
gausie committed Jul 25, 2019
2 parents f699717 + 05378e5 commit 179b0fd
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
9 changes: 6 additions & 3 deletions data/test_multifile_stories/stories_part_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
## show_it_all
> check_greet
> check_hello <!-- allows multiple entry points -->
* next_intent
- utter_greet <!-- actions taken by the bot -->

> check_intermediate <!-- allows intermediate checkpoints -->
* change_bank_details
- utter_default <!-- allows to end without checkpoints -->

## entities and slots
* greet{"cuisine": "italian"}
- slot{"cuisine": "italian"}
- utter_default
- utter_default <!-- just so length is different from the checkpoint story -->
6 changes: 6 additions & 0 deletions data/test_stories/stories.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@
> check_intermediate <!-- allows intermediate checkpoints -->
* change_bank_details
- utter_default <!-- allows to end without checkpoints -->

## entities and slots
* greet{"cuisine": "italian"}
- slot{"cuisine": "italian"}
- utter_default
- utter_default <!-- just so length is different from the checkpoint story -->
23 changes: 20 additions & 3 deletions rasa/core/training/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,28 @@ def _create_graph(fontsize: int = 12) -> "networkx.MultiDiGraph":
return graph


def sanitize(s):
def escape(pattern: Text):
"""Escape special characters in a string.
Used to fix different behavior in re.escape() for python
versions < 3.7 compared to >= 3.7.
"""
import sys
import re

_special_chars_map = {i: "\\" + chr(i) for i in b"()[]{}?*+-|^$\\.&~# \t\n\r\v\f"}

if sys.version_info >= (3, 7):
return re.escape(pattern)
else:
return pattern.translate(_special_chars_map)


def sanitize(s: Optional[Text] = None) -> Optional[Text]:
if s:
return re.escape(s)
return escape(s)
else:
return s
return None


def _add_message_edge(
Expand Down
6 changes: 4 additions & 2 deletions tests/core/test_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ async def test_can_read_test_story(default_domain):
tracker_limit=1000,
remove_duplicates=False,
)
assert len(trackers) == 7
assert len(trackers) == 8
# this should be the story simple_story_with_only_end -> show_it_all
# the generated stories are in a non stable order - therefore we need to
# do some trickery to find the one we want to test
tracker = [t for t in trackers if len(t.events) == 5][0]
trackers = [t for t in trackers if len(t.events) == 5]
assert len(trackers) == 1
tracker = trackers[0]
assert tracker.events[0] == ActionExecuted("action_listen")
assert tracker.events[1] == UserUttered(
"simple",
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ async def test_story_visualization(default_domain, tmpdir):
should_merge_nodes=False,
)

assert len(generated_graph.nodes()) == 51
assert len(generated_graph.nodes()) == 54

assert len(generated_graph.edges()) == 56
assert len(generated_graph.edges()) == 60


async def test_story_visualization_with_merging(default_domain):
Expand Down
5 changes: 3 additions & 2 deletions tests/core/test_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ async def test_graph_persistence(default_domain, tmpdir):
should_merge_nodes=False,
)

generated_graph = nx_pydot.to_pydot(generated_graph)
generated_graph = str(nx_pydot.to_pydot(generated_graph))

assert isfile(out_file)

with open(out_file, "r") as graph_file:
content = graph_file.read()

assert r'label="/greet\{\"cuisine\":\ \"italian\"\}"' in generated_graph
assert "isClient = true" in content
assert "graph = `{}`".format(generated_graph.to_string()) in content
assert "graph = `{}`".format(generated_graph) in content

0 comments on commit 179b0fd

Please sign in to comment.