From 3717a004598ffa32fc990df08dcd1a7f4e9d4aaf Mon Sep 17 00:00:00 2001 From: codex Date: Tue, 24 Nov 2026 10:21:22 +0000 Subject: [PATCH] Fix training year filter and reject incomplete OCR titles --- app/parser/education_document.py | 10 ++++++++-- app/services/admin_data.py | 3 +-- tests/test_training_filter.py | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/parser/education_document.py b/app/parser/education_document.py index e5140bc..91d19db 100644 --- a/app/parser/education_document.py +++ b/app/parser/education_document.py @@ -17,9 +17,15 @@ def _run(args): def _certificate(text): text = " ".join(text.split()) - title = re.search(r'(?:по (?:дополнительной профессиональной )?программе|по теме|на тему)\s*[:«"\s]*([^»"]{5,300})[»"]', text, re.I) + title = re.search( + r'(?:по (?:дополнительной профессиональной )?программе|по теме|на тему)' + r'(?: повышения квалификации| дополнительного профессионального образования)?' + r'\s*:?\s*[«"“]([^»"”]{5,300})[»"”]', text, re.I, + ) if not title: - title = re.search(r'[«"]([^«»"]{8,250})[»"]\s*[,.(]?\s*(?:в объ[её]ме|\d+ час)', text, re.I) + title = re.search(r'[«"“]([^«»"“”]{8,250})[»"”]\s*[,.(]?\s*(?:в объ[её]ме|\d+ час)', text, re.I) + if title and "|" in title[1]: + return None # OCR could not read the entire program name. years = re.findall(r"\b(?:19|20)\d{2}\b", text) if not title or not years or not re.search(r"квалификаци|сертификат|удостоверение", text, re.I): return None diff --git a/app/services/admin_data.py b/app/services/admin_data.py index fb23f46..c590ce5 100644 --- a/app/services/admin_data.py +++ b/app/services/admin_data.py @@ -42,7 +42,6 @@ DIRECTORY_COLUMNS = ( ) _TRAINING_LABEL = "повышение квалификации" -_TRAINING_KIND = re.compile(r",\s*повышение квалификации\s*(?:,|$)", re.IGNORECASE) _TRAINING_MENTION = re.compile( r"\b(?:повышение квалификации|(?:курс|программ)[а-яё]* (?:повышения|по повышению) квалификации)\b", re.IGNORECASE, @@ -66,7 +65,7 @@ def _has_training(data: dict[str, Any], since_year: int | None) -> bool: structured_texts.add(text) if since_year is not None and (type(year) is not int or year < since_year): continue - if text and text != str(year) and (dedicated or _TRAINING_KIND.search(_QUOTED_TEXT.sub("", text))): + if text and text != str(year) and (dedicated or _TRAINING_MENTION.search(_QUOTED_TEXT.sub("", text))): return True # Profiles may also list completed courses in manually entered paragraphs or lists. for text in _clean_list(section.get("paragraphs")) + _clean_list(section.get("items")): diff --git a/tests/test_training_filter.py b/tests/test_training_filter.py index bba1d2d..0896626 100644 --- a/tests/test_training_filter.py +++ b/tests/test_training_filter.py @@ -14,6 +14,8 @@ from app.services.admin_data import list_employees_page @pytest.mark.parametrize( ("html", "has_course", "has_recent_course"), [ + ('
2025
Курс повышения квалификации по Python
', True, True), + ('
2025
Стажировка «Курс повышения квалификации»
', False, False), ('

2024 (11 декабря), НИУ ВШЭ. Программа повышения квалификации «ИИ».

', True, True), ('', True, True), ('

Курс повышения квалификации «ДПО», 7 сентября 2024 год.

', True, True),