This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
273 additions
and
56 deletions.
There are no files selected for viewing
Binary file not shown.
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,83 @@ | ||
#-*- coding: utf-8 -*- | ||
""" | ||
@brief test log(time=10s) | ||
""" | ||
|
||
import sys | ||
import os | ||
import unittest | ||
|
||
|
||
try: | ||
import src | ||
except ImportError: | ||
path = os.path.normpath( | ||
os.path.abspath( | ||
os.path.join( | ||
os.path.split(__file__)[0], | ||
"..", | ||
".."))) | ||
if path not in sys.path: | ||
sys.path.append(path) | ||
import src | ||
|
||
try: | ||
import pyquickhelper as skip_ | ||
except ImportError: | ||
path = os.path.normpath( | ||
os.path.abspath( | ||
os.path.join( | ||
os.path.split(__file__)[0], | ||
"..", | ||
"..", | ||
"..", | ||
"pyquickhelper", | ||
"src"))) | ||
if path not in sys.path: | ||
sys.path.append(path) | ||
import pyquickhelper as skip_ | ||
|
||
from pyquickhelper.loghelper import fLOG | ||
from pyquickhelper.pycode import get_temp_folder | ||
from src.jupytalk.mokadi import MokadiEngine, MokadiMessage | ||
from src.jupytalk.mokadi.mokadi_action_slides import MokadiActionSlides | ||
from src.jupytalk.mokadi.mokadi_action_conversation import MokadiActionConversation | ||
|
||
|
||
class TestEngineExtended(unittest.TestCase): | ||
|
||
def test_engine_ex(self): | ||
fLOG( | ||
__file__, | ||
self._testMethodName, | ||
OutputPrint=__name__ == "__main__") | ||
|
||
messages = ["MOKADI liste presentation", | ||
"MOKADI lire presentation 1 slide 2", | ||
"MOKADI hello"] | ||
|
||
temp = get_temp_folder(__file__, "temp_engine_ex") | ||
clog = fLOG | ||
folder = os.path.join(temp, "..", "data") | ||
|
||
actions = [MokadiActionSlides(folder, fLOG=fLOG), | ||
MokadiActionConversation(fLOG=fLOG), | ||
] | ||
|
||
engine = MokadiEngine(temp, clog, actions=actions) | ||
verif = 0 | ||
for i, text in enumerate(messages): | ||
fLOG("***", text) | ||
mes = MokadiMessage(text, 1) | ||
res = list(engine.process(mes, exc=True)) | ||
fLOG(res) | ||
self.assertTrue(len(res) > 0) | ||
if i == 2: | ||
self.assertEqual(len(res), 1) | ||
self.assertTrue(res[0].HasSound) | ||
verif += 1 | ||
self.assertTrue(verif > 0) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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
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
Empty file.
Binary file not shown.
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,57 @@ | ||
#-*- coding: utf-8 -*- | ||
""" | ||
@file | ||
@brief Defines an action for Mokadi. | ||
""" | ||
import os | ||
from .mokadi_action import MokadiAction | ||
from .mokadi_info import MokadiInfo | ||
from .mokadi_exceptions import MokadiException | ||
|
||
|
||
class MokadiActionConversation(MokadiAction): | ||
""" | ||
Action. Conversation. | ||
""" | ||
|
||
_sounds = {"hello": os.path.join(os.path.abspath(os.path.dirname(__file__)), "data", "hello.wav"), | ||
} | ||
|
||
def __init__(self, fLOG=None): | ||
""" | ||
Constructor. | ||
@param folder folder where to look for presentation | ||
@param fLOG logging function | ||
""" | ||
MokadiAction.__init__(self, fLOG=fLOG) | ||
|
||
def can_do(self, interpreted, message): | ||
""" | ||
Tells if the class can process the message. | ||
@param interpreted interpreted message | ||
@param message message | ||
@return true if the class can process the message | ||
""" | ||
if len(interpreted) <= 1: | ||
return False | ||
res = self.process_interpreted_message(interpreted, message) | ||
for info in res: | ||
return True | ||
return False | ||
|
||
def process_interpreted_message(self, interpretation, message): | ||
""" | ||
Process the interpreted message. | ||
@param interpretation interpretation | ||
@param message original message | ||
@return iterator on Info | ||
""" | ||
sentance = [w[0].lower() for w in interpretation[1:3]] | ||
if sentance[0] in {"hello", "bonjour"}: | ||
yield MokadiInfo("ok", "hello", sound=MokadiActionConversation._sounds["hello"]) | ||
else: | ||
raise MokadiException( | ||
"Unable to answer to '{0}'.".format(sentance)) |
Oops, something went wrong.