From 52fe7b92fb0a88e0a2bb420b959ad0e707cb5e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Thu, 18 Jun 2026 08:22:18 +0400 Subject: [PATCH] =?UTF-8?q?v3.1.4:=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86?= =?UTF-8?q?=D1=8B=20=E2=80=94=20=D0=BC=D0=B8=D0=BD=202=20=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=BA=D0=B8,=2040%=20=D0=B7=D0=B0=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site/parser.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/site/parser.py b/site/parser.py index a22154b..d49c66f 100644 --- a/site/parser.py +++ b/site/parser.py @@ -154,7 +154,7 @@ def _parse_pdf(file_bytes: bytes) -> dict: tables = page.extract_tables() if tables: for tbl in tables: - if tbl and _table_has_content(tbl, min_fill_ratio=0.3): + if tbl and _table_has_content(tbl): result["elements"].append({ "type": "table", "rows": tbl, @@ -168,18 +168,22 @@ def _parse_pdf(file_bytes: bytes) -> dict: def _table_has_content(tbl: list, min_fill_ratio: float = 0.0) -> bool: """ - Проверить что таблица содержит осмысленные данные. + Проверить что таблица содержит осмысленные ТАБЛИЧНЫЕ данные. - Фильтры: - - Хотя бы одна непустая ячейка - - Не менее min_fill_ratio ячеек заполнены (по умолчанию 0 — без фильтра) + Отбрасываем: + - Полностью пустые + - Одна строка (обычно это текст, не таблица) + - Менее 40% ячеек заполнены """ if not tbl or not tbl[0]: return False + # Одна строка — не таблица, а текст + if len(tbl) <= 1: + return False + total = 0 filled = 0 - all_text = "" for row in tbl: if not row: @@ -189,15 +193,13 @@ def _table_has_content(tbl: list, min_fill_ratio: float = 0.0) -> bool: cell_str = str(cell).strip() if cell else "" if cell_str: filled += 1 - all_text += " " + cell_str if filled == 0: return False - # Фильтр по доле заполненных ячеек - if min_fill_ratio > 0 and total > 0: - if filled / total < min_fill_ratio: - return False + # Не менее 40% ячеек должны быть заполнены + if total > 0 and filled / total < 0.4: + return False return True