From 4c1d303555bc4c274645c8a3218d0b32183ce32b Mon Sep 17 00:00:00 2001 From: Piotr Biskup Date: Mon, 26 Apr 2021 13:31:00 +0200 Subject: [PATCH] add nlu module and code reformat --- Presenter.py | 0 View.py | 0 model/NaturalLanguageUnderstanding.py | 3 --- model/UserActFrame.py | 15 +++++++++++++++ presenter/Presenter.py | 9 +++++++++ .../chatbot_modules}/DialoguePolicy.py | 0 .../chatbot_modules}/DialogueStateTracker.py | 0 .../chatbot_modules}/NaturalLanguageGeneration.py | 1 - .../NaturalLanguageUnderstanding.py | 15 +++++++++++++++ view/View.py | 13 +++++++++++++ 10 files changed, 52 insertions(+), 4 deletions(-) delete mode 100644 Presenter.py delete mode 100644 View.py delete mode 100644 model/NaturalLanguageUnderstanding.py create mode 100644 model/UserActFrame.py create mode 100644 presenter/Presenter.py rename {model => presenter/chatbot_modules}/DialoguePolicy.py (100%) rename {model => presenter/chatbot_modules}/DialogueStateTracker.py (100%) rename {model => presenter/chatbot_modules}/NaturalLanguageGeneration.py (98%) create mode 100644 presenter/chatbot_modules/NaturalLanguageUnderstanding.py create mode 100644 view/View.py diff --git a/Presenter.py b/Presenter.py deleted file mode 100644 index e69de29..0000000 diff --git a/View.py b/View.py deleted file mode 100644 index e69de29..0000000 diff --git a/model/NaturalLanguageUnderstanding.py b/model/NaturalLanguageUnderstanding.py deleted file mode 100644 index f26d5cb..0000000 --- a/model/NaturalLanguageUnderstanding.py +++ /dev/null @@ -1,3 +0,0 @@ -class NaturalLanguageUnderstanding: - pass - diff --git a/model/UserActFrame.py b/model/UserActFrame.py new file mode 100644 index 0000000..4d0b096 --- /dev/null +++ b/model/UserActFrame.py @@ -0,0 +1,15 @@ +class UserActFrame: + + def __init__(self, act, parameters): + self.act = act + self.parameters = parameters + + def __str__(self): + result = "" + result += "Act: " + self.act + " Parameters: { " + for index, parameter in enumerate(self.parameters): + result += parameter + if index < len(self.parameters) - 1: + result += ', ' + result += ' }' + return result diff --git a/presenter/Presenter.py b/presenter/Presenter.py new file mode 100644 index 0000000..f837ab6 --- /dev/null +++ b/presenter/Presenter.py @@ -0,0 +1,9 @@ +from presenter.chatbot_modules.NaturalLanguageUnderstanding import NaturalLanguageUnderstanding + + +class Presenter: + + def process_user_input(self, user_input): + nlu = NaturalLanguageUnderstanding() + user_frames = nlu.text_to_user_frame(user_input) + return '' diff --git a/model/DialoguePolicy.py b/presenter/chatbot_modules/DialoguePolicy.py similarity index 100% rename from model/DialoguePolicy.py rename to presenter/chatbot_modules/DialoguePolicy.py diff --git a/model/DialogueStateTracker.py b/presenter/chatbot_modules/DialogueStateTracker.py similarity index 100% rename from model/DialogueStateTracker.py rename to presenter/chatbot_modules/DialogueStateTracker.py diff --git a/model/NaturalLanguageGeneration.py b/presenter/chatbot_modules/NaturalLanguageGeneration.py similarity index 98% rename from model/NaturalLanguageGeneration.py rename to presenter/chatbot_modules/NaturalLanguageGeneration.py index 217fe0b..8cdfd03 100644 --- a/model/NaturalLanguageGeneration.py +++ b/presenter/chatbot_modules/NaturalLanguageGeneration.py @@ -1,4 +1,3 @@ class NaturalLanguageGeneration: def get_frame(self, input_from_user): pass - diff --git a/presenter/chatbot_modules/NaturalLanguageUnderstanding.py b/presenter/chatbot_modules/NaturalLanguageUnderstanding.py new file mode 100644 index 0000000..86c8d34 --- /dev/null +++ b/presenter/chatbot_modules/NaturalLanguageUnderstanding.py @@ -0,0 +1,15 @@ +import re + +from model.UserActFrame import UserActFrame + + +class NaturalLanguageUnderstanding: + + def __init__(self): + self.user_acts = [ + (r"Cześć(.*)|czesc|Czesc", UserActFrame('hello()', [])), + (r"(.*)imię(.*)|Jak masz na imię(.*)", UserActFrame('request()', ['imię'])) + ] + + def text_to_user_frame(self, text): + return [user_act[1] for user_act in self.user_acts if re.match(user_act[0], text)] diff --git a/view/View.py b/view/View.py new file mode 100644 index 0000000..f3e9d10 --- /dev/null +++ b/view/View.py @@ -0,0 +1,13 @@ +from presenter.Presenter import Presenter + + +def init_chat(): + print('Witamy w systemie elektronicznej rezerwacji Biletów! W czym mogę pomóc?') + user_input = input() + result = Presenter().process_user_input(user_input) + for r in result: + print(r) + + +if __name__ == "__main__": + init_chat() \ No newline at end of file