Compare commits

..
4 changed files with 34 additions and 31 deletions

No files matched your search

-5
View File
@@ -23,7 +23,6 @@ dependencies = [
"channels~=4.2",
"channels-redis~=4.2",
"concurrent-log-handler~=0.9.25",
"cryptography>=50",
"dateparser~=1.4",
# WARNING: django does not use semver.
# Only patch versions are guaranteed to not introduce breaking changes.
@@ -47,7 +46,6 @@ dependencies = [
"flower>=2.0.1,<2.3",
"gotenberg-client[httpx]~=1.0",
"httpx-oauth~=0.17",
"humanize>=4.15",
"ijson>=3.5.1",
"imap-tools>=1.14,<1.16",
"jinja2~=3.1.6",
@@ -58,13 +56,10 @@ dependencies = [
"llama-index-embeddings-openai-like>=0.2.2",
"llama-index-llms-ollama>=0.9.1",
"llama-index-llms-openai-like>=0.7.1",
"lxml>=6.1",
"ocrmypdf[heic]>=17.12,<17.13",
"ollama>=0.6.1",
"openai>=2.48",
"pathvalidate~=3.3.1",
"pdf2image~=1.17.0",
"pikepdf>=10.13",
"python-dateutil~=2.9.0",
"python-dotenv~=1.2.1",
"python-gnupg~=0.5.4",
+18
View File
@@ -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,
+16 -16
View File
@@ -2,19 +2,18 @@ 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:
# These dateparser languages have no equivalent in any Tesseract release
# (checked against tessdata, tessdata_best and tessdata_fast), so they cannot
# be reached from the OCR language. Set PAPERLESS_DATE_PARSER_LANGUAGES to use them:
# agq, asa, bez, brx, cgg, ckb, dav, dje, dyo, ebu, guz, jgo, jmc, kde, kea, khq, kln,
# ksb, ksf, ksh, lag, lkt, lrc, luy, mer, mfe, mgh, mgo, mua, mzn, naq, nmg, nnh, nus,
# rof, rwk, saq, sbp, she, ses, shi, teo, twq, tzm, vun, wae, xog, yav, yue
@@ -22,7 +21,6 @@ OCR_TO_DATEPARSER_LANGUAGES = {
"amh": "am",
"ara": "ar",
"asm": "as",
"ast": "ast",
"aze": "az",
"bel": "be",
"bul": "bg",
@@ -31,7 +29,7 @@ OCR_TO_DATEPARSER_LANGUAGES = {
"bre": "br",
"bos": "bs",
"cat": "ca",
"cher": "chr",
"chr": "chr",
"ces": "cs",
"cym": "cy",
"dan": "da",
@@ -65,19 +63,21 @@ 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",
"msa": "ms",
"mlt": "mt",
"mya": "my",
"nor": "nb",
"nep": "ne",
"nld": "nl",
"ori": "or",
@@ -106,7 +106,7 @@ OCR_TO_DATEPARSER_LANGUAGES = {
"ukr": "uk",
"urd": "ur",
"uzb": "uz",
"via": "vi",
"vie": "vi", # codespell:ignore
"yid": "yi",
"yor": "yo",
"chi": "zh",
Generated
-10
View File
@@ -2516,7 +2516,6 @@ dependencies = [
{ name = "channels" },
{ name = "channels-redis" },
{ name = "concurrent-log-handler" },
{ name = "cryptography" },
{ name = "dateparser" },
{ name = "django" },
{ name = "django-allauth", extra = ["mfa", "socialaccount"] },
@@ -2538,7 +2537,6 @@ dependencies = [
{ name = "flower" },
{ name = "gotenberg-client", extra = ["httpx"] },
{ name = "httpx-oauth" },
{ name = "humanize" },
{ name = "ijson" },
{ name = "imap-tools" },
{ name = "jinja2" },
@@ -2549,13 +2547,10 @@ dependencies = [
{ name = "llama-index-embeddings-openai-like" },
{ name = "llama-index-llms-ollama" },
{ name = "llama-index-llms-openai-like" },
{ name = "lxml" },
{ name = "ocrmypdf", extra = ["heic"] },
{ name = "ollama" },
{ name = "openai" },
{ name = "pathvalidate" },
{ name = "pdf2image" },
{ name = "pikepdf" },
{ name = "python-dateutil" },
{ name = "python-dotenv" },
{ name = "python-gnupg" },
@@ -2673,7 +2668,6 @@ requires-dist = [
{ name = "channels", specifier = "~=4.2" },
{ name = "channels-redis", specifier = "~=4.2" },
{ name = "concurrent-log-handler", specifier = "~=0.9.25" },
{ name = "cryptography", specifier = ">=50.0.0" },
{ name = "dateparser", specifier = "~=1.4" },
{ name = "django", specifier = "~=5.2.18" },
{ name = "django-allauth", extras = ["mfa", "socialaccount"], specifier = "~=65.21.1" },
@@ -2696,7 +2690,6 @@ requires-dist = [
{ name = "gotenberg-client", extras = ["httpx"], specifier = "~=1.0" },
{ name = "granian", extras = ["uvloop"], marker = "extra == 'webserver'", specifier = ">=2.7,<2.9" },
{ name = "httpx-oauth", specifier = "~=0.17" },
{ name = "humanize", specifier = ">=4.15.0" },
{ name = "ijson", specifier = ">=3.5.1" },
{ name = "imap-tools", specifier = ">=1.14,<1.16" },
{ name = "jinja2", specifier = "~=3.1.6" },
@@ -2707,14 +2700,11 @@ requires-dist = [
{ name = "llama-index-embeddings-openai-like", specifier = ">=0.2.2" },
{ name = "llama-index-llms-ollama", specifier = ">=0.9.1" },
{ name = "llama-index-llms-openai-like", specifier = ">=0.7.1" },
{ name = "lxml", specifier = ">=6.1.0" },
{ name = "mysqlclient", marker = "extra == 'mariadb'", specifier = ">=2.2.7,<2.4" },
{ name = "ocrmypdf", extras = ["heic"], specifier = ">=17.12,<17.13" },
{ name = "ollama", specifier = ">=0.6.1" },
{ name = "openai", specifier = ">=2.48" },
{ name = "pathvalidate", specifier = "~=3.3.1" },
{ name = "pdf2image", specifier = "~=1.17.0" },
{ name = "pikepdf", specifier = ">=10.13" },
{ name = "psycopg", extras = ["c", "pool"], marker = "extra == 'postgres'", specifier = "==3.3.8" },
{ name = "psycopg-c", marker = "python_full_version == '3.12.*' and platform_machine == 'aarch64' and sys_platform == 'linux' and extra == 'postgres'", url = "https://github.com/paperless-ngx/builder/releases/download/psycopg-trixie-3.3.8/psycopg_c-3.3.8-cp312-cp312-manylinux_2_38_aarch64.whl" },
{ name = "psycopg-c", marker = "python_full_version == '3.14.*' and platform_machine == 'aarch64' and sys_platform == 'linux' and extra == 'postgres'", url = "https://github.com/paperless-ngx/builder/releases/download/psycopg-trixie-3.3.8/psycopg_c-3.3.8-cp314-cp314-manylinux_2_38_aarch64.whl" },