From 4747e3bb219781bd2438cc39fc071af2054e5ee5 Mon Sep 17 00:00:00 2001 From: Wiktor Date: Mon, 26 Apr 2021 15:00:45 +0200 Subject: [PATCH] responding to "jak masz na imie" + basic logic --- model/DialogueState.py | 1 - presenter/Presenter.py | 9 +++++++-- presenter/chatbot_modules/DialoguePolicy.py | 16 ++++++++++------ .../chatbot_modules/DialogueStateTracker.py | 14 -------------- .../chatbot_modules/NaturalLanguageGeneration.py | 10 ++++++++-- view/View.py | 5 ++--- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/model/DialogueState.py b/model/DialogueState.py index a486c67..1e655e8 100644 --- a/model/DialogueState.py +++ b/model/DialogueState.py @@ -3,5 +3,4 @@ class DialogueState: def __init__(self): self.currentActs = [] self.previousActs = [] - self.botName = 'Dia' self.date = None diff --git a/presenter/Presenter.py b/presenter/Presenter.py index 8ce77e6..1f7fb01 100644 --- a/presenter/Presenter.py +++ b/presenter/Presenter.py @@ -1,13 +1,18 @@ from presenter.chatbot_modules.DialogueStateTracker import DialogueStateTracker +from presenter.chatbot_modules.NaturalLanguageGeneration import NaturalLanguageGeneration from presenter.chatbot_modules.NaturalLanguageUnderstanding import NaturalLanguageUnderstanding +from presenter.chatbot_modules.DialoguePolicy import DialoguePolicy class Presenter: dialogue_state_tracker = DialogueStateTracker() nlu = NaturalLanguageUnderstanding() + policy = DialoguePolicy() + nlg = NaturalLanguageGeneration() def process_user_input(self, user_input): user_frames = self.nlu.text_to_user_frame(user_input) dialogue_state = self.dialogue_state_tracker.processUserAct(user_frames) - - return '' + system_frames = self.policy.resolve_system_acts(dialogue_state) + msg = self.nlg.generate_text(system_frames) + return msg diff --git a/presenter/chatbot_modules/DialoguePolicy.py b/presenter/chatbot_modules/DialoguePolicy.py index e5bb8e0..954536e 100644 --- a/presenter/chatbot_modules/DialoguePolicy.py +++ b/presenter/chatbot_modules/DialoguePolicy.py @@ -1,9 +1,13 @@ -from model.DialogueState import DialogueState +from model.SystemActFrame import SystemActFrame + + class DialoguePolicy: - def __init__(self): - pass + def resolve_system_acts(self, dialogueState): + system_acts = [] + for act in dialogueState.currentActs: + if "request()" in act.act: + if 'imię' in act.parameters: + system_acts.append(SystemActFrame("inform()", ["imię"])) - def resolveSystemActs(self, dialogueState): - - pass + return system_acts diff --git a/presenter/chatbot_modules/DialogueStateTracker.py b/presenter/chatbot_modules/DialogueStateTracker.py index 46315f0..adf932b 100644 --- a/presenter/chatbot_modules/DialogueStateTracker.py +++ b/presenter/chatbot_modules/DialogueStateTracker.py @@ -14,18 +14,4 @@ class DialogueStateTracker: """ self.dialogueState.currentActs = userActsFrame - if userActsFrame.act == 'hello()': - pass - elif userActsFrame.act == 'request': - pass - elif userActsFrame.act == 'inform': - pass - else: - pass - return self.dialogueState - - def setDialogueState(self, dialogueState): - self.dialogueState = dialogueState - - def getDialogueState(self, dialogueState): return self.dialogueState diff --git a/presenter/chatbot_modules/NaturalLanguageGeneration.py b/presenter/chatbot_modules/NaturalLanguageGeneration.py index 8cdfd03..cba6f51 100644 --- a/presenter/chatbot_modules/NaturalLanguageGeneration.py +++ b/presenter/chatbot_modules/NaturalLanguageGeneration.py @@ -1,3 +1,9 @@ class NaturalLanguageGeneration: - def get_frame(self, input_from_user): - pass + + def generate_text(self, system_frames): + for system_frame in system_frames: + if system_frame.act == 'inform()': + if 'imię' in system_frame.parameters: + return 'Nazywam się Dia.' + else: + return 'Nie rozumiem co masz na myśli.' diff --git a/view/View.py b/view/View.py index f3e9d10..f94b4cb 100644 --- a/view/View.py +++ b/view/View.py @@ -5,9 +5,8 @@ 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) + print(result) if __name__ == "__main__": - init_chat() \ No newline at end of file + init_chat()