diff --git a/DialogManager.ipynb b/DialogManager.ipynb index 7f0ed5e..542815e 100644 --- a/DialogManager.ipynb +++ b/DialogManager.ipynb @@ -102,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": 132, + "execution_count": 136, "metadata": {}, "outputs": [], "source": [ @@ -120,10 +120,8 @@ " system_acts = []\n", " for intent, domain, slot, value in state['user_act']:\n", " user_action[(domain.lower(), intent.lower())].append((slot.lower(), value))\n", - " print(user_action)\n", " for user_act in user_action:\n", " self.update_system_action(user_act, user_action, state, system_action)\n", - " print(self.update_system_action(user_act, user_action, state, system_action))\n", " system_acts = [[intent, domain, slot, value] for (domain, intent), slots in system_action.items() for slot, value in slots]\n", " state['system_act'] = system_acts\n", " return system_acts\n", @@ -131,6 +129,7 @@ "\n", " def update_system_action(self, user_act, user_action, state, system_action):\n", " domain, intent = user_act\n", + " constraints = [(slot, value) for slot, value in state['belief_state'][domain.lower()].items() if value != '']\n", " self.results = self.db['database'][domain]\n", "\n", " # ReguĊ‚a 1\n", @@ -149,45 +148,30 @@ " else:\n", " system_action[(domain, 'Inform')].append(['Choice', str(len(self.results))])\n", "\n", - " if self.results and 'name' in self.results[0]:\n", - " choice = self.results[0]\n", - "\n", - " if domain in [\"payment\", \"delivery\", \"product\"]:\n", - " system_action[(domain, 'Recommend')].append(['Name', choice['name']])" + " if domain == \"product\":\n", + " # Select the first product that matches the user's constraints\n", + " for product in self.results:\n", + " if all(product.get(slot, '').lower() == value.lower() for slot, value in constraints):\n", + " system_action[(domain, 'Recommend')].append(['Name', product['name']])\n", + " break\n" ] }, { "cell_type": "code", - "execution_count": 133, + "execution_count": 137, "metadata": {}, "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "defaultdict(, {('payment', 'inform'): [('type', 'karta')], ('delivery', 'inform'): [('type', 'paczkomat')], ('product', 'inform'): [('type', 'telefon')], ('product', 'request'): [('name', '?')]})\n", - "None\n", - "None\n", - "None\n", - "None\n" - ] - }, { "data": { "text/plain": [ "[['Inform', 'payment', 'Choice', '1'],\n", - " ['Inform', 'payment', 'Choice', '1'],\n", - " ['Inform', 'delivery', 'Choice', '1'],\n", " ['Inform', 'delivery', 'Choice', '1'],\n", " ['Inform', 'product', 'Choice', '3'],\n", - " ['Inform', 'product', 'Choice', '3'],\n", " ['Inform', 'product', 'name', 'banan'],\n", - " ['Inform', 'product', 'name', 'banan'],\n", - " ['Recommend', 'product', 'Name', 'banan'],\n", - " ['Recommend', 'product', 'Name', 'banan']]" + " ['Recommend', 'product', 'Name', 'iPhone']]" ] }, - "execution_count": 133, + "execution_count": 137, "metadata": {}, "output_type": "execute_result" }