Repository navigation
Description
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
noviluni commentedon Jun 22, 2020
Real-world case:
I and @lopuhin analyzed a project where
dateparserwas used to parse dates coming from different sources in different languages, and I can confirm that the new order would be more efficient.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.
dariuschira commentedon Sep 30, 2020
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:
Hebrew and Norwegian, are new.
New order will start with: