dateparser.languages package — DateParser 1.2.0 documentation

# dateparser.languages package

## Submodules

## dateparser.languages.dictionary module

class dateparser.languages.dictionary.Dictionary(locale_info, settings=None)

  Bases: `object`

  Class that modifies and stores translations and handles splitting of date string.

  Parameters:

    - locale_info – Locale info (translation data) of the locale.

    - settings (dict) – Configure customized behavior using settings defined in `dateparser.conf.Settings`.

  Returns:

    a Dictionary instance.

  are_tokens_valid(tokens)

    Check if tokens are valid tokens for the locale.

    Parameters:

      tokens (list) – a list of string tokens.

    Returns:

      True if tokens are valid, False otherwise.

  split(string, keep_formatting=False)

    Split the date string using translations in locale info.

    Parameters:

      - string (str) – Date string to be splitted.

      - keep_formatting (bool) – If True, retain formatting of the date string.

    Returns:

      A list of string tokens formed after splitting the date string.

class dateparser.languages.dictionary.NormalizedDictionary(locale_info, settings=None)

  Bases: `Dictionary`

exception dateparser.languages.dictionary.UnknownTokenError

  Bases: `Exception`

## dateparser.languages.loader module

class dateparser.languages.loader.LocaleDataLoader

  Bases: `object`

  Class that handles loading of locale instances.

  get_locale(shortname)

    Get a locale instance.

    Parameters:

      shortname (str) – A locale code, e.g. ‘fr-PF’, ‘qu-EC’, ‘af-NA’.

    Returns:

      locale instance

  get_locale_map(languages=None, locales=None, region=None, use_given_order=False, allow_conflicting_locales=False)

    Get an ordered mapping with locale codes as keys and corresponding locale instances as values.

    Parameters:

      - languages (list) – A list of language codes, e.g. [‘en’, ‘es’, ‘zh-Hant’]. If locales are not given, languages and region are used to construct locales to load.

      - locales (list) – A list of codes of locales which are to be loaded, e.g. [‘fr-PF’, ‘qu-EC’, ‘af-NA’]

      - region (str) – A region code, e.g. ‘IN’, ‘001’, ‘NE’. If locales are not given, languages and region are used to construct locales to load.

      - use_given_order (bool) – If True, the returned mapping is ordered in the order locales are given.

      - allow_conflicting_locales (bool) – if True, locales with same language and different region can be loaded.

    Returns:

      ordered locale code to locale instance mapping

  get_locales(languages=None, locales=None, region=None, use_given_order=False, allow_conflicting_locales=False)

    Yield locale instances.

    Parameters:

      - languages (list) – A list of language codes, e.g. [‘en’, ‘es’, ‘zh-Hant’]. If locales are not given, languages and region are used to construct locales to load.

      - locales (list) – A list of codes of locales which are to be loaded, e.g. [‘fr-PF’, ‘qu-EC’, ‘af-NA’]

      - region (str) – A region code, e.g. ‘IN’, ‘001’, ‘NE’. If locales are not given, languages and region are used to construct locales to load.

      - use_given_order (bool) – If True, the returned mapping is ordered in the order locales are given.

      - allow_conflicting_locales (bool) – if True, locales with same language and different region can be loaded.

    Yield:

      locale instances

## dateparser.languages.locale module

class dateparser.languages.locale.Locale(shortname, language_info)

  Bases: `object`

  Class that deals with applicability and translation from a locale.

  Parameters:

    - shortname (str) – A locale code, e.g. ‘fr-PF’, ‘qu-EC’, ‘af-NA’.

    - language_info (dict) – Language info (translation data) of the language the locale belongs to.

  Returns:

    A Locale instance

  static clean_dictionary(dictionary, threshold=2)
  count_applicability(text, strip_timezone=False, settings=None)
  get_wordchars_for_detection(settings)
  is_applicable(date_string, strip_timezone=False, settings=None)

    Check if the locale is applicable to translate date string.

    Parameters:

      - date_string (str) – A string representing date and/or time in a recognizably valid format.

      - strip_timezone (bool) – If True, timezone is stripped from date string.

    Returns:

      boolean value representing if the locale is applicable for the date string or not.

  to_parserinfo(base_cls=<class 'dateutil.parser._parser.parserinfo'>)
  translate(date_string, keep_formatting=False, settings=None)

    Translate the date string to its English equivalent.

    Parameters:

      - date_string (str) – A string representing date and/or time in a recognizably valid format.

      - keep_formatting (bool) – If True, retain formatting of the date string after translation.

    Returns:

      translated date string.

  translate_search(search_string, settings=None)

## dateparser.languages.validation module

class dateparser.languages.validation.LanguageValidator

  Bases: `object`

  VALID_KEYS = ['name', 'skip', 'pertain', 'simplifications', 'no_word_spacing', 'ago', 'in', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december', 'year', 'month', 'week', 'day', 'hour', 'minute', 'second', 'sentence_splitter_group']
  classmethod get_logger()
  logger = None
  classmethod validate_info(language_id, info)

## Module contents