Dodanie obsługi napoi w DSM

This commit is contained in:
Patryk Osiński 2024-06-10 00:53:38 +02:00
parent 79bf27aca4
commit 2b6a8b01a6
3 changed files with 19 additions and 8 deletions

View File

@ -1,6 +1,10 @@
{ {
"dough": ["thick"], "dough": ["thick"],
"drink": ["pepsi", "cola", "water"], "drink": {
"pepsi": {"price" : 10},
"cola": {"price" : 10},
"water": {"price" : 5}
},
"food": ["pizza"], "food": ["pizza"],
"meat": ["chicken", "ham", "tuna"], "meat": ["chicken", "ham", "tuna"],
"sauce": ["garlic", "1000w"], "sauce": ["garlic", "1000w"],

View File

@ -44,7 +44,10 @@ class DialogStateMonitor:
stage['completed'] = True stage['completed'] = True
return 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'] return normalize(name) in self.state['constants']['pizza']
def get_total_cost(self) -> int: def get_total_cost(self) -> int:
@ -58,12 +61,12 @@ class DialogStateMonitor:
new_order = dict() new_order = dict()
for slot in frame.slots: for slot in frame.slots:
value = normalize(slot.value) value = normalize(slot.value)
if slot.name == 'pizza': if slot.name == 'pizza' or slot.name == 'drink':
if self.pizza_exists(value) is False: if self.item_exists(slot.name, value) is False:
self.state['was_previous_order_invalid'] = True self.state['was_previous_order_invalid'] = True
return return
self.state['was_previous_order_invalid'] = False 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 new_order[slot.name] = value
self.state['belief_state']['order'].append(new_order) self.state['belief_state']['order'].append(new_order)
elif frame.act == 'inform/address': elif frame.act == 'inform/address':

View File

@ -4,8 +4,9 @@ from src.model.slot import Slot
dsm = DialogStateMonitor() dsm = DialogStateMonitor()
assert dsm.pizza_exists('capri') is True assert dsm.item_exists('pizza', 'capri') is True
assert dsm.pizza_exists('buraczana') is False 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 assert dsm.state['was_previous_order_invalid'] is False
frame1 = Frame('user', 'inform/order', [Slot('pizza', 'margarita'), Slot('sauce', 'ketchup')]) frame1 = Frame('user', 'inform/order', [Slot('pizza', 'margarita'), Slot('sauce', 'ketchup')])
@ -16,6 +17,9 @@ dsm.update(frame2)
assert dsm.get_total_cost() == 60 assert dsm.get_total_cost() == 60
frame3 = Frame('user', 'inform/order-complete', []) frame3 = Frame('user', 'inform/order-complete', [])
dsm.update(frame3) 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]['pizza'] == 'margarita'
assert dsm.state['belief_state']['order'][0]['sauce'] == 'ketchup' 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'][0] == frame1
assert dsm.state['history'][1] == frame2 assert dsm.state['history'][1] == frame2
assert dsm.state['history'][2] == frame3 assert dsm.state['history'][2] == frame3
assert dsm.state['history'][3] == frame4
assert dsm.get_current_active_stage() == 'collect_food' assert dsm.get_current_active_stage() == 'collect_food'
dsm.mark_current_stage_completed() dsm.mark_current_stage_completed()