fix: 修正规格摘要误判颜色标题 (#277)
This commit is contained in:
@@ -172,23 +172,29 @@ def _screen_bounds(root: ET.Element) -> Optional[Bounds]:
|
||||
return 0, 0, max(item[2] for item in bounds), max(item[3] for item in bounds)
|
||||
|
||||
|
||||
def _spec_heading_name(value: str) -> str:
|
||||
"""返回独立规格标题,排除“请选择”“选择后”等摘要和提示。"""
|
||||
|
||||
compact = re.sub(r"\s+", "", str(value or ""))
|
||||
compact = re.sub(r"[((]\d+[))]$", "", compact)
|
||||
supported = _COLOR_HEADINGS + _PACKAGE_HEADINGS
|
||||
return compact if compact in supported else ""
|
||||
|
||||
|
||||
def _heading_bounds(root: ET.Element) -> Optional[Bounds]:
|
||||
fuzzy_match: Optional[Bounds] = None
|
||||
package_fallback: Optional[Bounds] = None
|
||||
for node in root.iter("node"):
|
||||
text = node.get("text", "").strip()
|
||||
heading = _spec_heading_name(node.get("text", ""))
|
||||
bounds = _parse_bounds(node.get("bounds", ""))
|
||||
if bounds is None or not _is_available(node):
|
||||
if not heading or bounds is None or not _is_available(node):
|
||||
continue
|
||||
|
||||
# “请选择:颜色分类 尺码”等摘要不能当成颜色列表标题。
|
||||
if text == "颜色分类":
|
||||
if heading == "颜色分类":
|
||||
return bounds
|
||||
if fuzzy_match is None and any(heading in text for heading in _COLOR_HEADINGS):
|
||||
if fuzzy_match is None and heading in _COLOR_HEADINGS:
|
||||
fuzzy_match = bounds
|
||||
if package_fallback is None and any(
|
||||
heading in text for heading in _PACKAGE_HEADINGS
|
||||
):
|
||||
if package_fallback is None and heading in _PACKAGE_HEADINGS:
|
||||
package_fallback = bounds
|
||||
# “款式 + 套餐”优先定位款式;只有套餐一个维度时才用套餐兜底。
|
||||
return fuzzy_match or package_fallback
|
||||
|
||||
Reference in New Issue
Block a user