Dodanie obsługi napoi w DSM
This commit is contained in:
parent
79bf27aca4
commit
2b6a8b01a6
@ -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"],
|
||||
|
@ -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':
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user