Files
contracts-app/site/textify.py
T
naeel cbfba0bc54 feat: schema.py (DDL 5 таблиц), db.py без DDL, app.py минимальный, test_routes с комментариями
По рекомендации Sonnet:
- schema.py — все DDL (documents, contracts, supplements, spec_rows, spec_history)
- db.py — только транспорт (connect/query), DDL убран
- app.py — минимальный: ensure_schema() + register_blueprint()
- test_routes.py — подробные комментарии, исправлен импорт psysql
2026-06-13 17:14:48 +04:00

37 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
Преобразование elements JSON → линейный текст для LLM.
Ничего не фильтрует, не интерпретирует — только форматирует.
"""
def to_text(elements: list) -> str:
"""
Превращает список elements (из parser.py) в текстовое представление.
Параграфы: [Style] text
Таблицы: отбивка ---, строки как | cell | cell |
"""
lines = []
for el in elements:
if el["type"] == "paragraph":
style = el.get("style", "")
prefix = f"[{style}] " if style else ""
lines.append(f"{prefix}{el['text']}")
elif el["type"] == "table":
rows = el["rows"]
if not rows:
continue
ncols = len(rows[0])
lines.append(f"\n--- Таблица ({len(rows)}×{ncols}) ---")
for row in rows:
# дополняем строку до ncols
padded = list(row) + [""] * (ncols - len(row))
cells = [str(c).replace("\n", " ").replace("|", "\\|") for c in padded]
lines.append("| " + " | ".join(cells) + " |")
lines.append("")
return "\n".join(lines)