From a13810039873ea54f527c8e8f7ce29a5aa820b94 Mon Sep 17 00:00:00 2001 From: LLLin000 <809867916@qq.com> Date: Sat, 4 Jul 2026 22:17:43 +0800 Subject: [PATCH] fix(pr1): remove has_any_author gate from affiliation/email fallback --- paperforge/worker/ocr_render.py | 4 ++-- tests/test_ocr_render.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/paperforge/worker/ocr_render.py b/paperforge/worker/ocr_render.py index a418ef70..965b50d6 100644 --- a/paperforge/worker/ocr_render.py +++ b/paperforge/worker/ocr_render.py @@ -1223,9 +1223,9 @@ def _collect_frontmatter_fallback_fields( fallback_title = norm elif role == "authors" and not has_any_author: fallback_authors.append(norm) - elif role == "affiliation" and not has_any_author: + elif role == "affiliation": fallback_affiliations.append(norm) - elif role == "email" and not has_any_author: + elif role in {"email", "correspondence"}: fallback_emails.append(norm) elif role == "doi" and not has_doi: # Only accept clean DOI lines diff --git a/tests/test_ocr_render.py b/tests/test_ocr_render.py index aa6909d4..2f210030 100644 --- a/tests/test_ocr_render.py +++ b/tests/test_ocr_render.py @@ -979,6 +979,26 @@ def test_frontmatter_no_duplication_when_metadata_present() -> None: assert "John Smith" not in md +def test_render_frontmatter_affiliation_fallback_even_when_authors_metadata_present() -> None: + from paperforge.worker.ocr_render import render_fulltext_markdown + + structured = [ + {"page": 1, "role": "authors", "text": "John Smith", "block_id": "p1_a1"}, + {"page": 1, "role": "affiliation", "text": "University of Science", "block_id": "p1_af1"}, + ] + md = render_fulltext_markdown( + structured_blocks=structured, + resolved_metadata={"authors_display": "John Smith", "authors": {"value": ["John Smith"]}}, + figure_inventory={"matched_figures": [], "unmatched_assets": [], "unresolved_clusters": []}, + table_inventory={"tables": [], "unmatched_assets": []}, + page_count=1, + document_structure=None, + reader_payload={}, + ) + assert "**Affiliation:** University of Science" in md + assert "John Smith" in md + + def test_frontmatter_title_fallback_when_metadata_empty() -> None: """Title from structured blocks appears when metadata title is empty.""" from paperforge.worker.ocr_render import render_fulltext_markdown