Skip to content
This repository was archived by the owner on Jun 24, 2020. It is now read-only.

Commit 20d96f1

Browse files
author
Nathan Zylbersztejn
authored
Merge pull request #31 from mrbot-ai/swap_none_intents
Swap none intents
2 parents 0a5ed5f + eda4822 commit 20d96f1

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

rasa_addons/rules.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ def filter_entities(self, parse_data):
7070

7171
if len(filtered) < len(parse_data['entities']):
7272
# logging first
73-
logger.warn("entity(ies) were removed from parse stories")
73+
logger.warning("entity(ies) were removed from parse stories")
7474
parse_data['entities'] = filtered
7575

7676
def run_swap_intent_rules(self, parse_data, tracker):
77-
# don't do anything if no intent is present
78-
if parse_data["intent"]["name"] is None or parse_data["intent"]["name"] == "":
79-
return
77+
# # don't do anything if no intent is present
78+
# if parse_data["intent"]["name"] is None or parse_data["intent"]["name"] == "":
79+
# return
8080

8181
previous_action = self._get_previous_action(tracker)
8282

@@ -87,24 +87,29 @@ def run_swap_intent_rules(self, parse_data, tracker):
8787
@staticmethod
8888
def _swap_intent(parse_data, previous_action, rule):
8989
# don't do anything if no intent is present
90-
if parse_data["intent"]["name"] is None or parse_data["intent"]["name"] == "":
91-
return
90+
# if parse_data["intent"]["name"] is None or parse_data["intent"]["name"] == "":
91+
# return
9292

9393
# for an after rule
9494
if previous_action and 'after' in rule and re.match(rule['after'], previous_action):
9595
return Rules._swap_intent_after(parse_data, rule)
9696

9797
# for a general substitution
98-
elif 'after' not in rule and re.match(rule['intent'], parse_data['intent']['name']):
99-
return Rules.swap_intent_with(parse_data, rule)
98+
elif 'after' not in rule:
99+
if rule['intent'] is None or parse_data['intent']['name'] is None:
100+
return
101+
if (rule['intent'] is None and parse_data['intent']['name'] is None) \
102+
or (re.match(rule['intent'], parse_data['intent']['name'])):
103+
return Rules.swap_intent_with(parse_data, rule)
100104

101105
@staticmethod
102106
def _swap_intent_after(parse_data, rule):
103107
rule['unless'] = rule['unless'] if 'unless' in rule else []
104-
if parse_data['intent']['name'] not in rule['unless']:
105-
logger.warn(
108+
if parse_data['intent']['name'] is None or parse_data['intent']['name'] not in rule['unless']:
109+
logger.warning(
106110
"intent '{}' was replaced with '{}'".format(parse_data['intent']['name'], rule['intent']))
107111
parse_data['intent']['name'] = rule['intent']
112+
parse_data['intent']['confidence'] = 1.0
108113
parse_data.pop('intent_ranking', None)
109114
return True
110115

tests/test_rules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_swap_intent_none():
105105
# make sure intent swapped
106106
parse_data = {"intent": {"name": None, "confidence": 0.0}}
107107
Rules._swap_intent(parse_data, "utter_something", swap_rules.rules[0])
108-
assert parse_data["intent"]["name"] is None
108+
assert parse_data["intent"]["name"] == "intent_something"
109109

110110

111111
def test_swap_intent_empty():

0 commit comments

Comments
 (0)