alex.applications.PublicTransportInfoEN package¶
Subpackages¶
- alex.applications.PublicTransportInfoEN.data package
- Subpackages
- alex.applications.PublicTransportInfoEN.data.preprocessing package
- Submodules
- alex.applications.PublicTransportInfoEN.data.preprocessing.compatibility_script_manual module
- alex.applications.PublicTransportInfoEN.data.preprocessing.mta_to_csv module
- alex.applications.PublicTransportInfoEN.data.preprocessing.stops_to_streets_experiment module
- alex.applications.PublicTransportInfoEN.data.preprocessing.us_cities_to_csv module
- Module contents
- alex.applications.PublicTransportInfoEN.data.preprocessing package
- Submodules
- alex.applications.PublicTransportInfoEN.data.autopath module
- alex.applications.PublicTransportInfoEN.data.database module
- alex.applications.PublicTransportInfoEN.data.download_data module
- alex.applications.PublicTransportInfoEN.data.expand_boroughs_script module
- alex.applications.PublicTransportInfoEN.data.expand_cities_script module
- alex.applications.PublicTransportInfoEN.data.expand_states_script module
- alex.applications.PublicTransportInfoEN.data.expand_stops_script module
- alex.applications.PublicTransportInfoEN.data.expand_streets_script module
- alex.applications.PublicTransportInfoEN.data.ontology module
- Module contents
- Subpackages
- alex.applications.PublicTransportInfoEN.slu package
- Submodules
- alex.applications.PublicTransportInfoEN.slu.add_to_bootstrap module
- alex.applications.PublicTransportInfoEN.slu.autopath module
- alex.applications.PublicTransportInfoEN.slu.consolidate_keyfiles module
- alex.applications.PublicTransportInfoEN.slu.gen_bootstrap module
- alex.applications.PublicTransportInfoEN.slu.prepare_data module
- alex.applications.PublicTransportInfoEN.slu.query_google module
- alex.applications.PublicTransportInfoEN.slu.test_bootstrap module
- Module contents
Submodules¶
alex.applications.PublicTransportInfoEN.autopath module¶
self cloning, automatic path configuration
copy this into any subdirectory of pypy from which scripts need to be run, typically all of the test subdirs. The idea is that any such script simply issues
import autopath
and this will make sure that the parent directory containing “pypy” is in sys.path.
If you modify the master “autopath.py” version (in pypy/tool/autopath.py) you can directly run it which will copy itself on all autopath.py files it finds under the pypy root directory.
This module always provides these attributes:
pypydir pypy root directory path this_dir directory where this autopath.py resides
alex.applications.PublicTransportInfoEN.directions module¶
-
class
alex.applications.PublicTransportInfoEN.directions.
Directions
(**kwargs)[source]¶ Bases:
alex.applications.PublicTransportInfoEN.directions.Travel
Ancestor class for transit directions, consisting of several routes.
-
class
alex.applications.PublicTransportInfoEN.directions.
DirectionsFinder
[source]¶ Bases:
object
Abstract ancestor for transit direction finders.
-
class
alex.applications.PublicTransportInfoEN.directions.
GoogleDirections
(input_json={}, **kwargs)[source]¶ Bases:
alex.applications.PublicTransportInfoEN.directions.Directions
Traffic directions obtained from Google Maps API.
-
class
alex.applications.PublicTransportInfoEN.directions.
GoogleDirectionsFinder
(cfg)[source]¶ Bases:
alex.applications.PublicTransportInfoEN.directions.DirectionsFinder
,alex.tools.apirequest.APIRequest
Transit direction finder using the Google Maps query engine.
-
class
alex.applications.PublicTransportInfoEN.directions.
GoogleRoute
(input_json)[source]¶ Bases:
alex.applications.PublicTransportInfoEN.directions.Route
-
class
alex.applications.PublicTransportInfoEN.directions.
GoogleRouteLeg
(input_json)[source]¶ Bases:
alex.applications.PublicTransportInfoEN.directions.RouteLeg
-
class
alex.applications.PublicTransportInfoEN.directions.
GoogleRouteLegStep
(input_json)[source]¶ Bases:
alex.applications.PublicTransportInfoEN.directions.RouteStep
-
VEHICLE_TYPE_MAPPING
= {u'FUNICULAR': u'cable_car', u'COMMUTER_TRAIN': u'train', u'INTERCITY_BUS': u'bus', u'METRO_RAIL': u'tram', u'BUS': u'bus', u'SHARE_TAXI': u'bus', u'RAIL': u'train', u'Long distance train': u'train', u'CABLE_CAR': u'cable_car', u'Train': u'train', u'TRAM': u'tram', u'HEAVY_RAIL': u'train', u'OTHER': u'dontcare', u'SUBWAY': u'subway', u'TROLLEYBUS': u'bus', u'FERRY': u'ferry', u'GONDOLA_LIFT': u'ferry', u'MONORAIL': u'monorail', u'HIGH_SPEED_TRAIN': u'train'}¶
-
-
class
alex.applications.PublicTransportInfoEN.directions.
Route
[source]¶ Bases:
object
Ancestor class for one transit direction route.
-
class
alex.applications.PublicTransportInfoEN.directions.
RouteLeg
[source]¶ Bases:
object
One traffic directions leg.
-
class
alex.applications.PublicTransportInfoEN.directions.
RouteStep
(travel_mode)[source]¶ Bases:
object
One transit directions step – walking or using public transport. Data members: travel_mode – TRANSIT / WALKING
- For TRANSIT steps:
departure_stop departure_time arrival_stop arrival_time headsign – direction of the transit line vehicle – type of the transit vehicle (tram, subway, bus) line_name – name or number of the transit line
- For WALKING steps:
duration – estimated walking duration (seconds)
-
MODE_TRANSIT
= u'TRANSIT'¶
-
MODE_WALKING
= u'WALKING'¶
alex.applications.PublicTransportInfoEN.exceptions module¶
-
exception
alex.applications.PublicTransportInfoEN.exceptions.
PTIENHDCPolicyException
[source]¶ Bases:
alex.components.dm.exceptions.DialoguePolicyException
alex.applications.PublicTransportInfoEN.hdc_policy module¶
-
class
alex.applications.PublicTransportInfoEN.hdc_policy.
PTIENHDCPolicy
(cfg, ontology)[source]¶ Bases:
alex.components.dm.base.DialoguePolicy
The handcrafted policy for the PTI-EN system.
-
DEFAULT_AMPM_TIMES
= {u'night': u'00:00', u'evening': u'18:00', u'pm': u'15:00', u'am': u'10:00', u'morning': u'06:00'}¶
-
DESTIN
= u'FINAL_DEST'¶
-
ORIGIN
= u'ORIGIN'¶
-
backoff_action
(ds)[source]¶ Generate a random backoff dialogue act in case we don’t know what to do.
Parameters: ds – The current dialogue state Return type: DialogueAct
-
check_city_state_conflict
(in_city, in_state)[source]¶ Check for conflicts in the given city and state. Return an apology() DA if the state and city is incompatible.
Parameters: - in_city – city slot value
- in_state – state slot value
Return type: Returns: apology dialogue act in case of conflict, or None
-
check_directions_conflict
(wp)[source]¶ Check for conflicts in the given waypoints. Return an apology() DA if the origin and the destination are the same, or if a city is not compatible with the corresponding stop.
Parameters: wp – wayponts of the user’s connection query Return type: DialogueAct Returns: apology dialogue act in case of conflict, or None
-
confirm_info
(tobe_confirmed_slots)[source]¶ Return a DA containing confirming only one slot from the slot to be confirmed. Confirm the slot with the most probable value among all slots to be confirmed.
Parameters: tobe_confirmed_slots – A dictionary with keys for all slots that should be confirmed, along with their values Return type: DialogueAct
-
filter_iconfirms
(da)[source]¶ Filter implicit confirms if the same information is uttered in an inform dialogue act item. Also filter implicit confirms for stop names equaling city names. Also check if the stop and city names are equal!
Parameters: da – unfiltered dialogue act Returns: filtered dialogue act
-
gather_connection_info
(ds, accepted_slots)[source]¶ Return a DA requesting further information needed to search for traffic directions and a dictionary containing the known information. Infers city names based on stop names and vice versa.
If the request DA is empty, the search for directions may be commenced immediately.
Parameters: ds – The current dialogue state Return type: DialogueAct, dict
-
gather_time_info
(ds, accepted_slots)[source]¶ Handles if in_city specified it handles properly filled in_state slot. If needed, a Request DA is formed for missing in_state slot.
Returns Reqest DA and in_state If the request DA is empty, the search for current_time may be commenced immediately.
Parameters: ds – The current dialogue state,
-
gather_weather_info
(ds, accepted_slots)[source]¶ Handles in_city and in_state to be properly filled. If needed, a Request DA is formed for missing slots to be filled.
Returns Reqest DA and WeatherPoint - information about the place If the request DA is empty, the search for weather may be commenced immediately.
Parameters: ds – The current dialogue state,
-
get_accepted_mpv
(ds, slot_name, accepted_slots)[source]¶ Return a slot’s ‘mpv()’ (most probable value) if the slot is accepted, and return ‘none’ otherwise. Also, convert a mpv of ‘*’ to ‘none’ since we don’t know how to interpret it.
Parameters: - ds – Dialogue state
- slot_name – The name of the slot to query
- accepted_slots – The currently accepted slots of the dialogue state
Return type: string
-
get_an_alternative
(ds)[source]¶ Return an alternative route, if there is one, or ask for origin stop if there has been no route searching so far.
Parameters: ds – The current dialogue state Return type: DialogueAct
-
get_confirmed_info
(confirmed_slots, ds, accepted_slots)[source]¶ Return a DA containing information about all slots being confirmed by the user (confirm/deny).
Update the current dialogue state regarding the information provided.
WARNING This confirms only against values in the dialogue state, however, it should (also in some cases) confirm against the results obtained from database, e.g. departure_time slot.
Parameters: - ds – The current dialogue state
- confirmed_slots – A dictionary with keys for all slots being confirmed, along with their values
Return type:
-
get_connection_res_da
(ds, ludait, slots_being_requested, slots_being_confirmed, accepted_slots, changed_slots, state_changed)[source]¶ Handle the public transport connection dialogue topic.
Parameters: ds – The current dialogue state Return type: DialogueAct
-
get_current_time_res_da
(ds, accepted_slots, state_changed)[source]¶ Generates a dialogue act informing about the current time. :rtype: DialogueAct
-
get_da
(dialogue_state)[source]¶ - The main policy decisions are made here. For each action, some set of conditions must be met. These
- conditions depends on the action.
Parameters: dialogue_state – the belief state provided by the tracker Returns: a dialogue act - the system action
-
get_default_stop_for_city
(city)[source]¶ Return a `default’ stop based on the city name (main bus/train station).
Parameters: city – city name (unicode) Return type: unicode
-
get_directions
(ds, route_type=u'true', check_conflict=False)[source]¶ Retrieve Google directions, save them to dialogue state and return corresponding DAs.
Responsible for the interpretation of AM/PM time expressions.
Parameters: - ds – The current dialogue state
- route_type – a label for the found route (to be passed on to
say_directions()
) - check_conflict – If true, will check if the origin and destination stops are different and issue a warning DA if not.
Return type:
-
get_iconfirm_info
(changed_slots)[source]¶ Return a DA containing all needed implicit confirms.
Implicitly confirm all slots provided but not yet confirmed.
This include also slots changed during the conversation.
Parameters: changed_slots – A dictionary with keys for all slots that have not been implicitly confirmed, along with their values Return type: DialogueAct
-
get_requested_alternative
(ds, slots_being_requested, accepted_slots)[source]¶ Return the requested route (or inform about not finding one).
Parameters: ds – The current dialogue state Return type: DialogueAct
-
get_requested_info
(requested_slots, ds, accepted_slots)[source]¶ Return a DA containing information about all requested slots.
Parameters: - ds – The current dialogue state
- requested_slots – A dictionary with keys for all requested slots and the correct return values.
Return type:
-
get_weather
(ds, ref_point=None)[source]¶ Retrieve weather information according to the current dialogue state. Infers state names based on city names and vice versa.
Parameters: ds – The current dialogue state Return type: DialogueAct
-
get_weather_res_da
(ds, ludait, slots_being_requested, slots_being_confirmed, accepted_slots, changed_slots, state_changed)[source]¶ Handle the dialogue about weather.
Parameters: - ds – The current dialogue state
- slots_being_requested – The slots currently requested by the user
Return type:
-
interpret_time
(time_abs, time_ampm, time_rel, date_rel, lta_time)[source]¶ Interpret time, given current dialogue state most probable values for relative and absolute time and date, plus the corresponding last-talked-about value.
Returns: the inferred time value + flag indicating the inferred time type (‘abs’ or ‘rel’) Return type: tuple(datetime, string)
-
process_directions_for_output
(dialogue_state, route_type)[source]¶ Return DAs for the directions in the current dialogue state. If the directions are not valid (nothing found), delete their object from the dialogue state and return apology DAs.
Parameters: - dialogue_state – the current dialogue state
- route_type – the route type requested by the user (“last”, “next” etc.)
Return type:
-
req_arrival_time
(dialogue_state)[source]¶ Return a DA informing about the arrival time the destination stop of the last recommended connection.
-
req_arrival_time_rel
(dialogue_state)[source]¶ Return a DA informing about the relative arrival time the destination stop of the last recommended connection.
-
req_departure_time
(dialogue_state)[source]¶ Generates a dialogue act informing about the departure time from the origin stop of the last recommended connection.
:rtype : DialogueAct
-
req_departure_time_rel
(dialogue_state)[source]¶ Return a DA informing the user about the relative time until the last recommended connection departs.
-
req_distance
(dialogue_state)[source]¶ Return a DA informing the user about the distance and number of stops in the last recommended connection.
-
req_duration
(dialogue_state)[source]¶ Return a DA informing about journey time to the destination stop of the last recommended connection.
-
req_from_stop
(ds)[source]¶ Generates a dialogue act informing about the origin stop of the last recommended connection.
- TODO: this gives too much of information. Maybe it would be worth to split this into more dialogue acts
- and let user ask for all individual pieces of information. The good thing would be that it would lead to longer dialogues.
:rtype : DialogueAct
-
req_num_transfers
(dialogue_state)[source]¶ Return a DA informing the user about the number of transfers in the last recommended connection.
-
req_time_transfers
(dialogue_state)[source]¶ Return a DA informing the user about transfer places and time needed for the trasfer in the last recommended connection.
-
req_to_stop
(ds)[source]¶ Return a DA informing about the destination stop of the last recommended connection.
-
reset_on_change
(ds, changed_slots)[source]¶ Reset slots which depends on changed slots.
Parameters: - ds – dialogue state
- changed_slots – slots changed in the last turn
-
select_info
(tobe_selected_slots)[source]¶ Return a DA containing select act for two most probable values of only one slot from the slot to be used for select DAI.
Parameters: tobe_selected_slots – A dictionary with keys for all slots which the two most probable values should be selected Return type: DialogueAct
-
alex.applications.PublicTransportInfoEN.hdc_slu module¶
-
class
alex.applications.PublicTransportInfoEN.hdc_slu.
DAIBuilder
(utterance, abutterance_lenghts=None)[source]¶ Bases:
object
Builds DialogueActItems with proper alignment to corresponding utterance words. When words are successfully matched using DAIBuilder, their indices in the utterance are added to alignment set of the DAI as a side-effect.
-
build
(act_type=None, slot=None, value=None)[source]¶ Produce DialogueActItem based on arguments and alignment from this DAIBuilder state.
-
ending_phrases_in
(phrases)[source]¶ Returns True if the utterance ends with one of the phrases
Parameters: phrases – a list of phrases to search for Return type: bool
-
-
class
alex.applications.PublicTransportInfoEN.hdc_slu.
PTIENHDCSLU
(preprocessing, cfg)[source]¶ Bases:
alex.components.slu.base.SLUInterface
-
abstract_utterance
(utterance)[source]¶ Return a list of possible abstractions of the utterance.
Parameters: utterance – an Utterance instance Returns: a list of abstracted utterance, form, value, category label tuples
-
handle_false_abstractions
(abutterance)[source]¶ Revert false positive alarms of abstraction
Parameters: abutterance – the abstracted utterance Returns: the abstracted utterance without false positive abstractions
-
parse_1_best
(obs, verbose=False, *args, **kwargs)[source]¶ Parse an utterance into a dialogue act.
:rtype DialogueActConfusionNetwork
-
parse_ampm
(abutterance, cn)[source]¶ Detects the ampm in the input abstract utterance.
Parameters: - abutterance – the input abstract utterance.
- cn – The output dialogue act item confusion network.
-
parse_borough
(abutterance, cn)[source]¶ Detects stops in the input abstract utterance.
Parameters: - abutterance – the input abstract utterance.
- cn – The output dialogue act item confusion network.
-
parse_city
(abutterance, cn)[source]¶ Detects stops in the input abstract utterance.
Parameters: - abutterance – the input abstract utterance.
- cn – The output dialogue act item confusion network.
-
parse_date_rel
(abutterance, cn)[source]¶ Detects the relative date in the input abstract utterance.
Parameters: - abutterance – the input abstract utterance.
- cn – The output dialogue act item confusion network.
-
parse_meta
(utterance, abutt_lenghts, cn)[source]¶ Detects all dialogue acts which do not generalise its slot values using CLDB.
- NOTE: Use DAIBuilder (‘dai’ variable) to match words and build DialogueActItem,
- so that the DAI is aligned to corresponding words. If matched words are not supposed to be aligned, use PTICSHDCSLU matching method instead. Make sure to list negative conditions first, so the following positive conditions are not added to alignment, when they shouldn’t. E.g.: (not any_phrase_in(u, [‘dobrý den’, ‘dobrý večer’]) and dai.any_word_in(“dobrý”))
Parameters: - utterance – the input utterance
- cn – The output dialogue act item confusion network.
Returns: None
-
parse_non_speech_events
(utterance, cn)[source]¶ Processes non-speech events in the input utterance.
Parameters: - utterance – the input utterance
- cn – The output dialogue act item confusion network.
Returns: None
-
parse_number
(abutterance)[source]¶ Detect a number in the input abstract utterance
Number words that form time expression are collapsed into a single TIME category word. Recognized time expressions (where FRAC, HOUR and MIN stands for fraction, hour and minute numbers respectively):
- FRAC [na] HOUR
- FRAC hodin*
- HOUR a FRAC hodin*
- HOUR hodin* a MIN minut*
- HOUR hodin* MIN
- HOUR hodin*
- HOUR [0]MIN
- MIN minut*
Words of NUMBER category are assumed to be in format parsable to int or float
Parameters: abutterance (Utterance) – the input abstract utterance.
-
parse_state
(abutterance, cn)[source]¶ Detects state in the input abstract utterance.
Parameters: - abutterance – the input abstract utterance.
- cn – The output dialogue act item confusion network.
-
parse_stop
(abutterance, cn)[source]¶ Detects stops in the input abstract utterance.
Parameters: - abutterance – the input abstract utterance.
- cn – The output dialogue act item confusion network.
-
parse_street
(abutterance, cn)[source]¶ Detects street in the input abstract utterance.
Parameters: - abutterance – the input abstract utterance.
- cn – The output dialogue act item confusion network.
-
parse_task
(abutterance, cn)[source]¶ Detects the task in the input abstract utterance.
Parameters: - abutterance –
- cn – The output dialogue act item confusion network.
-
parse_time
(abutterance, cn)[source]¶ Detects the time in the input abstract utterance.
Parameters: - abutterance – the input abstract utterance.
- cn – The output dialogue act item confusion network.
-
parse_vehicle
(abutterance, cn)[source]¶ Detects the vehicle (transport type) in the input abstract utterance.
Parameters: - abutterance – the input abstract utterance.
- cn – The output dialogue act item confusion network.
-
parse_waypoint
(abutterance, cn, wp_id, wp_slot_suffix, phr_wp_types, phr_in=None)[source]¶ Detects stops or cities in the input abstract utterance (called through parse_city or parse_stop).
Parameters: - abutterance – the input abstract utterance.
- cn – The output dialogue act item confusion network.
- wp_id – waypoint slot category label (e.g. “STOP=”, “CITY=”)
- wp_slot_suffix – waypoint slot suffix (e.g. “stop”, “city”)
- phr_wp_types – set of phrases for each waypoint type
- phr_in – phrases for ‘in’ waypoint type
-
-
alex.applications.PublicTransportInfoEN.hdc_slu.
ending_phrases_in
(utterance, phrases)[source]¶ Returns True if the utterance ends with one of the phrases
Parameters: - utterance – The utterance to search in
- phrases – a list of phrases to search for
Return type: bool
-
alex.applications.PublicTransportInfoEN.hdc_slu.
first_phrase_span
(utterance, phrases)[source]¶ Returns the span (start, end+1) of the first phrase from the given list that is found in the utterance. Returns (-1, -1) if no phrase is found.
Parameters: - utterance – The utterance to search in
- phrases – a list of phrases to be tried (in the given order)
Return type: tuple
-
alex.applications.PublicTransportInfoEN.hdc_slu.
last_phrase_pos
(utterance, words)[source]¶ Returns the last position of a given phrase in the given utterance, or -1 if not found.
Return type: int
-
alex.applications.PublicTransportInfoEN.hdc_slu.
last_phrase_span
(utterance, phrases)[source]¶ Returns the span (start, end+1) of the last phrase from the given list that is found in the utterance. Returns (-1, -1) if no phrase is found.
Parameters: - utterance – The utterance to search in
- phrases – a list of phrases to be tried (in the given order)
Return type: tuple
alex.applications.PublicTransportInfoEN.preprocessing module¶
-
class
alex.applications.PublicTransportInfoEN.preprocessing.
PTIENNLGPreprocessing
(ontology)[source]¶ Bases:
alex.components.nlg.template.TemplateNLGPreprocessing
Template NLG preprocessing routines for English public transport information.
This serves for spelling out relative and absolute time expressions,
-
preprocess
(template, svs_dict)[source]¶ Preprocess values to be filled into an NLG template. Spells out temperature and time expressions and translates some of the values to English.
Parameters: svs_dict – Slot-value dictionary Returns: The same dictionary, with modified values
-
spell_temperature
(value, interval)[source]¶ Convert a temperature expression into words (assuming nominative).
Parameters: - value – Temperature value (whole number in degrees as string), e.g. ‘1’ or ‘-10’.
- interval – Boolean indicating whether to treat this as a start of an interval, i.e. omit the degrees word.
Returns: temperature expression as string
-
-
class
alex.applications.PublicTransportInfoEN.preprocessing.
PTIENSLUPreprocessing
(*args, **kwargs)[source]¶ Bases:
alex.components.slu.base.SLUPreprocessing
Extends SLUPreprocessing for some transformations:
alex.applications.PublicTransportInfoEN.site_preprocessing module¶
-
alex.applications.PublicTransportInfoEN.site_preprocessing.
expand
(element, spell_numbers=True)[source]¶
alex.applications.PublicTransportInfoEN.test_hdc_policy module¶
alex.applications.PublicTransportInfoEN.test_hdc_slu module¶
alex.applications.PublicTransportInfoEN.time_zone module¶
-
class
alex.applications.PublicTransportInfoEN.time_zone.
GoogleTimeFinder
(cfg)[source]¶