diff --git a/attributes.json b/attributes.json index 85dc730..944a30b 100644 --- a/attributes.json +++ b/attributes.json @@ -1,6 +1,10 @@ { "dough": ["thick"], - "drink": ["pepsi", "cola", "water"], + "drink": { + "pepsi": {"price" : 10}, + "cola": {"price" : 10}, + "water": {"price" : 5} + }, "food": ["pizza"], "meat": ["chicken", "ham", "tuna"], "sauce": ["garlic", "1000w"], diff --git a/src/service/dialog_state_monitor.py b/src/service/dialog_state_monitor.py index 67b15b5..73705e8 100644 --- a/src/service/dialog_state_monitor.py +++ b/src/service/dialog_state_monitor.py @@ -44,7 +44,10 @@ class DialogStateMonitor: stage['completed'] = True return - def pizza_exists(self, name: str) -> bool: + def item_exists(self, type: str, name: str) -> bool: + return normalize(name) in self.state['constants'][type] + + def drink_exists(self, name: str) -> bool: return normalize(name) in self.state['constants']['pizza'] def get_total_cost(self) -> int: @@ -58,12 +61,12 @@ class DialogStateMonitor: new_order = dict() for slot in frame.slots: value = normalize(slot.value) - if slot.name == 'pizza': - if self.pizza_exists(value) is False: + if slot.name == 'pizza' or slot.name == 'drink': + if self.item_exists(slot.name, value) is False: self.state['was_previous_order_invalid'] = True return self.state['was_previous_order_invalid'] = False - self.state['total_cost'] += self.state['constants']['pizza'][value]['price'] + self.state['total_cost'] += self.state['constants'][slot.name][value]['price'] new_order[slot.name] = value self.state['belief_state']['order'].append(new_order) elif frame.act == 'inform/address': diff --git a/src/test/dialog_state_monitor.py b/src/test/dialog_state_monitor.py index ae4b44a..5d8087b 100644 --- a/src/test/dialog_state_monitor.py +++ b/src/test/dialog_state_monitor.py @@ -4,8 +4,9 @@ from src.model.slot import Slot dsm = DialogStateMonitor() -assert dsm.pizza_exists('capri') is True -assert dsm.pizza_exists('buraczana') is False +assert dsm.item_exists('pizza', 'capri') is True +assert dsm.item_exists('pizza', 'buraczana') is False +assert dsm.item_exists('drink', 'cola') is True assert dsm.state['was_previous_order_invalid'] is False frame1 = Frame('user', 'inform/order', [Slot('pizza', 'margarita'), Slot('sauce', 'ketchup')]) @@ -16,6 +17,9 @@ dsm.update(frame2) assert dsm.get_total_cost() == 60 frame3 = Frame('user', 'inform/order-complete', []) dsm.update(frame3) +frame4 = Frame('user', 'inform/order', [Slot('drink', 'cola')]) +dsm.update(frame4) +assert dsm.get_total_cost() == 70 assert dsm.state['belief_state']['order'][0]['pizza'] == 'margarita' assert dsm.state['belief_state']['order'][0]['sauce'] == 'ketchup' @@ -23,7 +27,7 @@ assert dsm.state['belief_state']['order-complete'] is True assert dsm.state['history'][0] == frame1 assert dsm.state['history'][1] == frame2 assert dsm.state['history'][2] == frame3 - +assert dsm.state['history'][3] == frame4 assert dsm.get_current_active_stage() == 'collect_food' dsm.mark_current_stage_completed()