System_Dialogowy_Janet/Code/Modules/DST_module.py

57 lines
2.1 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-05-30 14:45:42 +02:00
def update(self, user_acts=None):
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
if 'prescription' in intent:
if (slot == 'prescription'):
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
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-05-30 14:45:42 +02:00
print(self.state)
return self.state