From adfea7187192cbfd35b05e04083f9e0cc0184646 Mon Sep 17 00:00:00 2001 From: Patryk Date: Fri, 7 Jun 2024 15:49:41 +0200 Subject: [PATCH] Dodanie normalizacji do DSM --- src/service/dialog_state_monitor.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/service/dialog_state_monitor.py b/src/service/dialog_state_monitor.py index 3edcf45..6916229 100644 --- a/src/service/dialog_state_monitor.py +++ b/src/service/dialog_state_monitor.py @@ -4,6 +4,11 @@ import json import copy +def normalize(value): + value = value.lower() + return ' '.join(value.split()) + + class DialogStateMonitor: def __init__(self, initial_state_file: str = '../attributes.json'): DST.__init__(self) @@ -25,28 +30,28 @@ class DialogStateMonitor: if frame.act == 'inform/order': new_order = dict() for slot in frame.slots: - new_order[slot.name] = slot.value + new_order[slot.name] = normalize(slot.value) self.__memory['order'].append(new_order) elif frame.act == 'inform/address': for slot in frame.slots: - self.__memory['address'][slot.name] = slot.value + self.__memory['address'][slot.name] = normalize(slot.value) elif frame.act == 'inform/phone': for slot in frame.slots: - self.__memory['phone'][slot.name] = slot.value + self.__memory['phone'][slot.name] = normalize(slot.value) elif frame.act == 'inform/order-complete': self.__memory['order-complete'] = True elif frame.act == 'inform/delivery': for slot in frame.slots: - self.__memory['delivery'][slot.name] = slot.value + self.__memory['delivery'][slot.name] = normalize(slot.value) elif frame.act == 'inform/payment': for slot in frame.slots: - self.__memory['payment'][slot.name] = slot.value + self.__memory['payment'][slot.name] = normalize(slot.value) elif frame.act == 'inform/time': for slot in frame.slots: - self.__memory['time'][slot.name] = slot.value + self.__memory['time'][slot.name] = normalize(slot.value) elif frame.act == 'inform/name': for slot in frame.slots: - self.__memory['name'][slot.name] = slot.value + self.__memory['name'][slot.name] = normalize(slot.value) def read(self) -> dict: return self.__memory