2022-05-23 21:07:01 +02:00
|
|
|
from dialogue_state import default_state
|
2022-05-28 14:18:38 +02:00
|
|
|
|
2022-05-23 21:07:01 +02:00
|
|
|
|
|
|
|
# Monitor stanu dialogu
|
2022-05-28 14:18:38 +02:00
|
|
|
class DST:
|
2022-05-23 21:07:01 +02:00
|
|
|
def __init__(self):
|
|
|
|
self.state = default_state()
|
|
|
|
|
|
|
|
def update(self, user_act=None):
|
|
|
|
for intent, domain, slot, value in user_act:
|
|
|
|
domain = domain.lower()
|
|
|
|
intent = intent.lower()
|
2022-05-28 14:18:38 +02:00
|
|
|
slot = slot.lower()
|
2022-05-23 21:07:01 +02:00
|
|
|
|
2022-05-28 14:18:38 +02:00
|
|
|
k = slot
|
2022-05-23 21:07:01 +02:00
|
|
|
|
2022-05-28 14:18:38 +02:00
|
|
|
if 'inform' in intent:
|
2022-05-23 21:07:01 +02:00
|
|
|
|
|
|
|
if k is None:
|
|
|
|
continue
|
|
|
|
|
|
|
|
domain_dic = self.state['belief_state'][domain]
|
|
|
|
|
|
|
|
if k in domain_dic['semi']:
|
2022-05-28 14:18:38 +02:00
|
|
|
self.state['belief_state'][domain]['semi'][k] = value
|
2022-05-23 21:07:01 +02:00
|
|
|
elif k in domain_dic['book']:
|
|
|
|
self.state['belief_state'][domain]['book'][k] = value
|
2022-05-28 14:18:38 +02:00
|
|
|
|
|
|
|
if 'request' in intent:
|
2022-05-23 21:07:01 +02:00
|
|
|
|
|
|
|
if domain not in self.state['request_state']:
|
|
|
|
self.state['request_state'][domain] = {}
|
|
|
|
if k not in self.state['request_state'][domain]:
|
|
|
|
self.state['request_state'][domain][k] = 0
|
|
|
|
|
2022-05-28 14:18:38 +02:00
|
|
|
self.state['user_action'].append([intent, domain, slot, value])
|
|
|
|
|
2022-05-23 21:07:01 +02:00
|
|
|
return self.state
|
|
|
|
|
|
|
|
def init_session(self):
|
|
|
|
self.state = default_state()
|
|
|
|
|
|
|
|
|
2022-05-28 14:18:38 +02:00
|
|
|
# Przykładowe uruchomienie dla kodu w izolacji
|
2022-05-23 21:07:01 +02:00
|
|
|
"""
|
|
|
|
dst = DST()
|
|
|
|
print(dst.state)
|
|
|
|
|
2022-05-28 14:18:38 +02:00
|
|
|
dst.update([['hello_inform', 'Cinema', 'Price', '15 zł'], ['Inform', 'Cinema', 'Movie', 'Batman']])
|
|
|
|
print(dst.state)
|
2022-05-23 21:07:01 +02:00
|
|
|
"""
|