mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-27 15:35:14 +00:00
Fix: correct OCR to dateparser language map entries
This commit is contained in:
1 parent
f775b94cd6
commit
82b6dd5fc0
2 files changed
+30
-14
No files matched your search
@@ -12,6 +12,11 @@ from paperless.utils import ocr_to_dateparser_languages
|
||||
pytest.param("eng", ["en"], id="single-language"),
|
||||
pytest.param("fra+ita+lao", ["fr", "it", "lo"], id="multiple-languages"),
|
||||
pytest.param("fil", ["fil"], id="no-two-letter-equivalent"),
|
||||
pytest.param(
|
||||
"afr+vie+kan+chr+mkd", # codespell:ignore
|
||||
["af", "vi", "kn", "chr", "mk"],
|
||||
id="previously-unmapped-languages",
|
||||
),
|
||||
pytest.param(
|
||||
"aze_cyrl+srp_latn",
|
||||
["az-Cyrl", "sr-Latn"],
|
||||
@@ -49,6 +54,19 @@ def test_ocr_to_dateparser_languages(ocr_language: str, expected: list[str]) ->
|
||||
assert sorted(ocr_to_dateparser_languages(ocr_language)) == sorted(expected)
|
||||
|
||||
|
||||
def test_ocr_to_dateparser_map_values_supported_by_dateparser() -> None:
|
||||
from dateparser.languages.loader import LocaleDataLoader
|
||||
|
||||
loader = LocaleDataLoader()
|
||||
unsupported = []
|
||||
for ocr_code, dateparser_code in utils.OCR_TO_DATEPARSER_LANGUAGES.items():
|
||||
try:
|
||||
loader.get_locale_map(locales=[dateparser_code])
|
||||
except Exception:
|
||||
unsupported.append((ocr_code, dateparser_code))
|
||||
assert unsupported == []
|
||||
|
||||
|
||||
def test_ocr_to_dateparser_languages_exception(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
|
||||
+12
-14
@@ -2,17 +2,15 @@ import logging
|
||||
|
||||
logger = logging.getLogger("paperless.utils")
|
||||
|
||||
# Translation map from languages supported by Tesseract OCR
|
||||
# to languages supported by dateparser.
|
||||
# To add a language, make sure it is supported by both libraries.
|
||||
# The ISO 639-2 will help you link a 3-char to 2-char language code.
|
||||
# Links:
|
||||
# - Tesseract languages: https://tesseract-ocr.github.io/tessdoc/Data-Files-in-different-versions.html
|
||||
# - Python dateparser languages: https://dateparser.readthedocs.io/en/latest/supported_locales.html
|
||||
# - ISO 639-2: https://www.loc.gov/standards/iso639-2/php/code_list.php
|
||||
OCR_TO_DATEPARSER_LANGUAGES = {
|
||||
"""
|
||||
Translation map from languages supported by Tesseract OCR
|
||||
to languages supported by dateparser.
|
||||
To add a language, make sure it is supported by both libraries.
|
||||
The ISO 639-2 will help you link a 3-char to 2-char language code.
|
||||
Links:
|
||||
- Tesseract languages: https://tesseract-ocr.github.io/tessdoc/Data-Files-in-different-versions.html
|
||||
- Python dateparser languages: https://dateparser.readthedocs.io/en/latest/supported_locales.html
|
||||
- ISO 639-2: https://www.loc.gov/standards/iso639-2/php/code_list.php
|
||||
"""
|
||||
# TODO check these Dateparser languages as they are not referenced on the ISO639-2 standard,
|
||||
# so we didn't find the equivalent in Tesseract:
|
||||
# agq, asa, bez, brx, cgg, ckb, dav, dje, dyo, ebu, guz, jgo, jmc, kde, kea, khq, kln,
|
||||
@@ -22,7 +20,6 @@ OCR_TO_DATEPARSER_LANGUAGES = {
|
||||
"amh": "am",
|
||||
"ara": "ar",
|
||||
"asm": "as",
|
||||
"ast": "ast",
|
||||
"aze": "az",
|
||||
"bel": "be",
|
||||
"bul": "bg",
|
||||
@@ -31,7 +28,7 @@ OCR_TO_DATEPARSER_LANGUAGES = {
|
||||
"bre": "br",
|
||||
"bos": "bs",
|
||||
"cat": "ca",
|
||||
"cher": "chr",
|
||||
"chr": "chr",
|
||||
"ces": "cs",
|
||||
"cym": "cy",
|
||||
"dan": "da",
|
||||
@@ -65,13 +62,14 @@ OCR_TO_DATEPARSER_LANGUAGES = {
|
||||
"kat": "ka",
|
||||
"kaz": "kk",
|
||||
"khm": "km",
|
||||
"knda": "kn",
|
||||
"kan": "kn",
|
||||
"kor": "ko",
|
||||
"kir": "ky",
|
||||
"ltz": "lb",
|
||||
"lao": "lo",
|
||||
"lit": "lt",
|
||||
"lav": "lv",
|
||||
"mkd": "mk",
|
||||
"mal": "ml",
|
||||
"mon": "mn",
|
||||
"mar": "mr",
|
||||
@@ -106,7 +104,7 @@ OCR_TO_DATEPARSER_LANGUAGES = {
|
||||
"ukr": "uk",
|
||||
"urd": "ur",
|
||||
"uzb": "uz",
|
||||
"via": "vi",
|
||||
"vie": "vi", # codespell:ignore
|
||||
"yid": "yi",
|
||||
"yor": "yo",
|
||||
"chi": "zh",
|
||||
|
||||
Reference in new issue
Block a user