lllin000_PaperForge/tests/test_ocr_render_v2.py
Research Assistant f9dff20cd8 feat: OCR complex layout and sidebar detection overhaul
- Add RegionPrepass data model for frontmatter/structured_insert/body classification
- Add PDF visual container detection (filled rects) for sidebar detection
- Add Box N and keyword-based sidebar anchor detection
- Add column-aware block expansion for mixed sidebar clusters
- Add _container_text from PDF text blocks for cross-column truncation
- Add degraded-mode heading level normalization with font size clustering
- Merge adjacent structured_insert blocks into single callout
- Fix metadata enrichment from Literature-hub note frontmatter for old papers
- Fix heading hierarchy using span font-size clusters when available
- Add real-paper regression harness (TSCKAVIS, CAQNW9Q2, A8E7SRVS, K7R8PEKW)
- Add body retention, heading, metadata, and callout acceptance tests
- 219 passed, 4 control guards passed
2026-06-07 21:35:57 +08:00

37 lines
1.5 KiB
Python

from __future__ import annotations
def test_render_fulltext_uses_resolved_metadata_and_object_links(tmp_path) -> None:
from paperforge.worker.ocr_render import render_fulltext_markdown
structured_blocks = [
{"page": 1, "block_id": "p1_b1", "role": "abstract_heading", "text": "Abstract", "render_default": True},
{"page": 1, "block_id": "p1_b2", "role": "abstract_body", "text": "Background text.", "render_default": True},
{"page": 2, "block_id": "p2_b1", "role": "section_heading", "text": "1 Introduction", "render_default": True},
{"page": 2, "block_id": "p2_b2", "role": "body_paragraph", "text": "Intro body.", "render_default": True},
]
resolved_metadata = {
"title": {"value": "Paper Title"},
"authors": {"value": ["Alice", "Bob"]},
"journal": {"value": "Journal A"},
"year": {"value": 2024},
"doi": {"value": "10.1000/xyz"},
}
figure_inventory = {
"matched_figures": [{"figure_id": "figure_001", "confidence": 0.91, "flags": []}],
}
table_inventory = {
"tables": [{"table_id": "table_001", "has_asset": True}],
}
md = render_fulltext_markdown(
structured_blocks=structured_blocks,
resolved_metadata=resolved_metadata,
figure_inventory=figure_inventory,
table_inventory=table_inventory,
)
assert "# Paper Title" in md
assert "Authors:" in md
assert "## 1 Introduction" in md
assert "![[figures/figure_001.md]]" in md or "![[render/figures/figure_001.md]]" in md