feat(shipping-notice): 完善 XFA 模板映射与订单审核流程
- 统一 XFA 数据集、字段拆分、校验及运行时解析 - 完善订单模板管理、发布检查与迁移状态 - 优化订单审核草稿、预约回退及 STP 投影缓存 - 更新前端模板编辑器、映射组件与多语言错误文案 - 补充后端与前端测试,并更新本地集成启动配置
This commit is contained in:
1 parent
43a30a7489
commit
4ec436d44c
67 files changed
+5411
-528
No files matched your search
@@ -3,7 +3,7 @@ services/shipping_notice/document_layout/field_split_core.py
|
||||
|
||||
用途:共享的声明式字段拆分核心——承接 XFA(XML Forms Architecture)拆分引擎的纯文本执行能力,
|
||||
为 Vendor Comments / Coordinate Region 等非 XFA 数据源提供统一的 prefix / regex / position
|
||||
匹配、优先级仲裁、多规则冲突诊断、mapped/evidence_only 处理与规则内容指纹。
|
||||
匹配(position 支持连续多行合并)、优先级仲裁、多规则冲突诊断、mapped/evidence_only 处理与规则内容指纹。
|
||||
依赖:Pydantic 2、xfa_contract(复用 XfaContractModel 作为 Base Model 保持一致性)、
|
||||
xfa_safe_regex(危险正则黑名单、超时限制、最大捕获组校验)。
|
||||
逻辑:对外暴露 BaseSplit* 契约与 execute_base_split_rule_set() 执行入口;
|
||||
@@ -55,6 +55,7 @@ SPLIT_UNMATCHED_PRIORITY: Final[int] = 3
|
||||
|
||||
SplitHandling = Literal['mapped', 'evidence_only']
|
||||
SplitMatcherType = Literal['position', 'prefix', 'regex']
|
||||
SplitJoinWith = Literal['newline', 'space', 'comma']
|
||||
SplitSourceScope = Literal['header', 'line']
|
||||
SplitUnmatchedPolicy = Literal['evidence_only', 'needs_review']
|
||||
SplitDuplicatePolicy = Literal['needs_review']
|
||||
@@ -63,6 +64,12 @@ SplitRuleSource = Literal['system_suggestion', 'user', 'imported']
|
||||
RelationCaptureType = Literal['line_reference']
|
||||
RelationPolicyType = Literal['bind_target_line', 'annotation_only']
|
||||
|
||||
_JOIN_WITH_SEPARATORS: Final[dict[str, str]] = {
|
||||
'newline': '\n',
|
||||
'space': ' ',
|
||||
'comma': ', ',
|
||||
}
|
||||
|
||||
_SEGMENT_CODE_RE = re.compile(r'^[a-z][a-z0-9_]{1,63}$')
|
||||
|
||||
|
||||
@@ -190,15 +197,18 @@ class BaseSplitSegment(XfaContractModel):
|
||||
|
||||
class BaseSplitMatcher(XfaContractModel):
|
||||
"""
|
||||
共享单行匹配器:position / prefix / regex。
|
||||
共享匹配器:position(可连续多行)/ prefix / regex。
|
||||
优先级由引擎固定为 prefix > regex > position;契约仅声明字段形状。
|
||||
|
||||
position 可通过 line_end(含)与 join_with 合并连续多行;缺省时仍为单行。
|
||||
新增 relation_capture:当前仅 line_reference(Q2);XFA 链路当前不启用,
|
||||
但 Base 契约提前引入避免阶段 2 再次改造。
|
||||
"""
|
||||
|
||||
type: SplitMatcherType
|
||||
line_index: int | None = Field(default=None, ge=1, le=1000)
|
||||
line_end: int | None = Field(default=None, ge=1, le=1000)
|
||||
join_with: SplitJoinWith | None = None
|
||||
value: str | None = Field(default=None, max_length=SPLIT_MAX_PREFIX_LENGTH)
|
||||
separators: list[str] = Field(default_factory=lambda: [':', ':'])
|
||||
case_sensitive: bool = False
|
||||
@@ -216,6 +226,19 @@ class BaseSplitMatcher(XfaContractModel):
|
||||
if self.type == 'position':
|
||||
if self.line_index is None:
|
||||
raise ValueError('position matcher requires line_index (1-based)')
|
||||
# 单行保持 line_end=None,避免历史确认指纹漂移;连续多行才写入 line_end。
|
||||
if self.line_end is not None:
|
||||
if int(self.line_end) < int(self.line_index):
|
||||
raise ValueError('position matcher line_end must be >= line_index')
|
||||
if int(self.line_end) == int(self.line_index):
|
||||
object.__setattr__(self, 'line_end', None)
|
||||
object.__setattr__(self, 'join_with', None)
|
||||
elif self.join_with is None:
|
||||
object.__setattr__(self, 'join_with', 'newline')
|
||||
elif self.join_with not in _JOIN_WITH_SEPARATORS:
|
||||
raise ValueError('position matcher join_with must be newline/space/comma')
|
||||
else:
|
||||
object.__setattr__(self, 'join_with', None)
|
||||
elif self.type == 'prefix':
|
||||
label = str(self.value or '').strip()
|
||||
if not label:
|
||||
@@ -356,6 +379,7 @@ def base_split_content_fingerprint(rule_set: BaseSplitRuleSet | dict[str, Any])
|
||||
核心逻辑:只冻结 matcher、normalization 与 relation_capture 定义;
|
||||
segment 的 Schema 映射字段(handling/target_field_*)不属于拆分逻辑本身,
|
||||
后续绑定或解绑目标字段不得取消已确认状态。
|
||||
单行 position 的空 line_end/join_with 不进入指纹,避免新增可选字段导致历史令牌失效。
|
||||
|
||||
Args:
|
||||
rule_set: 模型或 dict。
|
||||
@@ -374,7 +398,16 @@ def base_split_content_fingerprint(rule_set: BaseSplitRuleSet | dict[str, Any])
|
||||
payload.pop('rule_version', None)
|
||||
payload.pop('rule_id', None)
|
||||
for rule in payload.get('rules') or []:
|
||||
segment = rule.get('segment') if isinstance(rule, dict) else None
|
||||
if not isinstance(rule, dict):
|
||||
continue
|
||||
matcher = rule.get('matcher')
|
||||
if isinstance(matcher, dict):
|
||||
# [STEP] 单行 position 不序列化空连续行字段,保持与升级前指纹兼容。
|
||||
if matcher.get('line_end') in (None, matcher.get('line_index')):
|
||||
matcher.pop('line_end', None)
|
||||
if not matcher.get('join_with'):
|
||||
matcher.pop('join_with', None)
|
||||
segment = rule.get('segment')
|
||||
if not isinstance(segment, dict):
|
||||
continue
|
||||
segment.pop('handling', None)
|
||||
@@ -445,7 +478,7 @@ class _CoreSplitEngineResult:
|
||||
|
||||
@dataclass
|
||||
class _LineMatch:
|
||||
"""单行候选命中(共享核心版,含 relation 捕获)。"""
|
||||
"""单行/连续多行候选命中(共享核心版,含 relation 捕获)。"""
|
||||
|
||||
rule: BaseSplitRule
|
||||
matcher_type: str
|
||||
@@ -453,9 +486,43 @@ class _LineMatch:
|
||||
line_text: str
|
||||
normalized_text: str
|
||||
raw_line: str
|
||||
line_end_no: int | None = None
|
||||
claimed_line_nos: tuple[int, ...] = ()
|
||||
captured_relation: CoreCapturedRelation | None = None
|
||||
|
||||
|
||||
def position_line_span(matcher: BaseSplitMatcher) -> tuple[int, int]:
|
||||
"""
|
||||
解析 position matcher 的起止行(1-based,含两端)。
|
||||
|
||||
Args:
|
||||
matcher: position 匹配器。
|
||||
|
||||
Returns:
|
||||
(line_start, line_end)。
|
||||
"""
|
||||
start = int(matcher.line_index or 0)
|
||||
end = int(matcher.line_end or start or 0)
|
||||
if end < start:
|
||||
end = start
|
||||
return start, end
|
||||
|
||||
|
||||
def join_position_lines(lines: list[str], join_with: str | None) -> str:
|
||||
"""
|
||||
按 join_with 合并连续多行文本。
|
||||
|
||||
Args:
|
||||
lines: 已按行号切好的原文行。
|
||||
join_with: newline / space / comma;缺省按换行合并。
|
||||
|
||||
Returns:
|
||||
合并后的文本。
|
||||
"""
|
||||
separator = _JOIN_WITH_SEPARATORS.get(str(join_with or 'newline'), '\n')
|
||||
return separator.join(lines)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# [STEP 3] 纯文本执行函数——从 XFA 拆分引擎原封不动迁移,保持字节级一致
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -599,9 +666,17 @@ def _match_line(
|
||||
line_no: int,
|
||||
line: str,
|
||||
rule: BaseSplitRule,
|
||||
*,
|
||||
inventory: list[str] | None = None,
|
||||
) -> tuple[_LineMatch | None, str | None]:
|
||||
"""
|
||||
判断单条规则是否命中指定行(共享核心版,支持 relation 捕获)。
|
||||
判断单条规则是否命中指定行(共享核心版,支持 relation 捕获与连续多行 position)。
|
||||
|
||||
Args:
|
||||
line_no: 当前行号(1-based)。
|
||||
line: 当前行文本。
|
||||
rule: 待匹配规则。
|
||||
inventory: 完整行清单;position 连续多行时用于合并起止范围内的文本。
|
||||
|
||||
Returns:
|
||||
(match, error_code):命中时 error_code 为 None;未命中时 match 为 None。
|
||||
@@ -612,16 +687,27 @@ def _match_line(
|
||||
return None, 'unknown_matcher'
|
||||
|
||||
if matcher.type == 'position':
|
||||
if int(matcher.line_index or 0) != line_no:
|
||||
start, end = position_line_span(matcher)
|
||||
if int(start) != line_no:
|
||||
return None, None
|
||||
normalized = line.strip() if line else ''
|
||||
lines = list(inventory or [])
|
||||
if not lines:
|
||||
lines = [line]
|
||||
if end > len(lines):
|
||||
return None, 'position_line_range_out_of_bounds'
|
||||
span_lines = lines[start - 1:end]
|
||||
joined_raw = join_position_lines(span_lines, matcher.join_with) if end > start else line
|
||||
normalized = joined_raw.strip() if joined_raw else ''
|
||||
claimed = tuple(range(start, end + 1))
|
||||
return _LineMatch(
|
||||
rule=rule,
|
||||
matcher_type='position',
|
||||
priority=priority,
|
||||
line_text=line,
|
||||
line_text=joined_raw,
|
||||
normalized_text=normalized,
|
||||
raw_line=line,
|
||||
raw_line=joined_raw,
|
||||
line_end_no=end,
|
||||
claimed_line_nos=claimed,
|
||||
), None
|
||||
|
||||
if matcher.type == 'prefix':
|
||||
@@ -635,6 +721,8 @@ def _match_line(
|
||||
line_text=line,
|
||||
normalized_text=extracted,
|
||||
raw_line=line,
|
||||
line_end_no=line_no,
|
||||
claimed_line_nos=(line_no,),
|
||||
), None
|
||||
|
||||
if matcher.type == 'regex':
|
||||
@@ -650,6 +738,8 @@ def _match_line(
|
||||
line_text=line,
|
||||
normalized_text=value,
|
||||
raw_line=line,
|
||||
line_end_no=line_no,
|
||||
claimed_line_nos=(line_no,),
|
||||
captured_relation=relation,
|
||||
), None
|
||||
|
||||
@@ -712,6 +802,7 @@ def execute_base_split_rule_set(
|
||||
核心逻辑:
|
||||
1. normalization.line_breaks 拆行;
|
||||
2. 逐行收集命中规则,按 prefix > regex > position 决出唯一 segment;
|
||||
position 可声明 line_end 合并连续多行,并一次性认领起止范围内行;
|
||||
3. 同优先级多个 mapped 命中 → duplicate_line_match / needs_review;
|
||||
4. 未认领行按 unmatched_line_policy;
|
||||
5. evidence_only 全部保留;
|
||||
@@ -741,15 +832,17 @@ def execute_base_split_rule_set(
|
||||
segments: list[_CoreSegmentResult] = []
|
||||
claimed_lines: set[int] = set()
|
||||
|
||||
# [STEP 1] 逐行匹配并按优先级决出胜出规则。
|
||||
# [STEP 1] 逐行匹配并按优先级决出胜出规则;连续多行 position 一次性认领范围。
|
||||
for line_no, line in enumerate(inventory, start=1):
|
||||
if line_no in claimed_lines:
|
||||
continue
|
||||
matches: list[_LineMatch] = []
|
||||
for rule in rule_set.rules:
|
||||
outcome, error = _match_line(line_no, line, rule)
|
||||
outcome, error = _match_line(line_no, line, rule, inventory=inventory)
|
||||
if error:
|
||||
diagnostics.append(CoreSplitDiagnostic(
|
||||
code=error,
|
||||
message=f'Rule {rule.rule_id} regex failed on line {line_no}',
|
||||
message=f'Rule {rule.rule_id} failed on line {line_no}',
|
||||
line_no=line_no,
|
||||
field_code=rule.segment.target_field_code,
|
||||
rule_ids=[rule.rule_id],
|
||||
@@ -762,7 +855,9 @@ def execute_base_split_rule_set(
|
||||
if winner is None:
|
||||
continue
|
||||
|
||||
claimed_lines.add(line_no)
|
||||
span = winner.claimed_line_nos or (line_no,)
|
||||
claimed_lines.update(span)
|
||||
line_end_no = winner.line_end_no or max(span)
|
||||
seg = winner.rule.segment
|
||||
status = 'parsed'
|
||||
if not str(winner.normalized_text).strip() and seg.handling == 'mapped':
|
||||
@@ -779,7 +874,7 @@ def execute_base_split_rule_set(
|
||||
segment_code=seg.segment_code,
|
||||
display_name=seg.display_name,
|
||||
line_no=line_no,
|
||||
line_end_no=line_no,
|
||||
line_end_no=line_end_no,
|
||||
raw_text=winner.raw_line,
|
||||
normalized_text=winner.normalized_text,
|
||||
handling=seg.handling,
|
||||
|
||||
@@ -147,6 +147,9 @@ class FieldRegion(OrderProfileModel):
|
||||
field_code: str = Field(pattern=r'^[a-z][a-z0-9_]{0,63}$')
|
||||
scope: Literal['header', 'line']
|
||||
region: RelativeRegion
|
||||
# 画布框稳定身份;XFA datasets binding.field_layout_id 优先引用本字段,
|
||||
# 避免仅用「行:field_code」时同名字段/复制框互相抢绑。
|
||||
region_id: str | None = Field(default=None, max_length=128)
|
||||
extractor_key: Literal['direct', 'temp_internal_parts', 'quantity_uom', 'amount_currency', 'price_currency'] = 'direct'
|
||||
allowed_sources: list[Literal['pdf_coordinate', 'ocr_coordinate']] = Field(min_length=1)
|
||||
minimum_evidence_level: Literal['coordinate', 'ocr_coordinate'] = 'coordinate'
|
||||
|
||||
@@ -602,6 +602,7 @@ def rebuild_tree_dto_from_analysis(
|
||||
pdf_bytes: bytes,
|
||||
*,
|
||||
include_values: bool = False,
|
||||
include_full_values: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
按需从 PDF 重建字段树 DTO(管理员 API 用,不持久化 XML)。
|
||||
@@ -610,6 +611,7 @@ def rebuild_tree_dto_from_analysis(
|
||||
analysis: 已有结构分析记录。
|
||||
pdf_bytes: 原始 PDF 字节。
|
||||
include_values: 是否包含脱敏值。
|
||||
include_full_values: 是否写入完整 sample_value_display(需上游权限门禁)。
|
||||
|
||||
Returns:
|
||||
字段树 DTO。
|
||||
@@ -618,7 +620,15 @@ def rebuild_tree_dto_from_analysis(
|
||||
if outcome.dataset_analysis is None:
|
||||
return project_field_tree(analysis, include_values=include_values)
|
||||
root = outcome.dataset_analysis.nodes[0] if outcome.dataset_analysis.nodes else None
|
||||
tree = serialize_tree_node(root, include_values=include_values) if root else {}
|
||||
tree = (
|
||||
serialize_tree_node(
|
||||
root,
|
||||
include_values=include_values,
|
||||
include_full_values=include_full_values,
|
||||
)
|
||||
if root
|
||||
else {}
|
||||
)
|
||||
return sanitize_xfa_dto({
|
||||
'analysis_id': analysis.id,
|
||||
'document_kind': analysis.document_kind,
|
||||
@@ -626,4 +636,5 @@ def rebuild_tree_dto_from_analysis(
|
||||
'tree': tree,
|
||||
'header_candidates': outcome.dataset_analysis.header_candidates,
|
||||
'stats': outcome.dataset_analysis.stats,
|
||||
'full_values_revealed': bool(include_full_values),
|
||||
})
|
||||
@@ -679,8 +679,8 @@ class OrderXfaDatasetProfile(XfaContractModel):
|
||||
raise ValueError('field_layout_id must reference an order_field_layouts entry')
|
||||
layout_field_code = str(layout.get('field_code') or '')
|
||||
if layout_field_code != binding.field_code:
|
||||
# 一个多行源值(MATNR)可以通过已确认拆分规则产出多个行字段。
|
||||
# 每个目标仍指向同一个真实 MATNR 框,避免伪造重叠视觉框。
|
||||
# 同一 datasets 源字段经已确认拆分规则可产出多个行字段。
|
||||
# 每个目标仍指向同一个真实视觉框,避免伪造重叠框。
|
||||
split_ref = binding.split_rule_ref
|
||||
segment = split_segments.get(str(split_ref.segment_id)) if split_ref else None
|
||||
is_split_target_visual_reuse = bool(
|
||||
|
||||
@@ -559,13 +559,20 @@ def read_collection_rows(
|
||||
return rows
|
||||
|
||||
|
||||
def serialize_tree_node(node: XfaDatasetNode, *, include_values: bool = False) -> dict[str, Any]:
|
||||
def serialize_tree_node(
|
||||
node: XfaDatasetNode,
|
||||
*,
|
||||
include_values: bool = False,
|
||||
include_full_values: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
序列化单个树节点供 API 返回。
|
||||
|
||||
Args:
|
||||
node: 数据集树节点。
|
||||
include_values: 是否包含受控的样本展示值;不得暴露 raw_value。
|
||||
include_values: 是否包含受控的样本展示值;默认不得暴露 raw_value。
|
||||
include_full_values: 为 True 时把内存 raw_value 写入 sample_value_display
|
||||
(仅供已鉴权的映射台 reveal 路径;仍不输出 raw_value 键)。
|
||||
|
||||
Returns:
|
||||
安全 DTO 字典。
|
||||
@@ -580,16 +587,30 @@ def serialize_tree_node(node: XfaDatasetNode, *, include_values: bool = False) -
|
||||
'is_leaf': node.is_leaf,
|
||||
'is_header_candidate': node.is_header_candidate,
|
||||
'is_collection_candidate': node.is_collection_candidate,
|
||||
'children': [serialize_tree_node(child, include_values=include_values) for child in node.children],
|
||||
'children': [
|
||||
serialize_tree_node(
|
||||
child,
|
||||
include_values=include_values,
|
||||
include_full_values=include_full_values,
|
||||
)
|
||||
for child in node.children
|
||||
],
|
||||
}
|
||||
if include_values and node.is_leaf:
|
||||
# 字段树是批量 DTO:即使管理端需要映射辅助,也绝不能把 datasets
|
||||
# 原文放入可缓存/可下载的树响应。完整值只能经单值受控读取与审计接口取得。
|
||||
# 默认批量树只给脱敏/分级展示;完整值须经 reveal + 敏感读权限,且不输出 raw_value 键。
|
||||
payload['sample_value_masked'] = str(node.sample_value_masked or '')
|
||||
payload['sample_value_display'] = str(node.sample_value_display or '')
|
||||
payload['display_policy'] = str(node.display_policy or 'empty')
|
||||
payload['can_reveal'] = bool(node.can_reveal)
|
||||
payload['line_count'] = len(node.lines or [])
|
||||
raw = str(node.raw_value or '')
|
||||
if include_full_values and raw:
|
||||
payload['sample_value_display'] = raw
|
||||
payload['display_policy'] = 'full'
|
||||
payload['can_reveal'] = False
|
||||
payload['full_value_revealed'] = True
|
||||
else:
|
||||
payload['sample_value_display'] = str(node.sample_value_display or '')
|
||||
payload['display_policy'] = str(node.display_policy or 'empty')
|
||||
payload['can_reveal'] = bool(node.can_reveal)
|
||||
payload['full_value_revealed'] = False
|
||||
return payload
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ backend/app/services/shipping_notice/document_layout/xfa_profile_extraction.py
|
||||
order_profile_extractors。
|
||||
逻辑:由 order_extraction_workflow XFA 分支在精确命中后调用;正式提取仅读 bindings[],
|
||||
无 bindings 或仍含 header_mappings/line_mapping.fields 时 fail-closed;
|
||||
header 带 split_rule_ref 的目标跳过 STEP1 直读,仅由拆分规则产出(与 line 对齐);
|
||||
类型/normalizer/validator 取自 schema_fields;失败由上层回退坐标/OCR/通用。
|
||||
"""
|
||||
|
||||
@@ -574,10 +575,12 @@ def extract_xfa_profile(
|
||||
header_bindings = _bindings_for_scope(profile, 'header')
|
||||
line_bindings = _bindings_for_scope(profile, 'line')
|
||||
|
||||
# [STEP 1] Header bindings
|
||||
# [STEP 1] Header bindings:带 split_rule_ref 的目标由后续拆分产出,禁止再读源全文。
|
||||
header_fields: list[XfaExtractedField] = []
|
||||
header_issues: list[str] = []
|
||||
for binding in header_bindings:
|
||||
if binding.split_rule_ref is not None:
|
||||
continue
|
||||
data_path = str(binding.value_binding.data_path or '')
|
||||
value_type, normalizer_key, validator_key = _schema_metadata_for_field(
|
||||
schema_fields=schema_fields,
|
||||
|
||||
@@ -8,6 +8,7 @@ services/shipping_notice/document_layout/xfa_split_rule_contract.py
|
||||
BaseSplitSegment / BaseSplitRule / BaseSplitRuleSet)。
|
||||
逻辑:仅声明式校验,不执行规则、不读 PDF、不接网络;非法契约以 ValidationError
|
||||
或 ValueError 拒绝;匹配优先级由引擎固定 prefix > regex > position > unmatched;
|
||||
position 支持 line_end + join_with 合并连续多行;
|
||||
XfaSplit* 系列继承共享核心 BaseSplit*,但保留 XFA 专属字段(source_path_id /
|
||||
source_data_path 等)和 XFA 前缀的环境变量读取,保持对外行为零漂移。
|
||||
"""
|
||||
@@ -195,14 +196,17 @@ class XfaSplitPostProcessor(XfaContractModel):
|
||||
|
||||
class XfaSplitMatcher(BaseSplitMatcher):
|
||||
"""
|
||||
单行匹配器:position / prefix / regex。
|
||||
匹配器:position(可连续多行)/ prefix / regex。
|
||||
|
||||
优先级由引擎固定为 prefix > regex > position;契约仅声明字段形状。
|
||||
继承共享核心 BaseSplitMatcher;保留 XFA 自己的校验器与 XFA_ 前缀长度常量。
|
||||
position 可通过 line_end(含)与 join_with 合并连续多行。
|
||||
"""
|
||||
|
||||
type: XfaSplitMatcherType
|
||||
line_index: int | None = Field(default=None, ge=1, le=1000)
|
||||
line_end: int | None = Field(default=None, ge=1, le=1000)
|
||||
join_with: Literal['newline', 'space', 'comma'] | None = None
|
||||
value: str | None = Field(default=None, max_length=XFA_SPLIT_MAX_PREFIX_LENGTH)
|
||||
separators: list[str] = Field(default_factory=lambda: [':', ':'])
|
||||
case_sensitive: bool = False
|
||||
@@ -220,6 +224,19 @@ class XfaSplitMatcher(BaseSplitMatcher):
|
||||
if self.type == 'position':
|
||||
if self.line_index is None:
|
||||
raise ValueError('position matcher requires line_index (1-based)')
|
||||
# 单行保持 line_end=None,避免历史确认指纹漂移;连续多行才写入 line_end。
|
||||
if self.line_end is not None:
|
||||
if int(self.line_end) < int(self.line_index):
|
||||
raise ValueError('position matcher line_end must be >= line_index')
|
||||
if int(self.line_end) == int(self.line_index):
|
||||
object.__setattr__(self, 'line_end', None)
|
||||
object.__setattr__(self, 'join_with', None)
|
||||
elif self.join_with is None:
|
||||
object.__setattr__(self, 'join_with', 'newline')
|
||||
elif self.join_with not in {'newline', 'space', 'comma'}:
|
||||
raise ValueError('position matcher join_with must be newline/space/comma')
|
||||
else:
|
||||
object.__setattr__(self, 'join_with', None)
|
||||
elif self.type == 'prefix':
|
||||
label = str(self.value or '').strip()
|
||||
if not label:
|
||||
@@ -374,6 +391,7 @@ def split_rule_content_fingerprint(rule_set: XfaSplitRuleSet | dict[str, Any]) -
|
||||
|
||||
核心逻辑:只冻结 matcher 与 normalization;segment 的 Schema 映射字段不属于拆分逻辑,
|
||||
后续绑定或解绑目标字段不得取消已确认状态。
|
||||
单行 position 的空 line_end/join_with 不进入指纹,避免新增可选字段导致历史令牌失效。
|
||||
|
||||
【重要】:XFA 版指纹实现独立保留,不直接调用共享核心 base_split_content_fingerprint。
|
||||
原因:未来若共享核心为 Vendor Comments 增加 relation_capture 字段纳入指纹计算,
|
||||
@@ -399,7 +417,15 @@ def split_rule_content_fingerprint(rule_set: XfaSplitRuleSet | dict[str, Any]) -
|
||||
# 将同一规则对象交给 normalize/save,原地 pop 会使已确认草稿不可再次编辑。
|
||||
payload = json.loads(json.dumps(payload))
|
||||
for rule in payload.get('rules') or []:
|
||||
segment = rule.get('segment') if isinstance(rule, dict) else None
|
||||
if not isinstance(rule, dict):
|
||||
continue
|
||||
matcher = rule.get('matcher')
|
||||
if isinstance(matcher, dict):
|
||||
if matcher.get('line_end') in (None, matcher.get('line_index')):
|
||||
matcher.pop('line_end', None)
|
||||
if not matcher.get('join_with'):
|
||||
matcher.pop('join_with', None)
|
||||
segment = rule.get('segment')
|
||||
if not isinstance(segment, dict):
|
||||
continue
|
||||
segment.pop('handling', None)
|
||||
|
||||
@@ -385,6 +385,7 @@ def _validate_acroform(
|
||||
核心逻辑:
|
||||
- 允许展示格式不同,标准化后必须相同;
|
||||
- 明细按 AcroForm 同名多实例下标与提取行一一对应,禁止“全行扫到首个 field_code”;
|
||||
- 带 split_rule_ref 的 binding(表头/明细)跳过源 Widget 全文对账,正式值由拆分产出;
|
||||
- 无 Fields / 无重叠字段 → unavailable;仅部分字段可对 → partial;冲突 → mismatched。
|
||||
|
||||
Returns:
|
||||
@@ -405,10 +406,12 @@ def _validate_acroform(
|
||||
missing_counterpart = 0
|
||||
mismatches: list[dict[str, Any]] = []
|
||||
|
||||
# [STEP 1] Header:每个 binding 对应短名的首个 AcroForm 实例。
|
||||
# [STEP 1] Header:每个 binding 对应短名的首个 AcroForm 实例;拆分目标跳过源全文对账。
|
||||
for binding in profile.bindings:
|
||||
if binding.scope != 'header':
|
||||
continue
|
||||
if binding.split_rule_ref is not None:
|
||||
continue
|
||||
data_path = str(binding.value_binding.data_path or '')
|
||||
local = data_path.rsplit('/', 1)[-1].upper()
|
||||
acro_values = by_name.get(local) or []
|
||||
|
||||
Reference in new issue
Block a user