Zmiana staga po dodaniu określonego wpisu do DSM
This commit is contained in:
parent
dfed26e955
commit
5f128e7e88
@ -1,4 +1,4 @@
|
|||||||
from model.frame import Frame
|
from src.model.frame import Frame
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@ -62,17 +62,19 @@ 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' or slot.name == 'drink':
|
if (slot.name == 'pizza' and self.get_current_active_stage() == 'collect_food') or (slot.name == 'drink' and self.get_current_active_stage() == 'collect_drinks'):
|
||||||
if self.item_exists(slot.name, 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'][slot.name][value]['price']
|
self.state['total_cost'] += self.state['constants'][slot.name][value]['price']
|
||||||
|
self.mark_current_stage_completed()
|
||||||
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' and self.get_current_active_stage() == 'collect_address':
|
||||||
for slot in frame.slots:
|
for slot in frame.slots:
|
||||||
self.state['belief_state']['address'][slot.name] = normalize(slot.value)
|
self.state['belief_state']['address'][slot.name] = normalize(slot.value)
|
||||||
|
self.mark_current_stage_completed()
|
||||||
elif frame.act == 'inform/phone':
|
elif frame.act == 'inform/phone':
|
||||||
for slot in frame.slots:
|
for slot in frame.slots:
|
||||||
self.state['belief_state']['phone'][slot.name] = normalize(slot.value)
|
self.state['belief_state']['phone'][slot.name] = normalize(slot.value)
|
||||||
|
@ -9,17 +9,21 @@ assert dsm.item_exists('pizza', 'buraczana') is False
|
|||||||
assert dsm.item_exists('drink', 'cola') is True
|
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
|
||||||
|
|
||||||
|
assert dsm.get_current_active_stage() == 'collect_food'
|
||||||
frame1 = Frame('user', 'inform/order', [Slot('pizza', 'margarita'), Slot('sauce', 'ketchup')])
|
frame1 = Frame('user', 'inform/order', [Slot('pizza', 'margarita'), Slot('sauce', 'ketchup')])
|
||||||
dsm.update(frame1)
|
dsm.update(frame1)
|
||||||
|
assert dsm.get_current_active_stage() == 'collect_drinks'
|
||||||
assert dsm.get_total_cost() == 20
|
assert dsm.get_total_cost() == 20
|
||||||
frame2 = Frame('user', 'inform/order', [Slot('pizza', 'tuna')])
|
frame2 = Frame('user', 'inform/order', [Slot('pizza', 'tuna')])
|
||||||
dsm.update(frame2)
|
dsm.update(frame2)
|
||||||
assert dsm.get_total_cost() == 60
|
assert dsm.get_current_active_stage() == 'collect_drinks'
|
||||||
|
assert dsm.get_total_cost() == 20 # Pizza is not added, as previous stage is closed already
|
||||||
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')])
|
frame4 = Frame('user', 'inform/order', [Slot('drink', 'cola')])
|
||||||
dsm.update(frame4)
|
dsm.update(frame4)
|
||||||
assert dsm.get_total_cost() == 70
|
assert dsm.get_current_active_stage() == 'collect_address'
|
||||||
|
assert dsm.get_total_cost() == 30
|
||||||
|
|
||||||
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'
|
||||||
@ -29,14 +33,6 @@ 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.state['history'][3] == frame4
|
||||||
|
|
||||||
assert dsm.get_current_active_stage() == 'collect_food'
|
|
||||||
dsm.mark_current_stage_completed()
|
|
||||||
assert dsm.get_current_active_stage() == 'collect_drinks'
|
|
||||||
dsm.mark_current_stage_completed()
|
|
||||||
assert dsm.get_current_active_stage() == 'collect_address'
|
|
||||||
dsm.mark_current_stage_completed()
|
|
||||||
assert dsm.get_current_active_stage() is None
|
|
||||||
|
|
||||||
dsm.reset()
|
dsm.reset()
|
||||||
|
|
||||||
assert dsm.get_total_cost() == 0
|
assert dsm.get_total_cost() == 0
|
||||||
|
Loading…
Reference in New Issue
Block a user