DP and DST improvement
This commit is contained in:
parent
6a7196203e
commit
44588ed65b
@ -9,9 +9,6 @@ class ActFrame(ABC):
|
|||||||
self.__actType = actType
|
self.__actType = actType
|
||||||
|
|
||||||
if actParams != None:
|
if actParams != None:
|
||||||
if type(actParams) is not list:
|
|
||||||
raise Exception(
|
|
||||||
'actParams has wrong type: expected type \'list\', got \'{}\''.format(type(actParams)))
|
|
||||||
self.__actParams = actParams
|
self.__actParams = actParams
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -22,9 +19,6 @@ class ActFrame(ABC):
|
|||||||
|
|
||||||
|
|
||||||
def setActParams(self, actParams):
|
def setActParams(self, actParams):
|
||||||
if type(actParams) is not list:
|
|
||||||
raise Exception(
|
|
||||||
'actParams has wrong type: expected type \'list\', got \'{}\''.format(type(actParams)))
|
|
||||||
self.__actParams = actParams
|
self.__actParams = actParams
|
||||||
|
|
||||||
def getActParams(self):
|
def getActParams(self):
|
||||||
|
@ -11,43 +11,172 @@ class DP:
|
|||||||
Wyjście: Akt systemu (rama)
|
Wyjście: Akt systemu (rama)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, dst):
|
||||||
self.results = []
|
self.DST = dst
|
||||||
|
|
||||||
def chooseTactic(self, current_frame) -> SystemAct:
|
def chooseTactic(self) -> SystemAct:
|
||||||
#userAct = frameList[-1]
|
dialogue_state, last_user_act, last_system_act = self.DST.get_dialogue_state()
|
||||||
if current_frame.getActType() == UserActType.HELLO:
|
slots = self.DST.get_dialogue_slots()
|
||||||
return SystemAct(SystemActType.WELCOME_MSG)
|
# stan dodawania spotkania
|
||||||
elif current_frame.getActType() == UserActType.BYE:
|
if dialogue_state == UserActType.CREATE_MEETING:
|
||||||
return SystemAct(SystemActType.BYE)
|
if not last_system_act:
|
||||||
elif current_frame.getActType() == UserActType.CONFIRM:
|
if 'date' not in slots:
|
||||||
# Czy napewno zawsze po Confirm jest Affirm?
|
return SystemAct(SystemActType.REQUEST, ['date'])
|
||||||
return SystemAct(SystemActType.AFFIRM)
|
elif 'time' not in slots:
|
||||||
elif current_frame.getActType() == UserActType.NEGATE:
|
return SystemAct(SystemActType.REQUEST, ['time'])
|
||||||
# TODO rozpoznanie czy ma się już komplet danych
|
elif 'place' not in slots:
|
||||||
# Affirm (gdy ma się wszystkie potrzebne zdanie)
|
return SystemAct(SystemActType.REQUEST, ['place'])
|
||||||
# Request (gdy potrzeba się dopytać dalej)
|
elif 'description' not in slots:
|
||||||
# Bye (gdy to odp na REQMORE)
|
return SystemAct(SystemActType.REQUEST, ['description'])
|
||||||
return SystemAct(SystemActType.AFFIRM)
|
elif 'participants' not in slots:
|
||||||
elif current_frame.getActType() == UserActType.THANKYOU:
|
return SystemAct(SystemActType.REQUEST, ['participants'])
|
||||||
return SystemAct(SystemActType.REQMORE)
|
else:
|
||||||
elif current_frame.getActType() == UserActType.INFORM:
|
return SystemAct(SystemActType.CONFIRM_DOMAIN, slots)
|
||||||
# TODO najczęściej chyba AFFIRM, CONFIRM_DOMAIN i REQUEST
|
elif last_system_act.getActType() == SystemActType.REQUEST:
|
||||||
return SystemAct(SystemActType.REQUEST)
|
if last_user_act == UserActType.NEGATE:
|
||||||
elif current_frame.getActType() == UserActType.CREATE_MEETING:
|
slot_type = last_system_act.getActParams()[0]
|
||||||
# TODO najczęściej chyba CONFIRM_DOMAIN i REQUEST
|
if slot_type not in ['date', 'time']:
|
||||||
return SystemAct(SystemActType.REQUEST)
|
self.DST.insert_empty_slot(slot_type)
|
||||||
elif current_frame.getActType() == UserActType.UPDATE_MEETING:
|
if 'date' not in slots:
|
||||||
# TODO rozpoznanie czy ma się już komplet danych jak nie to REQUEST jak tak to CONFIRM_DOMAIN
|
return SystemAct(SystemActType.REQUEST, ['date'])
|
||||||
return SystemAct(SystemActType.REQUEST)
|
elif 'time' not in slots:
|
||||||
elif current_frame.getActType() == UserActType.CANCEL_MEETING:
|
return SystemAct(SystemActType.REQUEST, ['time'])
|
||||||
# TODO rozpoznanie czy ma się już komplet danych jak nie to REQUEST jak tak to CONFIRM_DOMAIN
|
elif 'place' not in slots:
|
||||||
return SystemAct(SystemActType.REQUEST)
|
return SystemAct(SystemActType.REQUEST, ['place'])
|
||||||
elif current_frame.getActType() == UserActType.MEETING_LIST:
|
elif 'description' not in slots:
|
||||||
return SystemAct(SystemActType.INFORM, ["meeting_list"])
|
return SystemAct(SystemActType.REQUEST, ['description'])
|
||||||
elif current_frame.getActType() == UserActType.FREE_TIME:
|
elif 'participants' not in slots:
|
||||||
return SystemAct(SystemActType.INFORM, ["freetime"])
|
return SystemAct(SystemActType.REQUEST, ['participants'])
|
||||||
elif current_frame.getActType() == UserActType.INVALID:
|
else:
|
||||||
return SystemAct(SystemActType.NOT_UNDERSTOOD)
|
return SystemAct(SystemActType.CONFIRM_DOMAIN, slots)
|
||||||
|
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()
|
||||||
|
return SystemAct(SystemActType.REQMORE, [])
|
||||||
|
else:
|
||||||
|
return SystemAct(SystemActType.NOT_UNDERSTOOD, [])
|
||||||
|
# stan edycji spotkania
|
||||||
|
elif dialogue_state == UserActType.UPDATE_MEETING:
|
||||||
|
meeting_to_update = False
|
||||||
|
if not last_system_act:
|
||||||
|
if 'date' not in slots:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['date'])
|
||||||
|
elif 'time' not in slots:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['time'])
|
||||||
|
else:
|
||||||
|
# implementacja wyszukiwania odpowiedniego spotkania w bazie
|
||||||
|
return SystemAct(SystemActType.CONFIRM_DOMAIN, ['meeting_to_update'])
|
||||||
|
elif last_system_act.getActType() == SystemActType.REQUEST:
|
||||||
|
if not meeting_to_update:
|
||||||
|
if 'date' not in slots:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['date'])
|
||||||
|
elif 'time' not in slots:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['time'])
|
||||||
|
else:
|
||||||
|
# implementacja wyszukiwania odpowiedniego spotkania w bazie
|
||||||
|
return SystemAct(SystemActType.CONFIRM_DOMAIN, ['meeting_to_update'])
|
||||||
|
else:
|
||||||
|
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:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['date'])
|
||||||
|
elif 'time' not in slots:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['time'])
|
||||||
|
elif 'place' not in slots:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['place'])
|
||||||
|
elif 'description' not in slots:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['description'])
|
||||||
|
elif 'participants' not in slots:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['participants'])
|
||||||
|
else:
|
||||||
|
return SystemAct(SystemActType.CONFIRM_DOMAIN, slots)
|
||||||
|
elif last_system_act.getActType() == SystemActType.CONFIRM_DOMAIN:
|
||||||
|
if meeting_to_update:
|
||||||
|
if last_user_act == UserActType.CONFIRM:
|
||||||
|
meeting_to_update = False
|
||||||
|
self.DST.clear()
|
||||||
|
return SystemAct(SystemActType.AFFIRM, ['update_meeting'])
|
||||||
|
elif last_user_act == UserActType.NEGATE:
|
||||||
|
self.DST.clear()
|
||||||
|
return SystemAct(SystemActType.REQMORE, [])
|
||||||
|
meeting_to_update = False
|
||||||
|
if not meeting_to_update:
|
||||||
|
if last_user_act == UserActType.CONFIRM:
|
||||||
|
meeting_to_update = True
|
||||||
|
self.DST.clear_slots()
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['date'])
|
||||||
|
elif last_user_act == UserActType.NEGATE:
|
||||||
|
self.DST.clear()
|
||||||
|
return SystemAct(SystemActType.REQMORE, [])
|
||||||
|
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:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['date'])
|
||||||
|
elif 'time' not in slots:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['time'])
|
||||||
|
else:
|
||||||
|
# implementacja wyszukiwania odpowiedniego spotkania w bazie
|
||||||
|
return SystemAct(SystemActType.CONFIRM_DOMAIN, ['cancel_meeting'])
|
||||||
|
elif last_system_act.getActType() == SystemActType.REQUEST:
|
||||||
|
if 'date' not in slots:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['date'])
|
||||||
|
elif 'time' not in slots:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['time'])
|
||||||
|
else:
|
||||||
|
# implementacja wyszukiwania odpowiedniego spotkania w bazie
|
||||||
|
return SystemAct(SystemActType.CONFIRM_DOMAIN, ['cancel_meeting'])
|
||||||
|
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()
|
||||||
|
return SystemAct(SystemActType.REQMORE, [])
|
||||||
|
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()
|
||||||
|
return SystemAct(SystemActType.REQMORE, [])
|
||||||
|
else:
|
||||||
|
if 'date' in slots:
|
||||||
|
system_act = SystemAct(SystemActType.MEETING_LIST, slots)
|
||||||
|
self.DST.clear()
|
||||||
|
return system_act
|
||||||
|
else:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['date'])
|
||||||
|
# stan prośby o czas wolny
|
||||||
|
elif dialogue_state == UserActType.FREE_TIME:
|
||||||
|
if last_user_act == UserActType.NEGATE:
|
||||||
|
self.DST.clear()
|
||||||
|
return SystemAct(SystemActType.REQMORE, [])
|
||||||
|
else:
|
||||||
|
if 'date' in slots:
|
||||||
|
system_act = SystemAct(SystemActType.FREE_TIME, slots)
|
||||||
|
self.DST.clear()
|
||||||
|
return system_act
|
||||||
|
else:
|
||||||
|
return SystemAct(SystemActType.REQUEST, ['date'])
|
||||||
|
# brak określonego stanu
|
||||||
else:
|
else:
|
||||||
return SystemAct(SystemActType.INFORM,['name'])
|
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, [])
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from os import system
|
||||||
from UserActType import UserActType
|
from UserActType import UserActType
|
||||||
from UserAct import UserAct
|
from UserAct import UserAct
|
||||||
|
|
||||||
@ -10,16 +11,41 @@ class DST:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.frameList = []
|
|
||||||
self.state = None
|
self.state = None
|
||||||
|
self.last_user_act = None
|
||||||
|
self.last_system_act = None
|
||||||
|
self.slots = {}
|
||||||
|
|
||||||
def update(self, frame):
|
def user_update(self, frame):
|
||||||
self.addFrame(frame)
|
user_act = frame.getActType()
|
||||||
self.state = frame
|
self.last_user_act = user_act
|
||||||
return self.state
|
for slot in frame.getActParams():
|
||||||
|
if slot[0] == 'participant':
|
||||||
|
if 'participants' not in self.slots:
|
||||||
|
self.slots['participants'] = [slot[1]]
|
||||||
|
else:
|
||||||
|
self.slots['participants'].append(slot[1])
|
||||||
|
else:
|
||||||
|
self.slots[slot[0]] = slot[1]
|
||||||
|
if not self.state:
|
||||||
|
if user_act in [UserActType.CREATE_MEETING, UserActType.UPDATE_MEETING, UserActType.CANCEL_MEETING, UserActType.MEETING_LIST, UserActType.FREE_TIME]:
|
||||||
|
self.state = user_act
|
||||||
|
|
||||||
def addFrame(self, frame):
|
def system_update(self, system_act):
|
||||||
self.frameList.append(frame)
|
self.last_system_act = system_act
|
||||||
|
|
||||||
def getFrames(self):
|
def insert_empty_slot(self, slot_name):
|
||||||
return self.frameList
|
self.slots[slot_name] = None
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
self.state = None
|
||||||
|
self.slots = {}
|
||||||
|
|
||||||
|
def clear_slots(self):
|
||||||
|
self.slots = {}
|
||||||
|
|
||||||
|
def get_dialogue_state(self):
|
||||||
|
return self.state, self.last_user_act, self.last_system_act
|
||||||
|
|
||||||
|
def get_dialogue_slots(self):
|
||||||
|
return self.slots
|
||||||
|
@ -4,12 +4,11 @@ from enum import Enum, unique
|
|||||||
@unique
|
@unique
|
||||||
class SystemActType(Enum):
|
class SystemActType(Enum):
|
||||||
WELCOME_MSG = 0
|
WELCOME_MSG = 0
|
||||||
INFORM = 1
|
BYE = 1
|
||||||
BYE = 2
|
REQMORE = 2
|
||||||
REQUEST = 3
|
AFFIRM = 3
|
||||||
INFORM = 4
|
CONFIRM_DOMAIN = 4
|
||||||
AFFIRM = 5
|
MEETING_LIST = 5
|
||||||
CONFIRM_DOMAIN = 6
|
FREE_TIME = 6
|
||||||
OFFER = 7
|
REQUEST = 7
|
||||||
REQMORE = 8
|
|
||||||
NOT_UNDERSTOOD = -1
|
NOT_UNDERSTOOD = -1
|
||||||
|
18
main.py
18
main.py
@ -7,16 +7,28 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
nlu = NLU()
|
nlu = NLU()
|
||||||
dst = DST()
|
dst = DST()
|
||||||
dp = DP()
|
dp = DP(dst)
|
||||||
nlg = NLG()
|
nlg = NLG()
|
||||||
|
|
||||||
while(1):
|
while(1):
|
||||||
user_input = input("Wpisz tekst: ")
|
user_input = input("Wpisz tekst: ")
|
||||||
|
|
||||||
user_frame = nlu.parse_user_input(user_input)
|
user_frame = nlu.parse_user_input(user_input)
|
||||||
|
print('------ rozpoznany user frame ------')
|
||||||
print(user_frame)
|
print(user_frame)
|
||||||
#dst.addFrame(user_frame)
|
dst.user_update(user_frame)
|
||||||
#system_act = dp.chooseTactic(dst.getFrames())
|
state, last_user_act, last_system_act = dst.get_dialogue_state()
|
||||||
|
slots = dst.get_dialogue_slots()
|
||||||
|
system_act = dp.chooseTactic()
|
||||||
|
dst.system_update(system_act)
|
||||||
|
print('------ stan ------')
|
||||||
|
print(state, last_user_act, last_system_act)
|
||||||
|
print('------ przechowywane sloty ------')
|
||||||
|
print(slots)
|
||||||
|
print('------ wybrana akcja systemu ------')
|
||||||
|
print(system_act)
|
||||||
|
print('-----------------------------------')
|
||||||
|
print('-----------------------------------')
|
||||||
#text = nlg.toText(system_act)
|
#text = nlg.toText(system_act)
|
||||||
|
|
||||||
#print(text)
|
#print(text)
|
||||||
|
Loading…
Reference in New Issue
Block a user