System_Dialogowy_Janet/Code/Modules/DST_module.py

47 lines
1.7 KiB
Python
Raw Normal View History

2021-05-30 13:31:34 +02:00
import json
2021-05-30 14:45:42 +02:00
class Rules_DST(): #Dialogue State Tracker
2021-05-27 15:11:28 +02:00
"""
Moduł odpowiedzialny za śledzenie stanu dialogu. Przechowuje informacje o tym jakie dane zostały uzyskane od użytkownika w toku prowadzonej konwersacji.
Wejście: Akt użytkownika (rama)
Wyjście: Reprezentacja stanu dialogu (rama)
"""
2021-05-30 13:31:34 +02:00
def __init__(self):
self.state = json.load(open('default_state.json'))
2021-06-06 12:09:20 +02:00
def update_user(self, user_acts=None):
2021-05-30 14:45:42 +02:00
for intent, domain, slot, value in user_acts:
self.state["user_action"].append([intent, domain, slot, value])
if domain in ['password', 'name', 'email', 'enter_email', 'enter_name']:
return
2021-05-30 13:31:34 +02:00
2021-05-30 14:45:42 +02:00
if 'appointment' in intent:
if (slot == 'appointment'):
continue
if(domain in slot):
slot.replace(domain + "/", '')
2021-05-30 13:31:34 +02:00
domain_dic = self.state['belief_state'][domain]
2021-05-30 14:45:42 +02:00
if slot in domain_dic:
self.state['belief_state'][domain][slot] = value
2021-05-31 00:01:31 +02:00
if 'request_information' in intent:
if (slot == 'request_information'):
continue
if(domain in slot):
slot.replace(domain + "/", '')
2021-05-31 00:01:31 +02:00
if domain not in self.state['request_state']:
self.state['request_state'][domain] = {}
if slot not in self.state['request_state'][domain]:
self.state['request_state'][domain][slot] = value
2021-06-06 12:09:20 +02:00
elif intent == 'end_conversation':
self.state = json.load(open('default_state.json'))
2021-05-30 14:45:42 +02:00
print(self.state)
2021-05-31 15:28:48 +02:00
print("\n")
2021-06-06 12:09:20 +02:00
return self.state