From 3464a04349e39c43dbf6e5ee3a5566d5f89e1182 Mon Sep 17 00:00:00 2001 From: PawelDopierala Date: Sat, 8 Jun 2024 14:11:17 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20Dzi=C4=99kuj=C4=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DialoguePolicy.py | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/DialoguePolicy.py b/DialoguePolicy.py index 3826cee..888e299 100644 --- a/DialoguePolicy.py +++ b/DialoguePolicy.py @@ -58,28 +58,29 @@ class DialoguePolicy(Policy): def update_system_action(self, user_act, user_action, state, system_action): domain, intent = user_act - constraints = [(slot, value) for slot, value in state['belief_state'][domain]['info'].items() if value != ''] - # print(f"Constraints: {constraints}") - self.results = deepcopy(self.query(domain.lower(), constraints)) - # print(f"Query results: {self.results}") + if domain in state['belief_state']: + constraints = [(slot, value) for slot, value in state['belief_state'][domain]['info'].items() if value != ''] + # print(f"Constraints: {constraints}") + self.results = deepcopy(self.query(domain.lower(), constraints)) + # print(f"Query results: {self.results}") - if intent == 'request': - if len(self.results) == 0: - system_action[(domain, 'NoOffer')] = [] - else: - for slot in user_action[user_act]: - if slot[0] in self.results[0]: - system_action[(domain, 'Inform')].append([slot[0], self.results[0].get(slot[0], 'unknown')]) + if intent == 'request': + if len(self.results) == 0: + system_action[(domain, 'NoOffer')] = [] + else: + for slot in user_action[user_act]: + if slot[0] in self.results[0]: + system_action[(domain, 'Inform')].append([slot[0], self.results[0].get(slot[0], 'unknown')]) - elif intent == 'inform': - if len(self.results) == 0: - system_action[(domain, 'NoOffer')] = [] - else: - system_action[(domain, 'Inform')].append(['Choice', str(len(self.results))]) - choice = self.results[0] + elif intent == 'inform': + if len(self.results) == 0: + system_action[(domain, 'NoOffer')] = [] + else: + system_action[(domain, 'Inform')].append(['Choice', str(len(self.results))]) + choice = self.results[0] - if domain in ["hotel"]: - system_action[(domain, 'Recommend')].append(['Name', choice['name']]) - for slot in state['belief_state'][domain]['info']: - if choice.get(slot): - state['belief_state'][domain]['info'][slot] = choice[slot] \ No newline at end of file + if domain in ["hotel"]: + system_action[(domain, 'Recommend')].append(['Name', choice['name']]) + for slot in state['belief_state'][domain]['info']: + if choice.get(slot): + state['belief_state'][domain]['info'][slot] = choice[slot]