Skip to content

Commit

Permalink
Improvements: bkinfo_area, bkinfo_bed_type, bkinfo_price nlu; validat…
Browse files Browse the repository at this point in the history
…ing revised_bkinfo; add mores tests
  • Loading branch information
sysang committed Aug 21, 2022
1 parent 3f3990b commit 386a4b4
Show file tree
Hide file tree
Showing 17 changed files with 402 additions and 108 deletions.
80 changes: 15 additions & 65 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,71 +40,21 @@ test:

testall:
-rm -f botserver-app/tests/reports/current/*
make query_hotel_room_01_schema_test model=$(M) endpoint=$(endpoint)
make query_hotel_room_02_sorting_test model=$(M) endpoint=$(endpoint)
make query_hotel_room_03_chitchat_revisebkinfo_test model=$(M) endpoint=$(endpoint)
make query_hotel_room_04_revise_invalid_bkinfo_test model=$(M) endpoint=$(endpoint)
make query_hotel_room_05_donecollecting_revisebkinfo_test model=$(M) endpoint=$(endpoint)
make query_hotel_room_06_jumpin_information_collecting_test model=$(M) endpoint=$(endpoint)
make query_hotel_room_07_chitchat_faq_test model=$(M) endpoint=$(endpoint)
make query_hotel_room_08_chitchat_smalltalk_test model=$(M) endpoint=$(endpoint)
make query_hotel_room_09_chitchat_outofscope_test model=$(M) endpoint=$(endpoint)
make query_hotel_room_10_chitchat_nlufallback_test model=$(M) endpoint=$(endpoint)
make query_hotel_room_11_terminate_booking_test model=$(M) endpoint=$(endpoint)
make query_hotel_room_12_execution_rejectedof_bkinfo_form_test model=$(M) endpoint=$(endpoint)
make query_hotel_room_13_bkinfo_area_nlu_test model=$(M) endpoint=$(endpoint)

query_hotel_room_01_schema_test:
export testfile=query_hotel_room_01_schema; \
make test testfile=$$testfile model=$(M)

query_hotel_room_02_sorting_test:
export testfile=query_hotel_room_02_sorting; \
make test testfile=$$testfile model=$(M)

query_hotel_room_03_chitchat_revisebkinfo_test:
export testfile=query_hotel_room_03_chitchat_revisebkinfo; \
make test testfile=$$testfile model=$(M)

query_hotel_room_04_revise_invalid_bkinfo_test:
export testfile=query_hotel_room_04_revise_invalid_bkinfo; \
make test testfile=$$testfile model=$(M)

query_hotel_room_05_donecollecting_revisebkinfo_test:
export testfile=query_hotel_room_05_donecollecting_revisebkinfo; \
make test testfile=$$testfile model=$(M)

query_hotel_room_06_jumpin_information_collecting_test:
export testfile=query_hotel_room_06_jumpin_information_collecting; \
make test testfile=$$testfile model=$(M)

query_hotel_room_07_chitchat_faq_test:
export testfile=query_hotel_room_07_chitchat_faq; \
make test testfile=$$testfile model=$(M)

query_hotel_room_08_chitchat_smalltalk_test:
export testfile=query_hotel_room_08_chitchat_smalltalk; \
make test testfile=$$testfile model=$(M)

query_hotel_room_09_chitchat_outofscope_test:
export testfile=query_hotel_room_09_chitchat_outofscope; \
make test testfile=$$testfile model=$(M)

query_hotel_room_10_chitchat_nlufallback_test:
export testfile=query_hotel_room_10_chitchat_nlufallback; \
make test testfile=$$testfile model=$(M)

query_hotel_room_11_terminate_booking_test:
export testfile=query_hotel_room_11_terminate_booking; \
make test testfile=$$testfile model=$(M)

query_hotel_room_12_execution_rejectedof_bkinfo_form_test:
export testfile=query_hotel_room_12_execution_rejectedof_bkinfo_form; \
make test testfile=$$testfile model=$(M)

query_hotel_room_13_bkinfo_area_nlu_test:
export testfile=query_hotel_room_13_bkinfo_area_nlu; \
make test testfile=$$testfile model=$(M)
make test testfile=query_hotel_room_01_schema model=$(M) endpoint=$(endpoint)
make test testfile=query_hotel_room_02_sorting model=$(M) endpoint=$(endpoint)
make test testfile=query_hotel_room_03_chitchat_revisebkinfo model=$(M) endpoint=$(endpoint)
make test testfile=query_hotel_room_04_revise_invalid_bkinfo model=$(M) endpoint=$(endpoint)
make test testfile=query_hotel_room_05_donecollecting_revisebkinfo model=$(M) endpoint=$(endpoint)
make test testfile=query_hotel_room_06_jumpin_information_collecting model=$(M) endpoint=$(endpoint)
make test testfile=query_hotel_room_07_chitchat_faq model=$(M) endpoint=$(endpoint)
make test testfile=query_hotel_room_08_chitchat_smalltalk model=$(M) endpoint=$(endpoint)
make test testfile=query_hotel_room_09_chitchat_outofscope model=$(M) endpoint=$(endpoint)
make test testfile=query_hotel_room_10_chitchat_nlufallback model=$(M) endpoint=$(endpoint)
make test testfile=query_hotel_room_11_terminate_booking model=$(M) endpoint=$(endpoint)
make test testfile=query_hotel_room_12_execution_rejectedof_bkinfo_form model=$(M) endpoint=$(endpoint)
make test testfile=query_hotel_room_13_bkinfo_area_nlu model=$(M) endpoint=$(endpoint)
make test testfile=query_hotel_room_14_bkinfo_price_nlu model=$(M) endpoint=$(endpoint)
make test testfile=query_hotel_room_15_bkinfo_bed_type model=$(M) endpoint=$(endpoint)

copyaddons:
docker cp botserver-app/addons rasachatbot-rasa-production-1:/app
Expand Down
54 changes: 42 additions & 12 deletions botserver-action/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,30 +659,60 @@ def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[T
search_result_flag = slots.get('search_result_flag')
additional = {}

def apply_change(slot_name, slot_name_revised, slot_value_revised):
response = f'utter_revised_{slot_name}'
dispatcher.utter_message(response=response)

events.append(SlotSet(slot_name, slot_value_revised))
events.append(SlotSet(slot_name_revised, None))
additional[slot_name_revised] = None


"""
Results:
- reflex the changes to bkinfo
- reset bkinfo_district, bkinfo_region, bkinfo_country if bkinfo_area is in revision
- set bkinfo_district, bkinfo_region, bkinfo_country if bkinfo_area is in revision
- reset the revised bkinfo
- inform user
"""
for slot_name in schema:
slot_name_revised = f"{slot_name}_revised"
slot_value_revised = slots.get(slot_name_revised, None)
slot_value_current = slots.get(slot_name, None)
if slot_value_revised and slot_value_revised != slot_value_current:
response = f'utter_revised_{slot_name}'
dispatcher.utter_message(response=response)

events.append(SlotSet(slot_name, slot_value_revised))
if slot_name == 'bkinfo_area':
bkinfo_area_type = slots.get('bkinfo_area_type', None)
bkinfo_country = slots.get('bkinfo_country', None)
bkinfo_region = slots.get('bkinfo_region', None)
bkinfo_district = slots.get('bkinfo_district', None)
bkinfo_area_type_revised = slots.get('bkinfo_area_type_revised', None)
bkinfo_country_revised = slots.get('bkinfo_country_revised', None)
bkinfo_region_revised = slots.get('bkinfo_region_revised', None)
bkinfo_district_revised = slots.get('bkinfo_district_revised', None)

if (slot_value_revised and
(
slot_value_revised != slot_value_current
or (bkinfo_area_type_revised and bkinfo_area_type_revised != bkinfo_area_type)
or (bkinfo_country_revised and bkinfo_country_revised != bkinfo_country)
or (bkinfo_region_revised and bkinfo_region_revised != bkinfo_region)
or (bkinfo_district_revised and bkinfo_district_revised != bkinfo_district)
)):
apply_change(slot_name=slot_name, slot_name_revised=slot_name_revised, slot_value_revised=slot_value_revised)

events.append(SlotSet('bkinfo_area_type', bkinfo_area_type_revised))
events.append(SlotSet('bkinfo_country', bkinfo_country_revised))
events.append(SlotSet('bkinfo_region', bkinfo_region_revised))
events.append(SlotSet('bkinfo_district', bkinfo_district_revised))

events.append(SlotSet('bkinfo_area_type_revised', None))
events.append(SlotSet('bkinfo_country_revised', None))
events.append(SlotSet('bkinfo_region_revised', None))
events.append(SlotSet('bkinfo_district_revised', None))

events.append(SlotSet(slot_name_revised, None))
additional[slot_name_revised] = None

if slot_name == 'bkinfo_area':
events.append(SlotSet('bkinfo_district', None))
events.append(SlotSet('bkinfo_region', None))
events.append(SlotSet('bkinfo_country', None))
else:
if slot_value_revised and slot_value_revised != slot_value_current:
apply_change(slot_name=slot_name, slot_name_revised=slot_name_revised, slot_value_revised=slot_value_revised)

if search_result_flag == 'available':
events.append(SlotSet('search_result_flag', 'updating'))
Expand Down
9 changes: 8 additions & 1 deletion botserver-action/actions_validate_info_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .utils import calc_time_distance_in_days
from .utils import SUSPICIOUS_CHECKIN_DISTANCE
from .utils import DictUpdatingMemmQueue
from .utils import parse_bkinfo_bed_type

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -59,7 +60,7 @@ def validate_bkinfo_area(
)
if not destination:
dispatcher.utter_message(response='utter_ask_valid_bkinfo_area')
return {slot_name: None}
return {slot_name: None, 'bkinfo_bed_type': None, 'bkinfo_district': None, 'bkinfo_region': None, 'bkinfo_country': None}

if self.is_new(tracker, slot_name, slot_value):
dest_label = destination.get('label', None)
Expand Down Expand Up @@ -146,6 +147,12 @@ def validate_bkinfo_bed_type(

slot_name = 'bkinfo_bed_type'

result = parse_bkinfo_bed_type(expression=slot_value)

if result.if_error('failed'):
dispatcher.utter_message(response='utter_ask_rephrase_bed_type')
return {slot_name: None}

return {slot_name: slot_value}

def validate_bkinfo_price(
Expand Down
34 changes: 23 additions & 11 deletions botserver-action/actions_validate_predefined_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .utils import calc_time_distance_in_days
from .utils import SUSPICIOUS_CHECKIN_DISTANCE
from .utils import DictUpdatingMemmQueue
from .utils import parse_bkinfo_bed_type


logger = logging.getLogger(__name__)
Expand All @@ -32,6 +33,11 @@ def old_slot_value(self, tracker, slot_name):
return DictUpdatingMemmQueue(data=old_slot).retrieve(key=slot_name)

def if_changed_by_botacts_utter_revised_bkinfo(self, tracker):
"""
hacking, to work around problem gave by validating action
it recovers old value from being updated by SlotSet event
(it prevents SlotSet event take effect)
"""
return tracker.latest_action_name == 'botacts_utter_revised_bkinfo'

def validate_bkinfo_area_revised(
Expand All @@ -42,20 +48,18 @@ def validate_bkinfo_area_revised(
domain: DomainDict,) -> Dict[Text, Any]:

slot_name = 'bkinfo_area_revised'

slots = tracker.slots

if self.if_changed_by_botacts_utter_revised_bkinfo(tracker):
return {slot_name: None}

destination = choose_location(
bkinfo_area=slot_value, bkinfo_area_type=slots.get('bkinfo_area_type'), bkinfo_district=slots.get('bkinfo_district'),
bkinfo_region=slots.get('bkinfo_region'), bkinfo_country=slots.get('bkinfo_country'),
bkinfo_area=slot_value, bkinfo_area_type=slots.get('bkinfo_area_type_revised'), bkinfo_district=slots.get('bkinfo_district_revised'),
bkinfo_region=slots.get('bkinfo_region_revised'), bkinfo_country=slots.get('bkinfo_country_revised'),
)
if not destination:
dispatcher.utter_message(response='utter_ask_valid_bkinfo_area')
return {slot_name: None}

# hacking, to work around problem gave by validating action
# it recovers old value from being update by SlotSet event
if self.if_changed_by_botacts_utter_revised_bkinfo(tracker):
return {slot_name: None}
return {slot_name: None, 'bkinfo_bed_type_revised': None, 'bkinfo_district_revised': None, 'bkinfo_region_revised': None, 'bkinfo_country_revised': None}

return {slot_name: slot_value}

Expand All @@ -79,7 +83,7 @@ def validate_bkinfo_checkin_time_revised(

if result.if_error('invalid_checkin_time'):
dispatcher.utter_message(response='utter_ask_valid_bkinfo_checkin_time')
return {slot_name: self.old_slot_value(tracker, slot_name)}
return {slot_name: None}

return {slot_name: slot_value}

Expand All @@ -99,7 +103,7 @@ def validate_bkinfo_duration_revised(

if result.if_error('failed'):
dispatcher.utter_message(response='utter_ask_rephrase_duration')
return {slot_name: self.old_slot_value(tracker, slot_name)}
return {slot_name: None}

if result.if_error('invalid_bkinfo_duration'):
dispatcher.utter_message(response='utter_ask_valid_bkinfo_duration')
Expand All @@ -124,6 +128,14 @@ def validate_bkinfo_bed_type_revised(
if self.if_changed_by_botacts_utter_revised_bkinfo(tracker):
return {slot_name: None}

result = parse_bkinfo_bed_type(expression=slot_value)

logger.info('[DEV] validate_bkinfo_price_revised: %s', result)
if result.if_error('failed'):
logger.info('[DEV] validate_bkinfo_price_revised -> failed')
dispatcher.utter_message(response='utter_ask_rephrase_bed_type')
return {slot_name: None}

return {slot_name: slot_value}

def validate_bkinfo_price_revised(
Expand Down
62 changes: 61 additions & 1 deletion botserver-action/duckling_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def parse_bkinfo_duration(expression):
dim_time = DIM_TIME
units = [UNIT_DAY, UNIT_WEEK]

expression = expression.replace('night', 'day').replace('nights', 'days')

result = duckling_parse(expression=expression, dims=dim_duration)
parsed = None
parsed_dim = None
Expand Down Expand Up @@ -288,12 +290,26 @@ def __test__parse_bkinfo_duration():
print(result)
assert result.error == None

expression = '2 night'
print('\n[TEST] expression: ', expression)
result = parse_bkinfo_duration(expression)
print(result)
assert result.error == None and result.value == 2 and result.unit == 'day'

expression = '3 nights'
print('\n[TEST] expression: ', expression)
result = parse_bkinfo_duration(expression)
print(result)
assert result.error == None and result.value == 3 and result.unit == 'day'

expression = '2 weeks'
print('\n[TEST] expression: ', expression)
result = parse_bkinfo_duration(expression)
print(result)
assert result.error == None

print('\nAll done.')


def __test__parse_bkinfo_price():

Expand All @@ -319,7 +335,51 @@ def __test__parse_bkinfo_price():
print('\n[TEST] expression: ', expression)
result = parse_bkinfo_price(expression)
print(result)
assert result.error == None
assert result.error == None and result.value == 100 and result.unit == 'EUR'

expression = '100eur'
print('\n[TEST] expression: ', expression)
result = parse_bkinfo_price(expression)
print(result)
assert result.error == None and result.value == 100 and result.unit == 'EUR'

expression = '2001 krw'
print('\n[TEST] expression: ', expression)
result = parse_bkinfo_price(expression)
print(result)
assert result.error == None and result.value == 2001 and result.unit == 'KRW'

expression = '2001krw'
print('\n[TEST] expression: ', expression)
result = parse_bkinfo_price(expression)
print(result)
assert result.error == None and result.value == 2001 and result.unit == 'KRW'

expression = '5000 jpy/night'
print('\n[TEST] expression: ', expression)
result = parse_bkinfo_price(expression)
print(result)
assert result.error == None and result.value == 5000 and result.unit == 'JPY'

expression = '5000jpy/night'
print('\n[TEST] expression: ', expression)
result = parse_bkinfo_price(expression)
print(result)
assert result.error == None and result.value == 5000 and result.unit == 'JPY'

expression = '5000 jpy per night'
print('\n[TEST] expression: ', expression)
result = parse_bkinfo_price(expression)
print(result)
assert result.error == None and result.value == 5000 and result.unit == 'JPY'

expression = '5000jpy per night'
print('\n[TEST] expression: ', expression)
result = parse_bkinfo_price(expression)
print(result)
assert result.error == None and result.value == 5000 and result.unit == 'JPY'

print('\nAll done.')


"""
Expand Down
5 changes: 5 additions & 0 deletions botserver-action/fsm_botmemo_booking_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
parse_bkinfo_duration,
parse_bkinfo_price,
)
from .utils import parse_bkinfo_bed_type

from .service import query_available_rooms, query_room_by_id
from .data_struture import BookingInfo
Expand Down Expand Up @@ -80,6 +81,10 @@ def validate_bkinfo_duration(self, value):
result = parse_bkinfo_duration(expression=value)
return result.is_valid()

def validate_bkinfo_bed_type(self, value):
result = parse_bkinfo_bed_type(expression=value)
return result.is_valid()

def validate_bkinfo_price(self, value):
result = parse_bkinfo_price(expression=value)
return result.is_valid()
Expand Down
Loading

0 comments on commit 386a4b4

Please sign in to comment.