Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
f69e664e04 | |||
508508a416 | |||
bf1c7b95fd | |||
af98dabec7 | |||
6e4e1271c4 |
36
DBManager.py
36
DBManager.py
@ -43,6 +43,10 @@ class calender_db:
|
|||||||
with open(self.db_file_path, 'r+') as f:
|
with open(self.db_file_path, 'r+') as f:
|
||||||
self.db = json.load(f)
|
self.db = json.load(f)
|
||||||
|
|
||||||
|
def clear_db(self):
|
||||||
|
self.db = {}
|
||||||
|
self.save_db()
|
||||||
|
|
||||||
def save_db(self):
|
def save_db(self):
|
||||||
with open(self.db_file_path, 'w+') as f:
|
with open(self.db_file_path, 'w+') as f:
|
||||||
json.dump(self.db, f)
|
json.dump(self.db, f)
|
||||||
@ -72,19 +76,10 @@ class calender_db:
|
|||||||
self.db[format_date(date_time)] = meetings
|
self.db[format_date(date_time)] = meetings
|
||||||
self.save_db()
|
self.save_db()
|
||||||
|
|
||||||
def update_meeting(self, meeting_dict):
|
|
||||||
date_time = get_date(
|
|
||||||
meeting_dict['date'].lower(), meeting_dict['time'].lower())
|
|
||||||
|
|
||||||
if format_date(date_time) in self.db.keys():
|
def update_meeting(self, old_meeting_date, old_meeting_time, new_meeting_dict):
|
||||||
meetings = self.db[format_date(date_time)]
|
self.delete_meeting(old_meeting_date, old_meeting_time)
|
||||||
for key, meeting in enumerate(meetings):
|
self.create_meeting(new_meeting_dict)
|
||||||
if format_time(meeting['time']) == format_time(meeting_dict['time'].lower()):
|
|
||||||
meetings.remove(meeting)
|
|
||||||
|
|
||||||
meetings.append(meeting_dict)
|
|
||||||
self.db[format_date(date_time)] = meetings
|
|
||||||
self.save_db()
|
|
||||||
|
|
||||||
def find_meeting(self, date, time):
|
def find_meeting(self, date, time):
|
||||||
if date in self.db.keys():
|
if date in self.db.keys():
|
||||||
@ -180,10 +175,15 @@ class calender_db:
|
|||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
# db = calender_db()
|
# db = calender_db()
|
||||||
# db.create_meeting({"date": "16.06.2021", "time": "15:00",
|
# db.clear_db()
|
||||||
# "description": "chuj"})
|
# db.create_meeting({"date": "16.06.2021", "time": "15:00", "description": "ciastko"})
|
||||||
# db.create_meeting({"date": "14.06.2021", "time": "13:00-18:00"})
|
# db.create_meeting({"date": "14.06.2021", "time": "13:00-18:00"})
|
||||||
# db.delete_meeting("16.06.2021", "15:00")
|
#db.create_meeting({"date": "16.06.2021", "time": "12:00-13:00", "description": "costam"})
|
||||||
# print(db.find_meeting("16.06.2021", "13:00-14:00"))
|
#print(db.get_meetings(["16.06.2021", "14.06.2021"]))
|
||||||
# print(db.get_meetings(["16.06.2021", "14.06.2021"]))
|
#db.update_meeting("16.06.2021", "12:00-13:00", {"date": "14.06.2021", "time": "11:00-12:00"})
|
||||||
# print(db.is_collision("16.06.2021", "12:30-13"))
|
#print(db.get_meetings(["16.06.2021", "14.06.2021"]))
|
||||||
|
#db.delete_meeting("16.06.2021", "15:00")
|
||||||
|
#print(db.find_meeting("16.06.2021", "13:00-14:00"))
|
||||||
|
#print(db.get_meetings(["16.06.2021", "14.06.2021"]))
|
||||||
|
#print(db.is_collision("16.06.2021", "12:30-13"))
|
||||||
|
#db.clear_db()
|
@ -11,8 +11,9 @@ class DP:
|
|||||||
Wyjście: Akt systemu (rama)
|
Wyjście: Akt systemu (rama)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, dst):
|
def __init__(self, dst, db):
|
||||||
self.DST = dst
|
self.DST = dst
|
||||||
|
self.DB = db
|
||||||
self.meeting_to_update = False
|
self.meeting_to_update = False
|
||||||
|
|
||||||
def chooseTactic(self) -> SystemAct:
|
def chooseTactic(self) -> SystemAct:
|
||||||
@ -71,6 +72,7 @@ class DP:
|
|||||||
self.DST.system_update(system_act)
|
self.DST.system_update(system_act)
|
||||||
return system_act
|
return system_act
|
||||||
else:
|
else:
|
||||||
|
# TODO sprawdzanie czy spotkanie nie koliduje
|
||||||
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)
|
||||||
return system_act
|
return system_act
|
||||||
@ -78,6 +80,7 @@ class DP:
|
|||||||
if last_user_act == UserActType.CONFIRM:
|
if last_user_act == UserActType.CONFIRM:
|
||||||
system_act = SystemAct(SystemActType.AFFIRM, ['create_meeting'])
|
system_act = SystemAct(SystemActType.AFFIRM, ['create_meeting'])
|
||||||
# implementacja wpisywanie spotkania do bazy
|
# implementacja wpisywanie spotkania do bazy
|
||||||
|
self.DB.create_meeting(slots)
|
||||||
self.DST.clear()
|
self.DST.clear()
|
||||||
return system_act
|
return system_act
|
||||||
elif last_user_act == UserActType.NEGATE:
|
elif last_user_act == UserActType.NEGATE:
|
||||||
@ -201,7 +204,10 @@ class DP:
|
|||||||
return system_act
|
return system_act
|
||||||
else:
|
else:
|
||||||
# implementacja wyszukiwania odpowiedniego spotkania w bazie
|
# implementacja wyszukiwania odpowiedniego spotkania w bazie
|
||||||
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, ['meeting_to_cancel'])
|
slots_to_delete = self.DB.find_meeting(slots['date'], slots['time'])
|
||||||
|
self.DST.update_slots(slots_to_delete)
|
||||||
|
#system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, ['meeting_to_cancel'])
|
||||||
|
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, slots_to_delete)
|
||||||
self.DST.system_update(system_act)
|
self.DST.system_update(system_act)
|
||||||
return system_act
|
return system_act
|
||||||
elif last_system_act.getActType() == SystemActType.REQUEST:
|
elif last_system_act.getActType() == SystemActType.REQUEST:
|
||||||
@ -215,13 +221,17 @@ class DP:
|
|||||||
return system_act
|
return system_act
|
||||||
else:
|
else:
|
||||||
# implementacja wyszukiwania odpowiedniego spotkania w bazie
|
# implementacja wyszukiwania odpowiedniego spotkania w bazie
|
||||||
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, ['meeting_to_cancel'])
|
slots_to_delete = self.DB.find_meeting(slots['date'], slots['time'])
|
||||||
|
self.DST.update_slots(slots_to_delete)
|
||||||
|
# system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, ['meeting_to_cancel'])
|
||||||
|
system_act = SystemAct(SystemActType.CONFIRM_DOMAIN, slots_to_delete)
|
||||||
self.DST.system_update(system_act)
|
self.DST.system_update(system_act)
|
||||||
return system_act
|
return system_act
|
||||||
elif last_system_act.getActType() == SystemActType.CONFIRM_DOMAIN:
|
elif last_system_act.getActType() == SystemActType.CONFIRM_DOMAIN:
|
||||||
if last_user_act == UserActType.CONFIRM:
|
if last_user_act == UserActType.CONFIRM:
|
||||||
system_act = SystemAct(SystemActType.AFFIRM, ['cancel_meeting'])
|
system_act = SystemAct(SystemActType.AFFIRM, ['cancel_meeting'])
|
||||||
# implementacja usuwania spotkania z bazy
|
# implementacja usuwania spotkania z bazy
|
||||||
|
self.DB.delete_meeting(slots['date'], slots['time'])
|
||||||
self.DST.clear()
|
self.DST.clear()
|
||||||
return system_act
|
return system_act
|
||||||
elif last_user_act == UserActType.NEGATE:
|
elif last_user_act == UserActType.NEGATE:
|
||||||
@ -231,18 +241,42 @@ class DP:
|
|||||||
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 not last_system_act:
|
||||||
self.DST.clear()
|
if 'date' not in slots:
|
||||||
return SystemAct(SystemActType.REQMORE, ['meeting_list'])
|
|
||||||
else:
|
|
||||||
if 'date' in slots:
|
|
||||||
system_act = SystemAct(SystemActType.MEETING_LIST, slots)
|
|
||||||
self.DST.clear()
|
|
||||||
return system_act
|
|
||||||
else:
|
|
||||||
system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
||||||
self.DST.system_update(system_act)
|
self.DST.system_update(system_act)
|
||||||
return system_act
|
return system_act
|
||||||
|
else:
|
||||||
|
# implementacja wyszukiwania spotkań w bazie
|
||||||
|
meetings_slots = self.DB.get_meetings([slots['date']])
|
||||||
|
system_act = SystemAct(SystemActType.MEETING_LIST, meetings_slots)
|
||||||
|
self.DST.system_update(system_act)
|
||||||
|
return system_act
|
||||||
|
elif last_system_act.getActType() == SystemActType.REQUEST:
|
||||||
|
if 'date' not in slots:
|
||||||
|
system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
||||||
|
self.DST.system_update(system_act)
|
||||||
|
return system_act
|
||||||
|
else:
|
||||||
|
# implementacja wyszukiwania spotkań w bazie
|
||||||
|
meetings_slots = self.DB.get_meetings([slots['date']])
|
||||||
|
system_act = SystemAct(SystemActType.MEETING_LIST, meetings_slots)
|
||||||
|
self.DST.system_update(system_act)
|
||||||
|
return system_act
|
||||||
|
else:
|
||||||
|
return SystemAct(SystemActType.NOT_UNDERSTOOD, [])
|
||||||
|
# if last_user_act == UserActType.NEGATE:
|
||||||
|
# self.DST.clear()
|
||||||
|
# return SystemAct(SystemActType.REQMORE, ['meeting_list'])
|
||||||
|
# else:
|
||||||
|
# if 'date' in slots:
|
||||||
|
# system_act = SystemAct(SystemActType.MEETING_LIST, slots)
|
||||||
|
# self.DST.clear()
|
||||||
|
# return system_act
|
||||||
|
# else:
|
||||||
|
# system_act = SystemAct(SystemActType.REQUEST, ['date'])
|
||||||
|
# self.DST.system_update(system_act)
|
||||||
|
# return system_act
|
||||||
# stan prośby o czas wolny
|
# stan prośby o czas wolny
|
||||||
elif dialogue_state == UserActType.FREE_TIME:
|
elif dialogue_state == UserActType.FREE_TIME:
|
||||||
if last_user_act == UserActType.NEGATE:
|
if last_user_act == UserActType.NEGATE:
|
||||||
|
@ -45,6 +45,9 @@ class DST:
|
|||||||
def clear_slots(self):
|
def clear_slots(self):
|
||||||
self.slots = {}
|
self.slots = {}
|
||||||
|
|
||||||
|
def update_slots(self, slots):
|
||||||
|
self.slots = slots
|
||||||
|
|
||||||
def get_dialogue_state(self):
|
def get_dialogue_state(self):
|
||||||
return self.state, self.last_user_act, self.last_system_act
|
return self.state, self.last_user_act, self.last_system_act
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ class NLG:
|
|||||||
self.DST = dst
|
self.DST = dst
|
||||||
|
|
||||||
def generateResponse(self, systemAct: SystemAct) -> str:
|
def generateResponse(self, systemAct: SystemAct) -> str:
|
||||||
dialogue_state, last_user_act, _ = self.DST.get_dialogue_state()
|
dialogue_state, _, last_system_act = self.DST.get_dialogue_state()
|
||||||
slots = self.DST.get_dialogue_slots()
|
slots = self.DST.get_dialogue_slots()
|
||||||
if dialogue_state == UserActType.CREATE_MEETING:
|
if dialogue_state == UserActType.CREATE_MEETING:
|
||||||
if systemAct.getActType() == SystemActType.REQUEST:
|
if systemAct.getActType() == SystemActType.REQUEST:
|
||||||
@ -33,6 +33,9 @@ class NLG:
|
|||||||
place = slots['place']
|
place = slots['place']
|
||||||
part_list = slots['participants']
|
part_list = slots['participants']
|
||||||
part = ""
|
part = ""
|
||||||
|
if part_list is None:
|
||||||
|
part = None
|
||||||
|
else:
|
||||||
for p in part_list:
|
for p in part_list:
|
||||||
part += p
|
part += p
|
||||||
part += ", "
|
part += ", "
|
||||||
@ -43,6 +46,11 @@ class NLG:
|
|||||||
|
|
||||||
# TODO: nie sprawdzone - trudno wejść do tego stanu
|
# TODO: nie sprawdzone - trudno wejść do tego stanu
|
||||||
elif dialogue_state == UserActType.UPDATE_MEETING:
|
elif dialogue_state == UserActType.UPDATE_MEETING:
|
||||||
|
# TODO zaślepka do wywalenia
|
||||||
|
response = "Przepraszam ale obecnie nie obsługuje jeszcze tej funkcji :("
|
||||||
|
self.DST.clear()
|
||||||
|
return response
|
||||||
|
# -------------------------------------
|
||||||
if systemAct.getActType() == SystemActType.REQUEST:
|
if systemAct.getActType() == SystemActType.REQUEST:
|
||||||
if "date" in systemAct.getActParams():
|
if "date" in systemAct.getActParams():
|
||||||
return "W jakim dniu miało się odbyć to spotkanie?"
|
return "W jakim dniu miało się odbyć to spotkanie?"
|
||||||
@ -55,6 +63,9 @@ class NLG:
|
|||||||
place = slots['place']
|
place = slots['place']
|
||||||
part_list = slots['participants']
|
part_list = slots['participants']
|
||||||
part = ""
|
part = ""
|
||||||
|
if part_list is None:
|
||||||
|
part = None
|
||||||
|
else:
|
||||||
for p in part_list:
|
for p in part_list:
|
||||||
part += p
|
part += p
|
||||||
part += ", "
|
part += ", "
|
||||||
@ -69,44 +80,54 @@ class NLG:
|
|||||||
return "W jakim dniu miało się odbyć to spotkanie?"
|
return "W jakim dniu miało się odbyć to spotkanie?"
|
||||||
if "time" in systemAct.getActParams():
|
if "time" in systemAct.getActParams():
|
||||||
return "W jakim czasie miało się odbyć to spotkanie?"
|
return "W jakim czasie miało się odbyć to spotkanie?"
|
||||||
# TODO dopracować po dodaniu DB
|
|
||||||
if systemAct.getActType() == SystemActType.CONFIRM_DOMAIN:
|
if systemAct.getActType() == SystemActType.CONFIRM_DOMAIN:
|
||||||
date = slots['date']
|
date = slots['date']
|
||||||
time = slots['time']
|
time = slots['time']
|
||||||
# place = slots['place']
|
place = slots['place']
|
||||||
# part_list = slots['participants']
|
part_list = slots['participants']
|
||||||
# part = ""
|
part = ""
|
||||||
# for p in part_list:
|
if part_list is None:
|
||||||
# part += p
|
part = None
|
||||||
# part += ", "
|
else:
|
||||||
# part = part[:-2]
|
for p in part_list:
|
||||||
# desc = slots['description']
|
part += p
|
||||||
return f'Spotkanie:\n' \
|
part += ", "
|
||||||
f'Dzień: {date}\nCzas: {time}'
|
part = part[:-2]
|
||||||
|
desc = slots['description']
|
||||||
|
return f'Odwołać te spotkanie?:\n' \
|
||||||
|
f'Dzień: {date}\nCzas: {time}\nMiejsce: {place}\nUczestnicy: {part}\nOpis: {desc}'
|
||||||
|
|
||||||
elif dialogue_state == UserActType.MEETING_LIST:
|
elif dialogue_state == UserActType.MEETING_LIST:
|
||||||
if systemAct.getActType() == SystemActType.REQUEST:
|
if systemAct.getActType() == SystemActType.REQUEST:
|
||||||
if "date" in systemAct.getActParams():
|
if "date" in systemAct.getActParams():
|
||||||
return "Z jakiego okresu chcesz przejrzeć spotkania?"
|
return "Z jakiego okresu chcesz przejrzeć spotkania?"
|
||||||
# TODO: dopracować po dodaniu DB
|
|
||||||
if systemAct.getActType() == SystemActType.MEETING_LIST:
|
if systemAct.getActType() == SystemActType.MEETING_LIST:
|
||||||
response = ""
|
response = ""
|
||||||
for s in slots:
|
for s in last_system_act.getActParams():
|
||||||
date = s['date']
|
date = s['date']
|
||||||
time = s['time']
|
time = s['time']
|
||||||
place = s['place']
|
place = s['place']
|
||||||
part_list = s['participants']
|
part_list = s['participants']
|
||||||
part = ""
|
part = ""
|
||||||
|
if part_list is None:
|
||||||
|
part = None
|
||||||
|
else:
|
||||||
for p in part_list:
|
for p in part_list:
|
||||||
part += p
|
part += p
|
||||||
part += ", "
|
part += ", "
|
||||||
part = part[:-2]
|
part = part[:-2]
|
||||||
desc = s['description']
|
desc = s['description']
|
||||||
response += f'Spotkanie:\nDzień: {date}\nCzas: {time}\nMiejsce: {place}\nUczestnicy: {part}\nOpis: {desc}\n'
|
response += f'\nSpotkanie:\nDzień: {date}\nCzas: {time}\nMiejsce: {place}\nUczestnicy: {part}\nOpis: {desc}\n'
|
||||||
response += "--------------------"
|
response += "--------------------"
|
||||||
|
self.DST.clear()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
elif dialogue_state == UserActType.FREE_TIME:
|
elif dialogue_state == UserActType.FREE_TIME:
|
||||||
|
# TODO zaślepka do wywalenia
|
||||||
|
response = "Przepraszam ale obecnie nie obsługuje jeszcze tej funkcji :("
|
||||||
|
self.DST.clear()
|
||||||
|
return response
|
||||||
|
#-------------------------------------
|
||||||
if systemAct.getActType() == SystemActType.REQUEST:
|
if systemAct.getActType() == SystemActType.REQUEST:
|
||||||
if "date" in systemAct.getActParams():
|
if "date" in systemAct.getActParams():
|
||||||
return "W jakim okresie chcesz znaleźć wolny czas?"
|
return "W jakim okresie chcesz znaleźć wolny czas?"
|
||||||
|
@ -124,6 +124,7 @@ def get_datetime_from_day(day, hours, minutes):
|
|||||||
|
|
||||||
|
|
||||||
def get_date(date, time):
|
def get_date(date, time):
|
||||||
|
print("test\ndate: ", date, "\ntime: ", time)
|
||||||
# parsowanie czasu
|
# parsowanie czasu
|
||||||
if re.match(r'^[0-2][0-9]$', time):
|
if re.match(r'^[0-2][0-9]$', time):
|
||||||
hours = int(time)
|
hours = int(time)
|
||||||
|
26
main.py
26
main.py
@ -3,36 +3,36 @@ from NaturalLanguageUnderstanding import NLU
|
|||||||
from NaturalLanguageGeneration import NLG
|
from NaturalLanguageGeneration import NLG
|
||||||
from DialogueStateTracker import DST
|
from DialogueStateTracker import DST
|
||||||
from DialoguePolicy import DP
|
from DialoguePolicy import DP
|
||||||
|
from DBManager import calender_db
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
db = calender_db()
|
||||||
nlu = NLU()
|
nlu = NLU()
|
||||||
dst = DST()
|
dst = DST()
|
||||||
dp = DP(dst)
|
dp = DP(dst, db)
|
||||||
nlg = NLG(dst)
|
nlg = NLG(dst)
|
||||||
|
|
||||||
while(1):
|
while(1):
|
||||||
user_input = input("Wpisz tekst: ")
|
user_input = input("\nWpisz tekst: ")
|
||||||
|
|
||||||
user_frame = nlu.parse_user_input(user_input)
|
user_frame = nlu.parse_user_input(user_input)
|
||||||
print('------ rozpoznany user frame ------')
|
# print('\n------ rozpoznany user frame ------')
|
||||||
print(user_frame)
|
# print(user_frame)
|
||||||
|
|
||||||
dst.user_update(user_frame)
|
dst.user_update(user_frame)
|
||||||
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('\n------ stan ------')
|
||||||
print(state, last_user_act, last_system_act)
|
# print(state, last_user_act, last_system_act)
|
||||||
print('------ przechowywane sloty ------')
|
# print('\n------ przechowywane sloty ------')
|
||||||
print(slots)
|
# print(slots)
|
||||||
print('------ wybrana akcja systemu ------')
|
print('\n------ wybrana akcja systemu ------')
|
||||||
print(system_act)
|
print(system_act)
|
||||||
system_response = nlg.generateResponse(system_act)
|
system_response = nlg.generateResponse(system_act)
|
||||||
print('------ wygenerowana odpowiedź systemu ------')
|
print('\n------ wygenerowana odpowiedź systemu ------')
|
||||||
print(system_response)
|
print(system_response)
|
||||||
print('-----------------------------------')
|
|
||||||
print('-----------------------------------')
|
|
||||||
|
|
||||||
if system_act.getActType() == SystemActType.BYE:
|
if system_act.getActType() == SystemActType.BYE:
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user