Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/docvortex/content/table/rules.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""跨页表格延续文本与 caption 的轻量判定规则。"""

import re

from ...foundation._text import full_to_half

CONTINUATION_END_MARKERS = [
Expand All @@ -18,16 +20,20 @@
"(continued)",
]

_CONTINUATION_PREFIX_RE = re.compile(r"^(?:(?:续表|续上表)\s*|continued\s+table\s+)(?=[a-z]?\d)")


def is_table_continuation_text(text: str) -> bool:
"""判断文本是否表达续表语义,供表格归组和跨页合并共同复用。"""
"""判断后缀、行内或带编号前缀是否表达续表语义。"""
continuation_text = full_to_half((text or "").strip()).lower()
if not continuation_text:
return False

return any(
_matches_continuation_end_marker(continuation_text, marker.lower()) for marker in CONTINUATION_END_MARKERS
) or any(marker.lower() in continuation_text for marker in CONTINUATION_INLINE_MARKERS)
return (
any(_matches_continuation_end_marker(continuation_text, marker.lower()) for marker in CONTINUATION_END_MARKERS)
or any(marker.lower() in continuation_text for marker in CONTINUATION_INLINE_MARKERS)
or _CONTINUATION_PREFIX_RE.match(continuation_text) is not None
)


def _matches_continuation_end_marker(text: str, marker: str) -> bool:
Expand Down
22 changes: 22 additions & 0 deletions tests/unittest/test_table_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,28 @@ def test_merge_table_applies_caption_and_footnote_rules(
assert current_table.get("continues_prev", False) is expected


@pytest.mark.parametrize(
("current_caption", "expected"),
[
("续表 2-1 临床信息表", True),
("续表2-1 临床信息表", True),
("续上表 2-1 临床信息表", True),
("Continued table 2-1 Clinical information", True),
("CONTINUED TABLE A1 Clinical information", True),
("续表说明见正文", False),
("Continued table of contents", False),
("Previous table 2-1", False),
],
)
def test_merge_table_scopes_leading_continuation_markers(current_caption: str, expected: bool) -> None:
"""验证带编号的中英前置续表标记,并拒绝相似普通文字。"""
current_table = _table(1, children=[_caption(current_caption), _table_body(index=1)])

merge_table([_page(0, [_table(0)]), _page(1, [current_table])])

assert current_table.get("continues_prev", False) is expected


def test_post_table_non_continuation_caption_does_not_block_merge() -> None:
"""验证 table body 下方的非续表 caption 不参与阻断判断。"""
current_children = [
Expand Down