2021-04-26 15:13:52 +02:00
|
|
|
from SystemAct import SystemAct
|
2021-04-26 00:29:07 +02:00
|
|
|
from UserActType import UserActType
|
2021-04-26 15:13:52 +02:00
|
|
|
from SystemActType import SystemActType
|
2021-05-30 19:01:45 +02:00
|
|
|
from collections import defaultdict
|
2021-04-26 00:29:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
class DP:
|
|
|
|
"""
|
2021-04-26 09:57:03 +02:00
|
|
|
Moduł decydujący o wyborze kolejnego aktu, który ma podjąć system prowadząc rozmowę.
|
|
|
|
Wejście: Reprezentacja stanu dialogu (rama)
|
|
|
|
Wyjście: Akt systemu (rama)
|
2021-04-26 00:29:07 +02:00
|
|
|
"""
|
|
|
|
|
2021-05-31 13:52:01 +02:00
|
|
|
def __init__(self, dst):
|
|
|
|
self.DST = dst
|
2021-05-31 14:53:20 +02:00
|
|
|
self.meeting_to_update = False
|
2021-04-26 00:29:07 +02:00
|
|
|
|
2021-05-31 13:52:01 +02:00
|
|
|
def chooseTactic(self) -> SystemAct:
|
|
|
|
dialogue_state, last_user_act, last_system_act = self.DST.get_dialogue_state()
|
|
|
|
slots = self.DST.get_dialogue_slots()
|
|
|
|
# stan dodawania spotkania
|
|
|
|
if dialogue_state == UserActType.CREATE_MEETING:
|
|
|
|
if not last_system_act:
|
|
|
|
if 'date' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif 'time' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['time'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif 'place' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['place'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif 'participants' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['participants'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-06-03 17:48:12 +02:00
|
|
|
elif 'description' not in slots:
|
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['description'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
else:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, slots)
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif last_system_act.getActType() == SystemActType.REQUEST:
|
|
|
|
if last_user_act == UserActType.NEGATE:
|
|
|
|
slot_type = last_system_act.getActParams()[0]
|
|
|
|
if slot_type not in ['date', 'time']:
|
|
|
|
self.DST.insert_empty_slot(slot_type)
|
|
|
|
if 'date' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif 'time' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['time'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif 'place' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['place'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif 'participants' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['participants'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-06-03 17:48:12 +02:00
|
|
|
elif 'description' not in slots:
|
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['description'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
else:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, slots)
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif last_system_act.getActType() == SystemActType.CONFIRM_DOMAIN:
|
|
|
|
if last_user_act == UserActType.CONFIRM:
|
|
|
|
system_act = SystemAct(SystemActType.AFFIRM, ['create_meeting'])
|
|
|
|
# implementacja wpisywanie spotkania do bazy
|
|
|
|
self.DST.clear()
|
|
|
|
return system_act
|
|
|
|
elif last_user_act == UserActType.NEGATE:
|
|
|
|
self.DST.clear()
|
2021-06-03 17:48:12 +02:00
|
|
|
return SystemAct(SystemActType.REQMORE, ['create_meeting'])
|
2021-05-31 13:52:01 +02:00
|
|
|
else:
|
|
|
|
return SystemAct(SystemActType.NOT_UNDERSTOOD, [])
|
|
|
|
# stan edycji spotkania
|
|
|
|
elif dialogue_state == UserActType.UPDATE_MEETING:
|
|
|
|
if not last_system_act:
|
|
|
|
if 'date' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif 'time' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['time'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
else:
|
|
|
|
# implementacja wyszukiwania odpowiedniego spotkania w bazie
|
|
|
|
return SystemAct(SystemActType.CONFIRM_DOMAIN, ['meeting_to_update'])
|
|
|
|
elif last_system_act.getActType() == SystemActType.REQUEST:
|
2021-05-31 14:53:20 +02:00
|
|
|
if not self.meeting_to_update:
|
2021-05-31 13:52:01 +02:00
|
|
|
if 'date' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif 'time' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['time'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
else:
|
|
|
|
# implementacja wyszukiwania odpowiedniego spotkania w bazie
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, ['meeting_to_update'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
else:
|
|
|
|
if last_user_act == UserActType.NEGATE:
|
|
|
|
slot_type = last_system_act.getActParams()[0]
|
2021-05-31 14:53:20 +02:00
|
|
|
self.DST.insert_empty_slot(slot_type)
|
2021-05-31 13:52:01 +02:00
|
|
|
if 'date' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif 'time' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['time'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif 'place' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['place'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif 'description' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['description'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif 'participants' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['participants'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
else:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, slots)
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
|
|
|
else:
|
|
|
|
if 'date' not in slots:
|
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
|
|
|
elif 'time' not in slots:
|
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['time'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
|
|
|
elif 'place' not in slots:
|
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['place'])
|
|
|
|
self.DST.system_update(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:
|
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['participants'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
|
|
|
else:
|
|
|
|
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, slots)
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif last_system_act.getActType() == SystemActType.CONFIRM_DOMAIN:
|
2021-05-31 14:53:20 +02:00
|
|
|
if self.meeting_to_update:
|
2021-05-31 13:52:01 +02:00
|
|
|
if last_user_act == UserActType.CONFIRM:
|
|
|
|
self.DST.clear()
|
|
|
|
return SystemAct(SystemActType.AFFIRM, ['update_meeting'])
|
|
|
|
elif last_user_act == UserActType.NEGATE:
|
|
|
|
self.DST.clear()
|
2021-06-03 17:48:12 +02:00
|
|
|
return SystemAct(SystemActType.REQMORE, ['meeting_to_update'])
|
2021-05-31 14:53:20 +02:00
|
|
|
self.meeting_to_update = False
|
|
|
|
if not self.meeting_to_update:
|
2021-05-31 13:52:01 +02:00
|
|
|
if last_user_act == UserActType.CONFIRM:
|
2021-05-31 14:53:20 +02:00
|
|
|
self.meeting_to_update = True
|
2021-05-31 13:52:01 +02:00
|
|
|
self.DST.clear_slots()
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif last_user_act == UserActType.NEGATE:
|
|
|
|
self.DST.clear()
|
2021-06-03 17:48:12 +02:00
|
|
|
return SystemAct(SystemActType.REQMORE, ['meeting_to_update'])
|
2021-05-31 13:52:01 +02:00
|
|
|
else:
|
|
|
|
return SystemAct(SystemActType.NOT_UNDERSTOOD, [])
|
|
|
|
# stan anulowania spotkania
|
|
|
|
elif dialogue_state == UserActType.CANCEL_MEETING:
|
|
|
|
if not last_system_act:
|
|
|
|
if 'date' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif 'time' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['time'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
else:
|
|
|
|
# implementacja wyszukiwania odpowiedniego spotkania w bazie
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, ['meeting_to_cancel'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif last_system_act.getActType() == SystemActType.REQUEST:
|
|
|
|
if 'date' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif 'time' not in slots:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['time'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
else:
|
|
|
|
# implementacja wyszukiwania odpowiedniego spotkania w bazie
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, ['meeting_to_cancel'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
elif last_system_act.getActType() == SystemActType.CONFIRM_DOMAIN:
|
|
|
|
if last_user_act == UserActType.CONFIRM:
|
|
|
|
system_act = SystemAct(SystemActType.AFFIRM, ['cancel_meeting'])
|
|
|
|
# implementacja usuwania spotkania z bazy
|
|
|
|
self.DST.clear()
|
|
|
|
return system_act
|
|
|
|
elif last_user_act == UserActType.NEGATE:
|
|
|
|
self.DST.clear()
|
2021-06-03 17:48:12 +02:00
|
|
|
return SystemAct(SystemActType.REQMORE, ['cancel_meeting'])
|
2021-05-31 13:52:01 +02:00
|
|
|
else:
|
|
|
|
return SystemAct(SystemActType.NOT_UNDERSTOOD, [])
|
|
|
|
# stan prośby o listę spotkań
|
|
|
|
elif dialogue_state == UserActType.MEETING_LIST:
|
|
|
|
if last_user_act == UserActType.NEGATE:
|
|
|
|
self.DST.clear()
|
2021-06-03 17:48:12 +02:00
|
|
|
return SystemAct(SystemActType.REQMORE, ['meeting_list'])
|
2021-05-31 13:52:01 +02:00
|
|
|
else:
|
|
|
|
if 'date' in slots:
|
|
|
|
system_act = SystemAct(SystemActType.MEETING_LIST, slots)
|
|
|
|
self.DST.clear()
|
|
|
|
return system_act
|
|
|
|
else:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
# stan prośby o czas wolny
|
|
|
|
elif dialogue_state == UserActType.FREE_TIME:
|
|
|
|
if last_user_act == UserActType.NEGATE:
|
|
|
|
self.DST.clear()
|
2021-06-03 17:48:12 +02:00
|
|
|
return SystemAct(SystemActType.REQMORE, ['free_time'])
|
2021-05-31 13:52:01 +02:00
|
|
|
else:
|
|
|
|
if 'date' in slots:
|
|
|
|
system_act = SystemAct(SystemActType.FREE_TIME, slots)
|
|
|
|
self.DST.clear()
|
|
|
|
return system_act
|
|
|
|
else:
|
2021-05-31 14:53:20 +02:00
|
|
|
system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
|
|
|
self.DST.system_update(system_act)
|
|
|
|
return system_act
|
2021-05-31 13:52:01 +02:00
|
|
|
# brak określonego stanu
|
2021-05-16 23:11:55 +02:00
|
|
|
else:
|
2021-05-31 13:52:01 +02:00
|
|
|
if last_user_act == UserActType.HELLO:
|
|
|
|
return SystemAct(SystemActType.WELCOME_MSG, [])
|
|
|
|
elif last_user_act == UserActType.BYE:
|
|
|
|
return SystemAct(SystemActType.BYE, [])
|
|
|
|
elif last_user_act == UserActType.THANKYOU:
|
|
|
|
return SystemAct(SystemActType.REQMORE, [])
|
|
|
|
else:
|
|
|
|
return SystemAct(SystemActType.NOT_UNDERSTOOD, [])
|