Log unsupported languages.
This extracts the logging logic that was being used in a few places to
indicate certain parcing functions are not supported in particular
languages, and adds the logging to extract_duration.
@@ -34,6 +34,22 @@ from mycroft.util.lang.parse_fr import normalize_fr
from .log import LOG
+def _log_unsupported_language(language, supported_languages):
+ """
+ Log a warning when a language is unsupported
+
+ Arguments:
+ language: str
+ The language that was supplied.
+ supported_languages: [str]
+ The list of supported languages.
+ """
+ supported = ' '.join(supported_languages)
+ LOG.warning('Language "{language}" not recognized! Please make sure your '
+ 'language is one of the following: {supported}.'
+ .format(language=language, supported=supported))
+
+
def fuzzy_match(x, against):
"""Perform a 'fuzzy' comparison between two strings.
Returns:
@@ -130,9 +146,8 @@ def extract_number(text, short_scale=True, ordinals=False, lang="en-us"):
elif lang_lower.startswith("de"):
return extractnumber_de(text)
# TODO: extractnumber_xx for other languages
- LOG.warning('Language "{}" not recognized! Please make sure your '
- 'language is one of the following: '
- 'en, es, pt, it, fr, sv, de.'.format(lang_lower))
+ _log_unsupported_language(lang_lower,
+ ['en', 'es', 'pt', 'it', 'fr', 'sv', 'de'])
return text
@@ -166,6 +181,7 @@ def extract_duration(text, lang="en-us"):
if lang_lower.startswith("en"):
return extract_duration_en(text)
# TODO: extract_duration for other languages
+ _log_unsupported_language(lang_lower, ['en'])
return text
@@ -241,9 +257,8 @@ def extract_datetime(text, anchorDate=None, lang="en-us", default_time=None):
elif lang_lower.startswith("de"):
return extract_datetime_de(text, anchorDate, default_time)
# TODO: extract_datetime for other languages
- LOG.warning('Language "{}" not recognized! Please make sure your '
- 'language is one of the following: '
- 'en, es, pt, it, fr, sv, de.'.format(lang_lower))
+ _log_unsupported_language(lang_lower,
+ ['en', 'es', 'pt', 'it', 'fr', 'sv', 'de'])
return text
# ==============================================================
@@ -278,9 +293,8 @@ def normalize(text, lang="en-us", remove_articles=True):
elif lang_lower.startswith("de"):
return normalize_de(text, remove_articles)
# TODO: Normalization for other languages
- LOG.warning('Language "{}" not recognized! Please make sure your '
- 'language is one of the following: '
- 'en, es, pt, it, fr, sv, de.'.format(lang_lower))
+ _log_unsupported_language(lang_lower,
+ ['en', 'es', 'pt', 'it', 'fr', 'sv', 'de'])
return text
