def _get_duration(request): """ Get's the duration the user wants to set a timer for Args: request (Request): contains info about the conversation up to this point (e.g. domain, intent, entities, etc) Returns: int: the seconds """ duration_entity_candidates = get_candidates_for_text( request.text, entity_types='sys_duration') duration_entity = None \ if len(duration_entity_candidates) == 0 else duration_entity_candidates[0] if duration_entity: count = duration_entity['value']['value'] if count == 1: unit = duration_entity['value']['unit'] else: unit = duration_entity['value'][ 'unit'] + 's' # Plural if greater than 1 return "{count} {units}".format(count=count, units=unit) else: return DEFAULT_TIMER_DURATION
def _get_temperature_change(request): """ Get's the user desired temperature change for thermostat, defaults to 1 degree Args: request (Request): contains info about the conversation up to this point (e.g. domain, intent, entities, etc) Returns: string: resolved temperature entity """ temperature_entity = get_candidates_for_text(request.text, entity_types='sys_temperature') if temperature_entity: return temperature_entity[0]['value']['value'] else: return DEFAULT_THERMOSTAT_CHANGE
def test_get_candidates_for_text_locale(text, locale, expected_entity): candidates = get_candidates_for_text(text, locale=locale) assert candidates[0]["body"] == expected_entity
def test_get_candidates_for_text_language(text, language, expected_entity): candidates = get_candidates_for_text(text, language=language) assert candidates[0]["body"] == expected_entity