actions.action_recommend_poi
¶
Custom actions related to point of interest recommendations.
Module Contents¶
Classes¶
Object for browsing POI-related things in database. |
|
Attributes¶
- actions.action_recommend_poi.DB_NAME = 'poi'¶
- actions.action_recommend_poi.CONFERENCE_ADDRESS = 'Kristine Bonnevies vei 22, 4021 Stavanger, Norway'¶
- actions.action_recommend_poi.MAPS¶
- class actions.action_recommend_poi.POIResults(category: Text = '', likes: List = [], dislikes: List = [])¶
Object for browsing POI-related things in database.
- Parameters
category – POI category. Defaults to “restaurant”.
likes – Liked POI tags. Defaults to [].
dislikes – Disliked POI tags. Defaults to [].
- DISLIKE_TO_LIKE_REPLACEMENT_MAP¶
- BUS_STOPS_WITHIN_WALKING_DISTANCE = ['Jernbaneveien', 'Jorenholmen', 'Kannik']¶
- LAYOVER_TO_ORIGIN_MAP¶
- SELECT_POI_BY_PID = Multiline-String¶
Show Value
""" SELECT * FROM POI WHERE pid IN ({pids}) ORDER BY {order} """
- SELECT_POI_BY_CATEGORY = Multiline-String¶
Show Value
""" SELECT * FROM POI WHERE LOWER(category) LIKE '%{category}%' ORDER BY {order} """
- SELECT_PID_BY_TAG = Multiline-String¶
Show Value
""" SELECT POI.pid FROM POI INNER JOIN POITag ON POI.pid = POITag.pid WHERE POITag.tag LIKE '%{}%' """
- SELECT_PID_BY_CATEGORY_AND_NOT_PID = Multiline-String¶
Show Value
""" SELECT pid FROM POI WHERE LOWER(category) LIKE '%{category}%' AND pid NOT IN ({pids}) """
- SELECT_TAG_BY_TAG = Multiline-String¶
Show Value
""" SELECT tag FROM POITag WHERE tag LIKE '%{}%' """
- SELECT_BUS_ROUTE_BY_DESTINATION = Multiline-String¶
Show Value
""" SELECT * FROM busRoute WHERE destination = '{}' ORDER BY duration ASC """
- initialization() None ¶
Further initialization of fields.
- swap_dislikes_with_likes() None ¶
Swaps certain disliked POI tags with more appropriate liked ones.
- remove_duplicate_tags() None ¶
Removes duplicates from liked and disliked POI tags. If the same tag is found in both dislikes and likes it will be removed from dislikes.
- get_poi_matches() List ¶
Returns a list of POIs that matches likes, dislikes or category.
- Returns
List of POIs.
- Return type
List
- get_cheap_poi_matches() List ¶
Returns a list of POIs sorted by price that matches likes, dislikes or category.
- Returns
List of POIs.
- Return type
List
- get_full_bus_route(destination: Text) Dict ¶
Gives dictionary of bus routes to reach some final bus stop.
- Parameters
destination – Name of bus top to be reached
- Returns
Dictionary of bus route dictionary objects.
- Return type
Dict
- fetch_bus_routes(destination: Text) List ¶
Fetches list of bus routes matching destination.
- Parameters
destination – Destination bus stop.
- Returns
List of route dictionary objects to provided bus stops.
- Return type
List
- fetch_pois_by_category() List ¶
Returns list of matching POIs based on category.
- Returns
List of POI dictionary objects.
- Return type
List
- fetch_pois_by_likes() List ¶
Gives list of POI objects based on likes.
- Returns
List of POI dictionary objects.
- Return type
List
- fetch_pids_by_likes() List ¶
Creates list of POIs containing all liked tags.
- Returns
List of POI IDs.
- Return type
List
- fetch_pids_by_dislikes() List ¶
Creates list of POIs containing any of the disliked tags.
- Returns
List of POI IDs.
- Return type
List
- fetch_pois_by_dislikes() List ¶
Gives list of POI objects without unwanted tags.
- Returns
List of POI dictionary objects.
- Return type
List
- fetch_pois_by_likes_and_dislikes() List ¶
Generates list of POI objects satisfying both likes and dislikes.
- Returns
List of POI dictionary objects.
- Return type
List
- fetch_proper_tags(tags: List) List ¶
Fetches list proper tag names from NLU generated ones.
- Parameters
tags – Tags extracted by NLU.
- Returns
Proper tags from database.
- Return type
List
- fetch_by_sql(sql: Text, list: List = []) List ¶
Fetches list from database based on SQL statement.
- Parameters
sql – SQL to be executed by SQLite.
list – List of arguments for SQL.
- Returns
List of items.
- Return type
List
- fetch_pois_by_pids(pids: List) List ¶
Given list of POI IDs, returns list of POI objects.
- Parameters
pids – List of POI IDs.
- Returns
List of POI dictonary objects.
- Return type
List
- get_organized_poi_list(cur: List) List ¶
Organizes SQL data into a list of POI dictionaries.
- Parameters
cur – Result from SQL query.
- Returns
List of POI dictionary objects.
- Return type
List
- get_organized_bus_route_list(cur: List) List ¶
Organizes SQL data into a list of bus route dictionaries.
- Parameters
cur – Result from SQL query.
- Returns
List of bus route dictionary objects.
- Return type
List
- class actions.action_recommend_poi.POIFunctions¶
- classmethod get_match(tracker: rasa_sdk.Tracker, is_cheap: bool = False) Dict ¶
Retrieves POI match based on slots and other preferences.
- Parameters
tracker – Class that maintains the state of a conversation.
is_cheap – Prioririzes cheap places if set to true.
- Returns
POI dictionary object.
- Return type
Dict
- classmethod get_matches_by_likes(tracker: rasa_sdk.Tracker) List ¶
Fetches all POI objects that has provided liked POI tags.
- Parameters
tracker – Class that maintains the state of a conversation.
- Returns
POI dictionary objects.
- Return type
List
- classmethod get_bus_route(tracker: rasa_sdk.Tracker) List ¶
- classmethod fetch_match(category: Text, likes: List, dislikes: List, is_cheap: bool = False) Dict ¶
Retrieves POI match from database using POI results class.
- Parameters
category – POI Category
likes – Liked POI tags.
dislikes – Disliked POI tags.
is_cheap – Prioririzes cheap places if set to true.
- Returns
POI dictionary object.
- Return type
Dict
- classmethod proper_tags_string(tags: List) Text ¶
- classmethod set_likes(tracker: rasa_sdk.Tracker) List ¶
Sets up the list of liked POI tags based on circumstances.
- Parameters
tracker – Class that maintains the state of a conversation.
- Returns
List of liked POI tags.
- Return type
List
- classmethod set_dislikes(tracker: rasa_sdk.Tracker) List ¶
Sets up the list of disliked POI tags based on circumstances.
- Parameters
tracker – Class that maintains the state of a conversation.
- Returns
List of disliked POI tags.
- Return type
List
- classmethod has_new_tags(tracker: rasa_sdk.Tracker) bool ¶
Checks if liked and disliked POI tags have changed since last recommendation.
- Parameters
tracker – Class that maintains the state of a conversation.
- Returns
True if there are new tags.
- Return type
bool
- classmethod has_new_category(tracker: rasa_sdk.Tracker) bool ¶
Checks if POI category has changed since last recommendation.
- Parameters
tracker – Class that maintains the state of a conversation.
- Returns
True if category has changed.
- Return type
bool
- classmethod has_walking_distance(tracker: rasa_sdk.Tracker) bool ¶
- classmethod is_different_list(list1: List, list2: List) bool ¶
Checks if two list contain different items.
- Parameters
list1 – First list.
list2 – Second list.
- Returns
True if they do not contain the same items.
- Return type
bool
- classmethod recommend_by_category(dispatcher: rasa_sdk.executor.CollectingDispatcher, match: Dict, response: Text) None ¶
Recommendes provided POI match with provided response utterance. Uses fields: name, category.
- Parameters
dispatcher – Class responsible for sending messages back to user.
match – POI Dictionary object.
response – The utterance being called by the dispatcher.
- classmethod recommend_by_likes(dispatcher: rasa_sdk.executor.CollectingDispatcher, match: Dict, response: Text) None ¶
Recommendes provided POI match with provided response utterance. Uses fields: name, category, likes.
- Parameters
dispatcher – Class responsible for sending messages back to user.
match – POI Dictionary object.
response – The utterance being called by the dispatcher.
- classmethod recommend_by_likes_and_dislikes(dispatcher: rasa_sdk.executor.CollectingDispatcher, match: Dict, response: Text) None ¶
Recommendes provided POI match with provided response utterance. Uses fields: name, category, likes, dislikes.
- Parameters
dispatcher – Class responsible for sending messages back to user.
match – POI Dictionary object.
response – The utterance being called by the dispatcher.
- classmethod stringify_list(list: List, seperator: Text = 'and') Text ¶
Turns list into human readable form.
- Parameters
list – List to be converted.
seperator – ‘and’, ‘or’, ‘nor’ etc.
- Returns
String with list items.
- Return type
Text
- classmethod random_first_index(idx_range: int) int ¶
Gives random value between 0 and 3 or 0 and idx_range.
- Parameters
idx_range – Maximun index allowed.
- Returns
Random index number.
- Return type
int
- classmethod generate_poi_template(poi: Dict) Dict ¶
Template object to be passed to external screen.
- Parameters
poi – POI dictionary object.
- Returns
Template dictionary object.
- Return type
Dict
- classmethod get_google_maps_img_url(poi: Dict) Text ¶
Gives URL to Google Maps static image based on POI data.
- Parameters
poi – POI entry used to generate URL.
match – POI entry being recommended.
- classmethod get_osm_iframe_url(poi: Dict) Text ¶
Gives URL to Open Street Map HTML file.
- Parameters
poi – POI entry used to generate URL.
match – POI entry being recommended.
- classmethod get_qr_code_url(url: Text) Text ¶
Gives URL to QR code generated from provided URL.
- Parameters
url – Website to generate QR code for.
- Returns
URL to QR-code image.
- Return type
Text
- class actions.action_recommend_poi.ActionRecommendPOI¶
Bases:
rasa_sdk.Action
- name() Text ¶
- run(dispatcher: rasa_sdk.executor.CollectingDispatcher, tracker: rasa_sdk.Tracker, domain: Dict[Text, Any]) List[Dict[Text, Any]] ¶
Gives top rated POI match based on provided entities.
- Parameters
dispatcher – Class responsible for sending messages back to user.
tracker – Class that maintains the state of a conversation.
domain – Dictionary containing information stored in ‘domain.yml’
- recommend_poi(dispatcher: rasa_sdk.executor.CollectingDispatcher, match: Dict) List[Dict[Text, Any]] ¶
Utters recommendation based on highest rating.
- Parameters
dispatcher – Class responsible for sending messages back to user.
match – POI dictionary object.
- class actions.action_recommend_poi.ActionRecommendCheapPOI¶
Bases:
rasa_sdk.Action
- name() Text ¶
- run(dispatcher: rasa_sdk.executor.CollectingDispatcher, tracker: rasa_sdk.Tracker, domain: Dict[Text, Any]) List[Dict[Text, Any]] ¶
Gives cheap POI match based on provided entities.
- Parameters
dispatcher – Class responsible for sending messages back to user.
tracker – Class that maintains the state of a conversation.
domain – Dictionary containing information stored in ‘domain.yml’
- recommend_poi(dispatcher: rasa_sdk.executor.CollectingDispatcher, match: Dict) None ¶
Utters recommendation based on lowest price and highest rating
- Parameters
dispatcher – Class responsible for sending messages back to user.
match – POI dictionary object.
- class actions.action_recommend_poi.ActionDoesPOIHave¶
Bases:
rasa_sdk.Action
- name() Text ¶
- run(dispatcher: rasa_sdk.executor.CollectingDispatcher, tracker: rasa_sdk.Tracker, domain: Dict[Text, Any]) List[Dict[Text, Any]] ¶
Responds to question on whether a POI has wanted POI tag.
- Parameters
dispatcher – Class responsible for sending messages back to user.
tracker – Class that maintains the state of a conversation.
domain – Dictionary containing information stored in ‘domain.yml’
- affirmative(dispatcher: rasa_sdk.executor.CollectingDispatcher, tracker: rasa_sdk.Tracker, recommended_poi: Dict) List[Dict[Text, Any]] ¶
Utters confirmation that place has POI tag.
- Parameters
dispatcher – Class responsible for sending messages back to user.
tracker – Class that maintains the state of a conversation.
recommended_poi – The POI in question.
- negative(dispatcher: rasa_sdk.executor.CollectingDispatcher, tracker: rasa_sdk.Tracker, recommended_poi: Dict, new_match: Dict) List[Dict[Text, Any]] ¶
Informs that the POI does not have the wanted POI tags. Goes on to recommend another POI that does have it.
- Parameters
dispatcher – Class responsible for sending messages back to user.
tracker – Class that maintains the state of a conversation.
recommended_poi – The POI in question.
new_match – New POI being recommended.
- no_matches_found(dispatcher: rasa_sdk.executor.CollectingDispatcher, tracker: rasa_sdk.Tracker, recommended_poi: Dict) List[Dict[Text, Any]] ¶
No POI has the user’s wanted POI tags.
- Parameters
dispatcher – Class responsible for sending messages back to user.
tracker – Class that maintains the state of a conversation.
recommended_poi – The POI in question.
- class actions.action_recommend_poi.ActionRecommendPOITransport¶
Bases:
rasa_sdk.Action
- CATEGORY_TO_UTTERANCE_MAP¶
- RECOGNIZED_MODES_OF_TRANSPORT = ['taxi', 'bus', 'walk']¶
- name() Text ¶
- run(dispatcher: rasa_sdk.executor.CollectingDispatcher, tracker: rasa_sdk.Tracker, domain: Dict[Text, Any]) List[Dict[Text, Any]] ¶
Responds to question on whether a POI has wanted POI tag.
- Parameters
dispatcher – Class responsible for sending messages back to user.
tracker – Class that maintains the state of a conversation.
domain – Dictionary containing information stored in ‘domain.yml’
- recommend_transport_to_poi(dispatcher: rasa_sdk.executor.CollectingDispatcher, tracker: rasa_sdk.Tracker, preference: Text) List[Dict[Text, Any]] ¶
Recommends transport to POI
- Parameters
dispatcher – Class responsible for sending messages back to user.
tracker – Class that maintains the state of a conversation.
preference – Transport preference.
- Returns
Events to be sent to Rasa.
- Return type
List
- recommend_transport_by_walking(dispatcher: rasa_sdk.executor.CollectingDispatcher, tracker: rasa_sdk.Tracker) None ¶
Utters walking distance to POI or recommends bus.
- Parameters
dispatcher – Class responsible for sending messages back to user.
tracker – Class that maintains the state of a conversation.
- recommend_transport_by_bus(dispatcher: rasa_sdk.executor.CollectingDispatcher, tracker: rasa_sdk.Tracker) None ¶
Generates bus route recommendation to a POI.
- Parameters
dispatcher – Class responsible for sending messages back to user.
tracker – Class that maintains the state of a conversation.
- recommend_transport_in_general(dispatcher: rasa_sdk.executor.CollectingDispatcher, tracker: rasa_sdk.Tracker, preference: Text) List[Dict[Text, Any]] ¶
Generates transport response not based on a specific POI
- Parameters
dispatcher – Class responsible for sending messages back to user.
tracker – Class that maintains the state of a conversation.
preference – Transport preference.
- Returns
Events to be sent to Rasa.
- Return type
List