Skip to content

Improve the default language used order #714

Closed

Description

@noviluni

When trying to parse a date if we don't pass any locale, language, or region, dateparser tries with different locales until it finds something that works.

The used order is defined here: https://github.com/scrapinghub/dateparser/blob/master/dateparser/data/languages_info.py, and that file is generated when running this script: dateparser_scripts/order_languages.py, that uses the most known/spoken language coming from here.

However, I think that this approach is not good enough and it could be improved. Even if this library can be used for a high number of different purposes, the main purpose is to parse dates coming from the internet. If you agree with this, it makes more sense to try first with the most used languages on the internet, which are not the same as the most known/spoken languages.

Here the list of the 10 most common languages on the internet (font: https://w3techs.com/technologies/overview/content_language):

  • en: 59.5%
  • ru: 8.6%
  • es: 4.0%
  • tr: 3.1%
  • fa: 2.9%
  • de: 2.7%
  • fr: 2.7%
  • ja: 2.3%
  • pt: 2%
  • vi: 1.5%

Here the list of the 10 first languages we try:

  • en: 59.5%
  • zh and zh-Hans: 1.5%
  • hi: 0.1%
  • es: 4.0%
  • ar: 0.9%
  • bn: <0.1%
  • fr: 2.7%
  • ur: <0.1%
  • pt: 2%
  • ta: <0.1%

Why are we trying with languages used by less than 0.1% of websites like Urdu, Tamil, etc. before trying with Russian, that it's in the 8.6% of the websites, Turkish (3.1%) or Japanese (2.3%)?

I think that changing this won't have a really big impact for most of the situations (that use English or only one language and the used locale is "cached"), but it could impact other projects that are using dateparser to parse some other languages intensively.

Let me know what you think and how we could implement this. :)

Activity

  1. added this to the v1.0.0 milestone on Jun 22, 2020
  2. noviluni commented on Jun 22, 2020

    @noviluni
    ContributorAuthor

    Real-world case:

    I and @lopuhin analyzed a project where dateparser was used to parse dates coming from different sources in different languages, and I can confirm that the new order would be more efficient.

    image(1)

    The improvement for English won't be any and it represents the language used in 80% of those analyzed websites, but it would be faster for 10.6% of the cases, while slower for 2% (Arabic + Chinese). Even that, it would probably improve the speed for non listed languages too (~9%) and the speed improvements in that 10.6% would be bigger than the speed deterioration for the other 2%.

    I would consider this new approach as validated, and now we should decide how to implement it, as I didn't find any JSON or similar structure containing the most used locales (should we order them manually?) and we should decide what to do with the other non listed languages (we could probably apply the current order we use to the remaining non-listed languages).

    Let me know if you have any ideas or feedback.

  3. modified the milestones: v1.0.0, 1.1.0 on Sep 28, 2020
  4. dariuschira commented on Sep 30, 2020

    @dariuschira
    Contributor

    I think the following is a working list from https://w3techs.com/technologies/overview/content_language

    Some languages, like Arabic and Chinese have some slight variations that I'm not sure should be included. I found a full list of languages using similar locales here: https://www.localeplanet.com/icu/iso639.html

    Should we consider only one locale per language and variations or should all be added? And if the latter, should we add them next to the main locale or maintain the original order?

    For example, Chinese has:

    Chinese (zh)
    Chinese (Simplified) (zh-Hans)
    Chinese (Simplified, China) (zh-Hans-CN)
    Chinese (Simplified, Hong Kong SAR China) (zh-Hans-HK)
    Chinese (Simplified, Macau SAR China) (zh-Hans-MO)
    Chinese (Simplified, Singapore) (zh-Hans-SG)
    Chinese (Traditional) (zh-Hant)
    Chinese (Traditional, Hong Kong SAR China) (zh-Hant-HK)
    Chinese (Traditional, Macau SAR China) (zh-Hant-MO)
    Chinese (Traditional, Taiwan) (zh-Hant-TW)
    

    Hebrew and Norwegian, are new.

    New order will start with:

    en English	
    ru Russian	
    es Spanish	
    tr Turkish	
    fa Persian	
    fr French	
    de German	
    ja Japanese	
    pt Portuguese	
    vi Vietnamese	
    zh Chinese	
    # 'zh-Hans' variation previously prioritised
    ar Arabic
    # 'pa-Arab' - Punjabi (Arabic) - variation previously prioritised 
    it Italian	
    pl Polish	
    in Indonesian	
    el Greek	
    nl Dutch, Flemish	
    ko Korean	
    th Thai	
    iw Hebrew   # new
    uk Ukrainian	
    cs Czech	
    sv Swedish	
    ro Romanian	
    hu Hungarian	
    da Danish	
    sr Serbian	
    sk Slovak	
    fi Finnish	
    bg Bulgarian	
    hr Croatian	
    lt Lithuanian	
    hi Hindi
    no_NO Norwegian Bokmål	# new
    sl Slovenian	
    no Norwegian   # new 
    et Estonian	
    lv Latvian	
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions