35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
|
class SimpleRuleDST:
|
||
|
def __init__(self):
|
||
|
self.state = None
|
||
|
self.init_session()
|
||
|
|
||
|
def update(self, user_act=None):
|
||
|
for intent, domain, slot, value in user_act:
|
||
|
domain = domain.lower()
|
||
|
intent = intent.lower()
|
||
|
slot = slot.lower()
|
||
|
value = slot.lower()
|
||
|
|
||
|
if domain not in self.state['belief_state']:
|
||
|
continue
|
||
|
|
||
|
if intent == 'inform':
|
||
|
if slot == 'none' or slot == '':
|
||
|
continue
|
||
|
|
||
|
domain_dic = self.state['belief_state'][domain]
|
||
|
|
||
|
if slot in domain_dic:
|
||
|
self.state['belief_state'][domain][slot] = value
|
||
|
|
||
|
elif intent == 'request':
|
||
|
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] = 0
|
||
|
|
||
|
return self.state
|
||
|
|
||
|
def init_session(self):
|
||
|
self.state = None
|