fix(shipping-notice): 重识别 Run 终态激活 Case 并收紧裸数字兜底口径
- 修复重解析延迟激活钩子未接线:Run 终态原子激活可复核 Case 为文件 Stream 当前版本,工作台队列不再空白 - 新增 run_is_reparse_successor_of_case 判定 Case 与重解析 Run 的后继关系 - 裸数字兜底口径收紧:仅扫「整格恰好 5/10 位纯数字」的正文 HTML 表格单元格,自由文本与带前后字符的值一律不取,防误绑签名与邮编 - 新增客户 PO 匹配变体集合(原值/归一/去前导零)纳入排除集,补充合并末段裁决更准 - 同步预约号启发式测试,business/technical 文档记录收紧决策
This commit is contained in:
1 parent
1efb165fd5
commit
e78f750db0
9 files changed
+208
-98
No files matched your search
@@ -77,68 +77,60 @@ def _reservation_observation(order: dict):
|
||||
|
||||
# ---------------------------------------------------------------- 候选扫描
|
||||
|
||||
def test_scan_finds_bare_reservation_in_headerless_row():
|
||||
"""截图 1:无表头数据行只识别 4000122230;仓库/料号/日期/供应商号不误报。"""
|
||||
row = 'DBS SLC 4000122230 6233 504-006075-001 D4-AR1200163A1 Welltrust 10/13/2026'
|
||||
candidates = find_bare_numeric_reservation_candidates(body_text=row, content_hash='h')
|
||||
# 断言:仅 10 位纯数字 4000122230 入选;4 位站点号、带连字符料号、日期均被长度/边界挡住。
|
||||
assert [item['value'] for item in candidates] == ['4000122230']
|
||||
assert candidates[0]['evidence']['row_index'] == 1
|
||||
assert candidates[0]['evidence']['cell_id'].startswith('reservation-heuristic:h:line')
|
||||
def test_scan_finds_bare_reservation_in_headerless_table_row():
|
||||
"""截图场景:无表头数据表只识别整格纯数字的 39739;PO 整格入选由合并端排除。"""
|
||||
html = (
|
||||
'<table><tr><td>DBS PHX01</td><td>39739</td><td>6233</td>'
|
||||
'<td>504-006055-001</td><td>D4-A08AR12000002</td><td>WEL</td>'
|
||||
'<td>10/12/2026</td><td>120</td><td>1000053286</td></tr></table>'
|
||||
)
|
||||
candidates = find_bare_numeric_reservation_candidates(html_tables=[html], content_hash='h')
|
||||
# 断言:仅两个整格纯数字入选——预约号 39739 与 PO 1000053286(10 位同样合规,
|
||||
# 由合并端用已提取 PO 字段值/主题标签排除);仓库/料号/日期/数量格一概不取。
|
||||
assert [item['value'] for item in candidates] == ['39739', '1000053286']
|
||||
evidence = candidates[0]['evidence']
|
||||
# 断言:DOM 级证据齐全,可回溯到具体表格/行/列。
|
||||
assert evidence['table_index'] == 0
|
||||
assert evidence['row_index'] == 0 and evidence['column_index'] == 1
|
||||
assert evidence['cell_id'].startswith('reservation-heuristic:h:0')
|
||||
|
||||
|
||||
def test_scan_finds_five_digit_reservation():
|
||||
"""截图 3:5 位候选 39739 同样可识别。"""
|
||||
row = 'DBS PHX01 39739 6233 504-006055-001 D4-A08AR12000002 WEL 10/12/2026'
|
||||
candidates = find_bare_numeric_reservation_candidates(body_text=row, content_hash='h')
|
||||
def test_scan_ignores_cells_with_any_surrounding_content():
|
||||
"""收紧规则:邮编地址、带字母/备注前后的值一律不取(07094/00410 误报修复)。"""
|
||||
html = (
|
||||
'<table><tr>'
|
||||
'<td>Secaucus, NJ 07094</td>'
|
||||
'<td>T00410</td>'
|
||||
'<td>00410-CN</td>'
|
||||
'<td>39739 (A)</td>'
|
||||
'<td> 39739 </td>'
|
||||
'<td>35354-1</td>'
|
||||
'</tr></table>'
|
||||
)
|
||||
candidates = find_bare_numeric_reservation_candidates(html_tables=[html], content_hash='h')
|
||||
# 断言:只有去除首尾空白后恰好为纯数字的整格幸存(39739);
|
||||
# 07094 藏在地址文本里、00410 带字母前后、39739 带备注、35354-1 带后缀,全部排除。
|
||||
assert [item['value'] for item in candidates] == ['39739']
|
||||
|
||||
|
||||
def test_scan_rejects_labeled_context_and_wrong_lengths():
|
||||
"""标签上下文(PO/Invoice/Qty/紧凑 PO12345)排除;4/6/11/13 位数字不入选。"""
|
||||
text = (
|
||||
'PO# 1000053337\n'
|
||||
'Purchase Order : 1000053286\n'
|
||||
'Invoice 1234567890\n'
|
||||
'Qty 10000\n'
|
||||
'PO39739\n'
|
||||
'ref 1234 123456 12345678901 1234567890123\n'
|
||||
'valid 4000122230'
|
||||
)
|
||||
candidates = find_bare_numeric_reservation_candidates(body_text=text, content_hash='h')
|
||||
# 断言:只有裸露的 10 位 4000122230 幸存;带标签数字与错误长度全部排除。
|
||||
assert [item['value'] for item in candidates] == ['4000122230']
|
||||
|
||||
|
||||
def test_scan_accepts_short_numeric_suffix_form():
|
||||
"""35354-1 短行序后缀形态:本体 35354 作为候选(归一由合并端处理)。"""
|
||||
candidates = find_bare_numeric_reservation_candidates(body_text='IR# 35354-1', content_hash='h')
|
||||
# 断言:35354 后跟 "-"(非数字)满足边界;IR# 标签不在排除标签清单内。
|
||||
assert [item['value'] for item in candidates] == ['35354']
|
||||
def test_scan_returns_nothing_without_html_tables():
|
||||
"""收紧规则:正文无 HTML 表格时不做兜底,纯文本中的数字不再是候选来源。"""
|
||||
assert find_bare_numeric_reservation_candidates(html_tables=[], content_hash='h') == []
|
||||
assert find_bare_numeric_reservation_candidates(html_tables=None, content_hash='h') == []
|
||||
|
||||
|
||||
def test_scan_dedupes_and_caps_candidates():
|
||||
"""同值只留首个证据;候选总数截断到上限,防止引用链刷爆快照。"""
|
||||
text = '\n'.join(['4000122230'] + [f'{30000 + index}' for index in range(30)])
|
||||
candidates = find_bare_numeric_reservation_candidates(body_text=text, content_hash='h')
|
||||
values = [item['value'] for item in candidates]
|
||||
# 断言:30 个不同 5 位数字 + 1 个 10 位数字共 31 个 token,但只保留前 20 个。
|
||||
assert len(values) == 20
|
||||
assert values.count('4000122230') == 1
|
||||
|
||||
|
||||
def test_scan_uses_dom_cell_evidence_for_html_tables():
|
||||
"""HTML 表格单元格候选携带 DOM 级 cell_id,供复核证据回溯。"""
|
||||
html = '<table><tr><td>1000053337</td><td>4000122230</td></tr></table>'
|
||||
candidates = find_bare_numeric_reservation_candidates(
|
||||
body_text='', html_tables=[html], content_hash='dom123',
|
||||
"""同值只留首个证据;候选总数截断到上限,防止大表刷爆快照。"""
|
||||
cells = '<td>4000122230</td><td>4000122230</td>' + ''.join(
|
||||
f'<td>{30000 + index}</td>' for index in range(25)
|
||||
)
|
||||
assert [item['value'] for item in candidates] == ['1000053337', '4000122230']
|
||||
# 断言:表格路径证据含 table_index/column_index/cell_id(DOM 定位),无 context 片段。
|
||||
evidence = candidates[1]['evidence']
|
||||
assert evidence['table_index'] == 0
|
||||
assert evidence['column_index'] == 1
|
||||
assert evidence['cell_id'].startswith('reservation-heuristic:dom123:0')
|
||||
html = f'<table><tr>{cells}</tr></table>'
|
||||
candidates = find_bare_numeric_reservation_candidates(html_tables=[html], content_hash='h')
|
||||
values = [item['value'] for item in candidates]
|
||||
# 断言:重复格只保留首个证据;总数截断到 20(1 个 10 位 + 前 19 个 5 位)。
|
||||
assert len(values) == 20
|
||||
assert values[0] == '4000122230'
|
||||
assert values.count('4000122230') == 1
|
||||
|
||||
|
||||
def test_labeled_context_helper_extracts_subject_po():
|
||||
|
||||
Reference in new issue
Block a user