from dialogue_state import default_state import json from convlab2.dst.dst import DST as CL2DST from convlab2.dst.rule.multiwoz.dst_util import normalize_value # from convlab2.util.multiwoz.multiwoz_slot_trans import REF_SYS_DA REF_SYS_DA = { 'Cinema': { 'Type': 'type','Price': 'price','Stars': 'stars', 'Name': 'name','Day': 'day','People': 'people','Movie': 'movie', 'E-mail': 'e-mail', 'none': None }, } # Monitor stanu dialogu class DST(CL2DST): def __init__(self): CL2DST.__init__(self) self.state = default_state() self.value_dict = json.load(open('value_dict.json')) def update(self, user_act=None): for intent, domain, slot, value in user_act: domain = domain.lower() intent = intent.lower() if domain in ['unk', 'general', 'booking']: continue if intent == 'inform': k = REF_SYS_DA[domain.capitalize()].get(slot, slot) if k is None: continue domain_dic = self.state['belief_state'][domain] if k in domain_dic['semi']: nvalue = normalize_value(self.value_dict, domain, k, value) self.state['belief_state'][domain]['semi'][k] = nvalue elif k in domain_dic['book']: self.state['belief_state'][domain]['book'][k] = value elif k.lower() in domain_dic['book']: self.state['belief_state'][domain]['book'][k.lower()] = value elif intent == 'request': k = REF_SYS_DA[domain.capitalize()].get(slot, slot) 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 return self.state def init_session(self): self.state = default_state() # Przykładowe uruchomienie dla kodu jeszcze bez zmian pod rezerwację biletów kinowych """ dst = DST() print(dst.state) dst.update([['Inform', 'Cinema', 'Price', '15 zł'], ['Inform', 'Cinema', 'Movie', 'Batman']]) print(dst.state['belief_state']['cinema']) """