WB_Branch #2

Merged
s470609 merged 2 commits from WB_Branch into master 2021-04-26 15:03:18 +02:00
7 changed files with 55 additions and 47 deletions

View File

@ -1,7 +1,6 @@
class DialogueState: class DialogueState:
def init(self): def __init__(self):
self.currentActs = [] self.currentActs = []
self.previousActs = [] self.previousActs = []
self.botName = 'Dia'
self.date = None self.date = None

15
model/SystemActFrame.py Normal file
View File

@ -0,0 +1,15 @@
class SystemActFrame:
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

View File

@ -1,9 +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.NaturalLanguageUnderstanding import NaturalLanguageUnderstanding
from presenter.chatbot_modules.DialoguePolicy import DialoguePolicy
class Presenter: class Presenter:
dialogue_state_tracker = DialogueStateTracker()
nlu = NaturalLanguageUnderstanding()
policy = DialoguePolicy()
nlg = NaturalLanguageGeneration()
def process_user_input(self, user_input): def process_user_input(self, user_input):
nlu = NaturalLanguageUnderstanding() user_frames = self.nlu.text_to_user_frame(user_input)
user_frames = 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

View File

@ -1,10 +1,13 @@
from model import DialogueState from model.SystemActFrame import SystemActFrame
class DialoguePolicy: class DialoguePolicy:
pass
def init(self): def resolve_system_acts(self, dialogueState):
pass 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): return system_acts
pass

View File

@ -1,40 +1,17 @@
from model import DialogueState from model.DialogueState import DialogueState
class DialogueStateTracker: class DialogueStateTracker:
def init(self, dialogueState): def __init__(self):
pass self.dialogueState = DialogueState()
def processinformFrame(self, userActsFrame, dialogueState): def processUserAct(self, userActsFrame):
"""
:param userActsFrame:
:param dialogueState:
:return:
"""
def processUserAct(self, userActsFrame, dialogueState):
""" """
:param userActsFrame: input of user acts incoming :param userActsFrame: input of user acts incoming
:return: dialogueState :return: dialogueState
""" """
dialogueState.currentActs=userActsFrame self.dialogueState.currentActs = userActsFrame
if userActsFrame.act == 'hello()': return self.dialogueState
pass
elif userActsFrame.act == 'request':
pass
elif userActsFrame.act == 'inform':
dialogueState=self.processinformFrame(userActsFrame, dialogueState)
else:
pass
return dialogueState
# def setDialogueState(self, dialogueState):
# self.DialogueState=dialogueState
#
# def getDialogueState(self, dialogueState):
# return self.DialogueState

View File

@ -1,3 +1,9 @@
class NaturalLanguageGeneration: 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.'

View File

@ -5,8 +5,7 @@ def init_chat():
print('Witamy w systemie elektronicznej rezerwacji Biletów! W czym mogę pomóc?') print('Witamy w systemie elektronicznej rezerwacji Biletów! W czym mogę pomóc?')
user_input = input() user_input = input()
result = Presenter().process_user_input(user_input) result = Presenter().process_user_input(user_input)
for r in result: print(result)
print(r)
if __name__ == "__main__": if __name__ == "__main__":