隔离美国报价口径,完善条件更正和订单分页

This commit is contained in:
2026-11-05 15:11:06 +08:00
parent f777867749
commit 97ec6ed44b
19 changed files with 548 additions and 81 deletions
+10 -4
View File
@@ -147,6 +147,10 @@ def parse_shipping_intent(text):
dl = re.search(r"长(\d+(?:\.\d+)?)宽(\d+(?:\.\d+)?)高(\d+(?:\.\d+)?)", t)
if dl:
intent["dims"] = [float(x) for x in dl.groups()]
else:
dl = re.search(r"(\d+(?:\.\d+)?)长(\d+(?:\.\d+)?)宽(\d+(?:\.\d+)?)高", t)
if dl:
intent["dims"] = [float(x) for x in dl.groups()]
# 重量:带单位的数字。去掉空格后在原始文本上匹配,
# 但不能把尺寸里的数字(如 120*100*100 的第三个数)当成重量
@@ -177,20 +181,22 @@ def parse_shipping_intent(text):
return intent
def detect_dim_unit(text):
"""识别尺寸单位:cm(默认)/ m / mm"""
"""Recognize explicit dimensions; aggregate CBM does not imply meters."""
low = text.lower()
if re.search(r'英寸|\binch(?:es)?(?![A-Za-z])|\d\s*in(?![A-Za-z0-9])|\d\s*["″]',low):
return 'in'
if re.search(r"毫米|\d\s*mm", low):
return "mm"
if re.search(r"米", low) and not re.search(r"厘米", low):
return "m"
if re.search(r"\d\s*cm|\d\s*厘米", low):
return "cm"
if re.search(r"\d\s*m", low): # 注意:cm 里也含 m,所以放在 cm 之后判断
if re.search(r"\d\s*(?:m(?![A-Za-z0-9²³])|米)", low):
return "m"
return "cm"
def dims_to_cm(dims, unit):
"""统一换算成厘米,体积重公式按 cm 计算"""
if unit == 'in':
return [d * 2.54 for d in dims]
if unit == "m":
return [d * 100 for d in dims]
if unit == "mm":