2.6 KiB
2.6 KiB
import json
import os
class DST():
def __init__(self):
self.state = json.load(open('dictionary.json'))
def update(self, user_act=None):
for intent, domain, slot, value in user_act:
domain = domain.lower()
intent = intent.lower()
slot = 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
dst = DST()
user_act = [('inform', 'payment', 'type', 'credit card'), ('inform', 'product', 'name', 'iPhone')]
state = dst.update(user_act)
print(state['belief_state'])
print(state['request_state'])
{'payment': {'type': 'credit card', 'amount': '', 'loyalty_card': ''}, 'delivery': {'type': '', 'address': '', 'time': ''}, 'product': {'name': 'iPhone', 'type': '', 'brand': '', 'price': '', 'quantity': '', 'quality': ''}} {}