ADD: Basic modules - NLU, DP, DST, NLG
This commit is contained in:
parent
7c2c87e308
commit
711904c435
75
Modules.py
Normal file
75
Modules.py
Normal file
@ -0,0 +1,75 @@
|
||||
#Natural Language Understanding
|
||||
class NLU:
|
||||
#Text analysys
|
||||
def __init__(self, acts, arguments):
|
||||
self.acts = acts
|
||||
self.arguments = arguments
|
||||
|
||||
def analyze(self, text):
|
||||
#Turn text into frame
|
||||
#return vector for further use
|
||||
|
||||
act = "(greetings()&request(name))"
|
||||
vector = [[0],[1,0]]
|
||||
return vector
|
||||
|
||||
#Dialogue policy
|
||||
class DP:
|
||||
#Module decide what act takes next
|
||||
def __init__(self, acts, arguments):
|
||||
self.acts = acts
|
||||
self.arguments = arguments
|
||||
|
||||
def tacticChoice(self, frame_list):
|
||||
act_vector = [0, 0]
|
||||
return act_vector
|
||||
|
||||
#Dialogue State Tracker
|
||||
class DST:
|
||||
#Contain informations about state of the dialogue and data taken from user
|
||||
def __init__(self, acts, arguments):
|
||||
self.acts = acts
|
||||
self.arguments = arguments
|
||||
self.frame_list= []
|
||||
|
||||
#store new act into frame
|
||||
def store(self, frame):
|
||||
self.frame_list.append(frame)
|
||||
|
||||
def transfer(self):
|
||||
return self.frame_list
|
||||
#Natural Language Generator
|
||||
class NLG:
|
||||
def __init__(self, acts, arguments):
|
||||
self.acts = acts
|
||||
self.arguments = arguments
|
||||
|
||||
def vectorToText(self, act_vector):
|
||||
if(act_vector == [0, 0]):
|
||||
return "Cześć, mam na imię Mateusz"
|
||||
return "Nie rozumiem Cię"
|
||||
|
||||
class Run:
|
||||
def __init__(self):
|
||||
self.acts={
|
||||
0: "greetings",
|
||||
1: "request",
|
||||
}
|
||||
self.arguments={
|
||||
0: "name"
|
||||
}
|
||||
self.nlu = NLU(self.acts, self.arguments)
|
||||
self.dp = DP(self.acts, self.arguments)
|
||||
self.nlg = NLG(self.acts, self.arguments)
|
||||
self.dst = DST(self.acts, self.arguments)
|
||||
|
||||
def process(self, command):
|
||||
act = self.nlu.analyze(command)
|
||||
self.dst.store(act)
|
||||
dest_act = self.dp.tacticChoice(self.dst.transfer())
|
||||
return self.nlg.vectorToText(dest_act)
|
||||
|
||||
run = Run()
|
||||
while(1):
|
||||
message = input("Napisz coś: ")
|
||||
print(run.process(message))
|
Loading…
Reference in New Issue
Block a user