add nlu module and code reformat
This commit is contained in:
parent
7c85ecd41f
commit
4c1d303555
@ -1,3 +0,0 @@
|
|||||||
class NaturalLanguageUnderstanding:
|
|
||||||
pass
|
|
||||||
|
|
15
model/UserActFrame.py
Normal file
15
model/UserActFrame.py
Normal file
@ -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
|
9
presenter/Presenter.py
Normal file
9
presenter/Presenter.py
Normal file
@ -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 ''
|
@ -1,4 +1,3 @@
|
|||||||
class NaturalLanguageGeneration:
|
class NaturalLanguageGeneration:
|
||||||
def get_frame(self, input_from_user):
|
def get_frame(self, input_from_user):
|
||||||
pass
|
pass
|
||||||
|
|
15
presenter/chatbot_modules/NaturalLanguageUnderstanding.py
Normal file
15
presenter/chatbot_modules/NaturalLanguageUnderstanding.py
Normal file
@ -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)]
|
13
view/View.py
Normal file
13
view/View.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user