Compare commits

...

3 Commits

Author SHA1 Message Date
a850690dc9 Formatowanie 2024-06-10 00:54:09 +02:00
2b6a8b01a6 Dodanie obsługi napoi w DSM 2024-06-10 00:53:38 +02:00
79bf27aca4 Poprawka testu 2024-06-10 00:48:05 +02:00
3 changed files with 102 additions and 43 deletions

View File

@ -1,9 +1,30 @@
{
"dough": ["thick"],
"drink": ["pepsi", "cola", "water"],
"food": ["pizza"],
"meat": ["chicken", "ham", "tuna"],
"sauce": ["garlic", "1000w"],
"dough": [
"thick"
],
"drink": {
"pepsi": {
"price": 10
},
"cola": {
"price": 10
},
"water": {
"price": 5
}
},
"food": [
"pizza"
],
"meat": [
"chicken",
"ham",
"tuna"
],
"sauce": [
"garlic",
"1000w"
],
"ingredient": {
"chicken": {},
"tuna": {},
@ -14,26 +35,56 @@
"ham": {},
"pepper": {}
},
"menu": ["capri", "margarita", "hawajska", "barcelona", "tuna"],
"menu": [
"capri",
"margarita",
"hawajska",
"barcelona",
"tuna"
],
"pizza": {
"capri": {
"ingredient": ["tomato", "ham", "mushrooms", "cheese"],
"ingredient": [
"tomato",
"ham",
"mushrooms",
"cheese"
],
"price": 25
},
"margarita": {
"ingredient": ["tomato", "cheese"],
"ingredient": [
"tomato",
"cheese"
],
"price": 20
},
"hawajska": {
"ingredient": ["tomato", "pineapple", "chicken", "cheese"],
"ingredient": [
"tomato",
"pineapple",
"chicken",
"cheese"
],
"price": 30
},
"barcelona": {
"ingredient": ["tomato", "onion", "ham", "pepper", "cheese"],
"ingredient": [
"tomato",
"onion",
"ham",
"pepper",
"cheese"
],
"price": 40
},
"tuna": {
"ingredient": ["tomato", "tuna", "onion", "cheese"],
"ingredient": [
"tomato",
"tuna",
"onion",
"cheese"
],
"price": 40
}
}

View File

@ -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':

View File

@ -4,7 +4,9 @@ from src.model.slot import Slot
dsm = DialogStateMonitor()
assert dsm.pizza_exists('capri') is True
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')])
@ -15,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'
@ -22,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()
@ -42,7 +47,7 @@ assert len(dsm.state['history']) == 0
dsm.reset()
frame1 = Frame('user', 'inform/order', [Slot('pizza', 'buraczna')])
frame1 = Frame('user', 'inform/order', [Slot('pizza', 'buraczana')])
dsm.update(frame1)
assert dsm.state['was_previous_order_invalid'] is True
assert dsm.state['belief_state']['order'] == []