fix(ТСН): единица «Измеритель» не переезжает на следующую таблицу сборника
Находка зайки: current_unit жил через границу таблиц, и таблица без строки «Измеритель» молча получала единицу соседней — карантин «нет единицы» не срабатывал. Теперь единицу ведёт правило: «Измеритель: …» задаёт её, подпись новой таблицы сбрасывает; работы таблицы без единицы честно уходят в карантин. Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
+11
-9
@@ -141,12 +141,16 @@ def _assign(values: list[tuple[float, float, str]], cols: list[tuple[str, float]
|
||||
return out
|
||||
|
||||
|
||||
def _unit_of(lines: list[list[tuple[float, float, str]]]) -> str:
|
||||
for line in lines:
|
||||
text = " ".join(w for _, _, w in line)
|
||||
if text.lower().startswith("измеритель"):
|
||||
return text.split(":", 1)[-1].strip() or text
|
||||
return ""
|
||||
def _track_unit(current: str, text: str) -> str:
|
||||
"""Единица измерения своей таблицы. «Измеритель: …» задаёт её, подпись новой
|
||||
таблицы сбрасывает: таблица без строки «Измеритель» не получает единицу соседней
|
||||
(находка зайки 18.11.2026 — молчаливое наследование чужой единицы)."""
|
||||
low = text.lower()
|
||||
if CAPTION_RE.match(text) and "продолжение" not in low:
|
||||
return ""
|
||||
if low.startswith("измеритель"):
|
||||
return text.split(":", 1)[-1].strip()
|
||||
return current
|
||||
|
||||
|
||||
def parse_rate_book(path: str, meta: dict | None = None) -> dict:
|
||||
@@ -184,10 +188,8 @@ def parse_rate_book(path: str, meta: dict | None = None) -> dict:
|
||||
if found:
|
||||
current_table = found[-1]
|
||||
lines = _lines(page.get_text("words"))
|
||||
unit = _unit_of(lines)
|
||||
if unit:
|
||||
current_unit = unit
|
||||
for line in lines:
|
||||
current_unit = _track_unit(current_unit, " ".join(w for _, _, w in line))
|
||||
cols = _columns(line)
|
||||
if cols:
|
||||
current_cols = cols
|
||||
|
||||
Reference in New Issue
Block a user