NaturalLanguageGeneration update
This commit is contained in:
parent
f343ebec98
commit
d0f9db73bd
@ -33,14 +33,14 @@ class DP:
|
|||||||
system_act = SystemAct(SystemActType.REQUEST, ['place'])
|
system_act = SystemAct(SystemActType.REQUEST, ['place'])
|
||||||
self.DST.system_update(system_act)
|
self.DST.system_update(system_act)
|
||||||
return system_act
|
return system_act
|
||||||
elif 'description' not in slots:
|
|
||||||
system_act = SystemAct(SystemActType.REQUEST, ['description'])
|
|
||||||
self.DST.system_update(system_act)
|
|
||||||
return system_act
|
|
||||||
elif 'participants' not in slots:
|
elif 'participants' not in slots:
|
||||||
system_act = SystemAct(SystemActType.REQUEST, ['participants'])
|
system_act = SystemAct(SystemActType.REQUEST, ['participants'])
|
||||||
self.DST.system_update(system_act)
|
self.DST.system_update(system_act)
|
||||||
return system_act
|
return system_act
|
||||||
|
elif 'description' not in slots:
|
||||||
|
system_act = SystemAct(SystemActType.REQUEST, ['description'])
|
||||||
|
self.DST.system_update(system_act)
|
||||||
|
return system_act
|
||||||
else:
|
else:
|
||||||
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, slots)
|
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, slots)
|
||||||
self.DST.system_update(system_act)
|
self.DST.system_update(system_act)
|
||||||
@ -62,14 +62,14 @@ class DP:
|
|||||||
system_act = SystemAct(SystemActType.REQUEST, ['place'])
|
system_act = SystemAct(SystemActType.REQUEST, ['place'])
|
||||||
self.DST.system_update(system_act)
|
self.DST.system_update(system_act)
|
||||||
return system_act
|
return system_act
|
||||||
elif 'description' not in slots:
|
|
||||||
system_act = SystemAct(SystemActType.REQUEST, ['description'])
|
|
||||||
self.DST.system_update(system_act)
|
|
||||||
return system_act
|
|
||||||
elif 'participants' not in slots:
|
elif 'participants' not in slots:
|
||||||
system_act = SystemAct(SystemActType.REQUEST, ['participants'])
|
system_act = SystemAct(SystemActType.REQUEST, ['participants'])
|
||||||
self.DST.system_update(system_act)
|
self.DST.system_update(system_act)
|
||||||
return system_act
|
return system_act
|
||||||
|
elif 'description' not in slots:
|
||||||
|
system_act = SystemAct(SystemActType.REQUEST, ['description'])
|
||||||
|
self.DST.system_update(system_act)
|
||||||
|
return system_act
|
||||||
else:
|
else:
|
||||||
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, slots)
|
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, slots)
|
||||||
self.DST.system_update(system_act)
|
self.DST.system_update(system_act)
|
||||||
@ -82,7 +82,7 @@ class DP:
|
|||||||
return system_act
|
return system_act
|
||||||
elif last_user_act == UserActType.NEGATE:
|
elif last_user_act == UserActType.NEGATE:
|
||||||
self.DST.clear()
|
self.DST.clear()
|
||||||
return SystemAct(SystemActType.REQMORE, [])
|
return SystemAct(SystemActType.REQMORE, ['create_meeting'])
|
||||||
else:
|
else:
|
||||||
return SystemAct(SystemActType.NOT_UNDERSTOOD, [])
|
return SystemAct(SystemActType.NOT_UNDERSTOOD, [])
|
||||||
# stan edycji spotkania
|
# stan edycji spotkania
|
||||||
@ -174,7 +174,7 @@ class DP:
|
|||||||
return SystemAct(SystemActType.AFFIRM, ['update_meeting'])
|
return SystemAct(SystemActType.AFFIRM, ['update_meeting'])
|
||||||
elif last_user_act == UserActType.NEGATE:
|
elif last_user_act == UserActType.NEGATE:
|
||||||
self.DST.clear()
|
self.DST.clear()
|
||||||
return SystemAct(SystemActType.REQMORE, [])
|
return SystemAct(SystemActType.REQMORE, ['meeting_to_update'])
|
||||||
self.meeting_to_update = False
|
self.meeting_to_update = False
|
||||||
if not self.meeting_to_update:
|
if not self.meeting_to_update:
|
||||||
if last_user_act == UserActType.CONFIRM:
|
if last_user_act == UserActType.CONFIRM:
|
||||||
@ -185,7 +185,7 @@ class DP:
|
|||||||
return system_act
|
return system_act
|
||||||
elif last_user_act == UserActType.NEGATE:
|
elif last_user_act == UserActType.NEGATE:
|
||||||
self.DST.clear()
|
self.DST.clear()
|
||||||
return SystemAct(SystemActType.REQMORE, [])
|
return SystemAct(SystemActType.REQMORE, ['meeting_to_update'])
|
||||||
else:
|
else:
|
||||||
return SystemAct(SystemActType.NOT_UNDERSTOOD, [])
|
return SystemAct(SystemActType.NOT_UNDERSTOOD, [])
|
||||||
# stan anulowania spotkania
|
# stan anulowania spotkania
|
||||||
@ -226,14 +226,14 @@ class DP:
|
|||||||
return system_act
|
return system_act
|
||||||
elif last_user_act == UserActType.NEGATE:
|
elif last_user_act == UserActType.NEGATE:
|
||||||
self.DST.clear()
|
self.DST.clear()
|
||||||
return SystemAct(SystemActType.REQMORE, [])
|
return SystemAct(SystemActType.REQMORE, ['cancel_meeting'])
|
||||||
else:
|
else:
|
||||||
return SystemAct(SystemActType.NOT_UNDERSTOOD, [])
|
return SystemAct(SystemActType.NOT_UNDERSTOOD, [])
|
||||||
# stan prośby o listę spotkań
|
# stan prośby o listę spotkań
|
||||||
elif dialogue_state == UserActType.MEETING_LIST:
|
elif dialogue_state == UserActType.MEETING_LIST:
|
||||||
if last_user_act == UserActType.NEGATE:
|
if last_user_act == UserActType.NEGATE:
|
||||||
self.DST.clear()
|
self.DST.clear()
|
||||||
return SystemAct(SystemActType.REQMORE, [])
|
return SystemAct(SystemActType.REQMORE, ['meeting_list'])
|
||||||
else:
|
else:
|
||||||
if 'date' in slots:
|
if 'date' in slots:
|
||||||
system_act = SystemAct(SystemActType.MEETING_LIST, slots)
|
system_act = SystemAct(SystemActType.MEETING_LIST, slots)
|
||||||
@ -247,7 +247,7 @@ class DP:
|
|||||||
elif dialogue_state == UserActType.FREE_TIME:
|
elif dialogue_state == UserActType.FREE_TIME:
|
||||||
if last_user_act == UserActType.NEGATE:
|
if last_user_act == UserActType.NEGATE:
|
||||||
self.DST.clear()
|
self.DST.clear()
|
||||||
return SystemAct(SystemActType.REQMORE, [])
|
return SystemAct(SystemActType.REQMORE, ['free_time'])
|
||||||
else:
|
else:
|
||||||
if 'date' in slots:
|
if 'date' in slots:
|
||||||
system_act = SystemAct(SystemActType.FREE_TIME, slots)
|
system_act = SystemAct(SystemActType.FREE_TIME, slots)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from SystemAct import SystemAct
|
from SystemAct import SystemAct
|
||||||
from SystemActType import SystemActType
|
from SystemActType import SystemActType
|
||||||
|
from UserActType import UserActType
|
||||||
|
|
||||||
class NLG:
|
class NLG:
|
||||||
"""
|
"""
|
||||||
@ -8,17 +9,146 @@ class NLG:
|
|||||||
Wyjście: Tekst
|
Wyjście: Tekst
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, dst):
|
||||||
pass
|
self.DST = dst
|
||||||
|
|
||||||
def toText(self, systemAct: SystemAct) -> str:
|
def generateResponse(self, systemAct: SystemAct) -> str:
|
||||||
if systemAct.getActType() == SystemActType.WELCOME_MSG:
|
dialogue_state, last_user_act, _ = self.DST.get_dialogue_state()
|
||||||
return "Cześć"
|
slots = self.DST.get_dialogue_slots()
|
||||||
if systemAct.getActType() == SystemActType.INFORM:
|
if dialogue_state == UserActType.CREATE_MEETING:
|
||||||
if "name" in systemAct.getActParams():
|
if systemAct.getActType() == SystemActType.REQUEST:
|
||||||
return "Nazywam się Janusz"
|
if "date" in systemAct.getActParams():
|
||||||
if systemAct.getActType() == SystemActType.BYE:
|
return "W jakim dniu ma się odbyć to spotkanie?"
|
||||||
return "Do widzenia."
|
if "time" in systemAct.getActParams():
|
||||||
if systemAct.getActType() == SystemActType.NOT_UNDERSTOOD:
|
return "W jakim czasie ma się odbyć to spotkanie?"
|
||||||
return "Nie rozumiem o czym mówisz."
|
if "place" in systemAct.getActParams():
|
||||||
|
return "Gdzie ma się odbyć to spotkanie?"
|
||||||
|
if "description" in systemAct.getActParams():
|
||||||
|
return "Czy mam dodać jakiś opis do tego spotkania?"
|
||||||
|
if "participants" in systemAct.getActParams():
|
||||||
|
return "Kto ma wziąć udział w spotkaniu?"
|
||||||
|
if systemAct.getActType() == SystemActType.CONFIRM_DOMAIN:
|
||||||
|
date = slots['date']
|
||||||
|
time = slots['time']
|
||||||
|
place = slots['place']
|
||||||
|
part_list = slots['participants']
|
||||||
|
part = ""
|
||||||
|
for p in part_list:
|
||||||
|
part += p
|
||||||
|
part += ", "
|
||||||
|
part = part[:-2]
|
||||||
|
desc = slots['description']
|
||||||
|
return f'Czy mam dodać te spotkanie do kalendarza?\n' \
|
||||||
|
f'Dzień: {date}\nCzas: {time}\nMiejsce: {place}\nUczestnicy: {part}\nOpis: {desc}'
|
||||||
|
|
||||||
|
# TODO: nie sprawdzone - trudno wejść do tego stanu
|
||||||
|
elif dialogue_state == UserActType.UPDATE_MEETING:
|
||||||
|
if systemAct.getActType() == SystemActType.REQUEST:
|
||||||
|
if "date" in systemAct.getActParams():
|
||||||
|
return "W jakim dniu miało się odbyć to spotkanie?"
|
||||||
|
if "time" in systemAct.getActParams():
|
||||||
|
return "W jakim czasie miało się odbyć to spotkanie?"
|
||||||
|
# TODO dopracować po dodaniu DB
|
||||||
|
if systemAct.getActType() == SystemActType.CONFIRM_DOMAIN:
|
||||||
|
date = slots['date']
|
||||||
|
time = slots['time']
|
||||||
|
place = slots['place']
|
||||||
|
part_list = slots['participants']
|
||||||
|
part = ""
|
||||||
|
for p in part_list:
|
||||||
|
part += p
|
||||||
|
part += ", "
|
||||||
|
part = part[:-2]
|
||||||
|
desc = slots['description']
|
||||||
|
return f'Spotkanie:\n' \
|
||||||
|
f'Dzień: {date}\nCzas: {time}\nMiejsce: {place}\nUczestnicy: {part}\nOpis: {desc}'
|
||||||
|
|
||||||
|
elif dialogue_state == UserActType.CANCEL_MEETING:
|
||||||
|
if systemAct.getActType() == SystemActType.REQUEST:
|
||||||
|
if "date" in systemAct.getActParams():
|
||||||
|
return "W jakim dniu miało się odbyć to spotkanie?"
|
||||||
|
if "time" in systemAct.getActParams():
|
||||||
|
return "W jakim czasie miało się odbyć to spotkanie?"
|
||||||
|
# TODO dopracować po dodaniu DB
|
||||||
|
if systemAct.getActType() == SystemActType.CONFIRM_DOMAIN:
|
||||||
|
date = slots['date']
|
||||||
|
time = slots['time']
|
||||||
|
# place = slots['place']
|
||||||
|
# part_list = slots['participants']
|
||||||
|
# part = ""
|
||||||
|
# for p in part_list:
|
||||||
|
# part += p
|
||||||
|
# part += ", "
|
||||||
|
# part = part[:-2]
|
||||||
|
# desc = slots['description']
|
||||||
|
return f'Spotkanie:\n' \
|
||||||
|
f'Dzień: {date}\nCzas: {time}'
|
||||||
|
|
||||||
|
elif dialogue_state == UserActType.MEETING_LIST:
|
||||||
|
if systemAct.getActType() == SystemActType.REQUEST:
|
||||||
|
if "date" in systemAct.getActParams():
|
||||||
|
return "Z jakiego okresu chcesz przejrzeć spotkania?"
|
||||||
|
# TODO: dopracować po dodaniu DB
|
||||||
|
if systemAct.getActType() == SystemActType.MEETING_LIST:
|
||||||
|
response = ""
|
||||||
|
for s in slots:
|
||||||
|
date = s['date']
|
||||||
|
time = s['time']
|
||||||
|
place = s['place']
|
||||||
|
part_list = s['participants']
|
||||||
|
part = ""
|
||||||
|
for p in part_list:
|
||||||
|
part += p
|
||||||
|
part += ", "
|
||||||
|
part = part[:-2]
|
||||||
|
desc = s['description']
|
||||||
|
response += f'Spotkanie:\nDzień: {date}\nCzas: {time}\nMiejsce: {place}\nUczestnicy: {part}\nOpis: {desc}\n'
|
||||||
|
response += "--------------------"
|
||||||
|
return response
|
||||||
|
|
||||||
|
elif dialogue_state == UserActType.FREE_TIME:
|
||||||
|
if systemAct.getActType() == SystemActType.REQUEST:
|
||||||
|
if "date" in systemAct.getActParams():
|
||||||
|
return "W jakim okresie chcesz znaleźć wolny czas?"
|
||||||
|
# TODO: dopracować po dodaniu DB
|
||||||
|
if systemAct.getActType() == SystemActType.FREE_TIME:
|
||||||
|
response = ""
|
||||||
|
for s in slots:
|
||||||
|
date = s['date']
|
||||||
|
time = s['time']
|
||||||
|
response += f'Spotkanie:\nDzień: {date}\nCzas: {time}\n'
|
||||||
|
return response
|
||||||
|
|
||||||
|
elif systemAct.getActType() == SystemActType.AFFIRM:
|
||||||
|
if "create_meeting" in systemAct.getActParams():
|
||||||
|
return "Spotkanie zostało dodane"
|
||||||
|
if "update_meeting" in systemAct.getActParams():
|
||||||
|
return "Spotkanie zostało zaktualizowane"
|
||||||
|
if "cancel_meeting" in systemAct.getActParams():
|
||||||
|
return "Spotkanie zostało odwołane"
|
||||||
|
|
||||||
|
elif systemAct.getActType() == SystemActType.REQMORE:
|
||||||
|
if "create_meeting" in systemAct.getActParams():
|
||||||
|
return "Spotkanie zostało odrzucone. Mogę pomóc w czymś jeszcze?"
|
||||||
|
if "update_meeting" in systemAct.getActParams():
|
||||||
|
return "Aktualizacja spotkania została anulowana. Mogę pomóc w czymś jeszcze?"
|
||||||
|
if "cancel_meeting" in systemAct.getActParams():
|
||||||
|
return "Odwoływanie spotkania zostało anulowane. Mogę pomóc w czymś jeszcze?"
|
||||||
|
if "meeting_list" in systemAct.getActParams() or "free_time" in systemAct.getActParams():
|
||||||
|
return "Mogę pomóc w czymś jeszcze?"
|
||||||
|
|
||||||
|
else:
|
||||||
|
if systemAct.getActType() == SystemActType.WELCOME_MSG:
|
||||||
|
return "Cześć"
|
||||||
|
if systemAct.getActType() == SystemActType.REQMORE:
|
||||||
|
return "Czy mogę Ci w czymś jeszcze pomóc?"
|
||||||
|
if systemAct.getActType() == SystemActType.BYE:
|
||||||
|
return "Do widzenia."
|
||||||
|
if systemAct.getActType() == SystemActType.NOT_UNDERSTOOD:
|
||||||
|
return "Nie rozumiem o czym mówisz."
|
||||||
|
|
||||||
|
# TODO: Not implemented in DP
|
||||||
|
# if systemAct.getActType() == SystemActType.INFORM:
|
||||||
|
# if "name" in systemAct.getActParams():
|
||||||
|
# return "Nazywam się Janusz"
|
||||||
raise Exception("SystemAct:{} not recognized".format(systemAct))
|
raise Exception("SystemAct:{} not recognized".format(systemAct))
|
||||||
|
7
main.py
7
main.py
@ -9,7 +9,7 @@ if __name__ == "__main__":
|
|||||||
nlu = NLU()
|
nlu = NLU()
|
||||||
dst = DST()
|
dst = DST()
|
||||||
dp = DP(dst)
|
dp = DP(dst)
|
||||||
nlg = NLG()
|
nlg = NLG(dst)
|
||||||
|
|
||||||
while(1):
|
while(1):
|
||||||
user_input = input("Wpisz tekst: ")
|
user_input = input("Wpisz tekst: ")
|
||||||
@ -21,15 +21,18 @@ if __name__ == "__main__":
|
|||||||
state, last_user_act, last_system_act = dst.get_dialogue_state()
|
state, last_user_act, last_system_act = dst.get_dialogue_state()
|
||||||
slots = dst.get_dialogue_slots()
|
slots = dst.get_dialogue_slots()
|
||||||
system_act = dp.chooseTactic()
|
system_act = dp.chooseTactic()
|
||||||
|
|
||||||
print('------ stan ------')
|
print('------ stan ------')
|
||||||
print(state, last_user_act, last_system_act)
|
print(state, last_user_act, last_system_act)
|
||||||
print('------ przechowywane sloty ------')
|
print('------ przechowywane sloty ------')
|
||||||
print(slots)
|
print(slots)
|
||||||
print('------ wybrana akcja systemu ------')
|
print('------ wybrana akcja systemu ------')
|
||||||
print(system_act)
|
print(system_act)
|
||||||
|
system_response = nlg.generateResponse(system_act)
|
||||||
|
print('------ wygenerowana odpowiedź systemu ------')
|
||||||
|
print(system_response)
|
||||||
print('-----------------------------------')
|
print('-----------------------------------')
|
||||||
print('-----------------------------------')
|
print('-----------------------------------')
|
||||||
#text = nlg.toText(system_act)
|
|
||||||
|
|
||||||
if system_act.getActType() == SystemActType.BYE:
|
if system_act.getActType() == SystemActType.BYE:
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user