-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from smn-snkl/abstract_forms
Abstract Action Detection
- Loading branch information
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
from rasa_core_sdk import Action, Tracker | ||
from rasa_core_sdk.events import SlotSet | ||
from rasa_core_sdk.executor import ActionExecutor, CollectingDispatcher | ||
|
||
|
||
class CustomActionBase(Action): | ||
@classmethod | ||
def name(cls): | ||
# Name method needed to test if base action was registered | ||
return "base_action" | ||
|
||
class Meta: | ||
abstract = True | ||
|
||
@staticmethod | ||
def some_common_feature(): | ||
return "test" | ||
|
||
def run(self, dispatcher, tracker, domain): | ||
raise NotImplementedError | ||
|
||
|
||
class CustomAction(CustomActionBase): | ||
|
||
@classmethod | ||
def name(cls): | ||
return "custom_action" | ||
|
||
def run(self, dispatcher, tracker, domain): | ||
return [SlotSet('test', self.some_common_feature())] | ||
|
||
|
||
def test_abstract_action(): | ||
executor = ActionExecutor() | ||
executor.register_package('tests') | ||
assert CustomAction.name() in executor.actions | ||
assert CustomActionBase.name() not in executor.actions | ||
|
||
dispatcher = CollectingDispatcher() | ||
tracker = Tracker('test', {}, {}, [], False, None, {}, 'listen') | ||
domain = {} | ||
|
||
events = CustomAction().run(dispatcher, tracker, domain) | ||
assert events == [SlotSet('test', "test")] |