checkpoint: 提交当前工作区代码(同义词配置初版 + 既有流程改动)

- 新增 inq_synonym 表、62组同义词种子与智能体只读接口
- Python 同义词加载/归一化与 1板/2箱 机读
- 同步当前分支既有协作、报价识别、陆运等改动
This commit is contained in:
linmianxun
2026-11-24 16:26:49 +08:00
parent d9b2029c47
commit 04e00f0cfc
69 changed files with 7126 additions and 395 deletions
+106
View File
@@ -871,6 +871,112 @@ def extract_adjust(
)
# 调价尝试的粗筛词:只要句子里出现这些,就算销售在试图调价。
# 不能把「价格」「报价」单独放进来,否则「这个价格再谈谈」也会被当调价。
_ADJUST_ATTEMPT_HINTS = re.compile(
r"上调|下调|上涨|下降|上浮|下浮|提高|提升|降低|增加|减少|"
r"调整|改[成为到]|调到|涨到|升到|加到|减到|增至|变为|变成|"
r"加\s*\d|减\s*\d|\d+(?:\.\d+)?\s*[%%]|[一二三四五六七八九十]\s*成"
)
# 「加一成」的口语:一=10%,二=20%…十=100%。
_CHENG_NUM = {
"一": 10, "二": 20, "三": 30, "四": 40, "五": 50,
"六": 60, "七": 70, "八": 80, "九": 90, "十": 100,
}
def inspect_adjust_recognition(
text: str,
extract: AdjustExtract,
*,
fee_names: list[str] | None = None,
) -> Optional[dict[str, Any]]:
"""
判断这句话是不是调价尝试,以及识别程度。
返回 None:不像调价,调用方按原流程继续,禁止乱回调价提示。
返回 {"status": full/partial/none, "recognized": [...], "missing": [...]}。
「部分」= 有费用名没幅度、有幅度没费用名、或只写了「改成」没写值。
副作用:无。线程:纯函数。
"""
raw = (text or "").strip()
if not raw:
return None
names = [str(n).strip() for n in (fee_names or []) if str(n).strip()]
items = list(getattr(extract, "items", []) or [])
wants_total = bool(getattr(extract, "wants_total", False))
# 完整的调价:至少一项有值,且点名了费用(或明确只改总价)。
complete = bool(getattr(extract, "is_adjust", False)) and any(
float(it.value or 0) > 0
and (str(it.fee_name or "").strip() or wants_total)
for it in items
)
looks = bool(getattr(extract, "is_adjust", False)) or bool(
_ADJUST_ATTEMPT_HINTS.search(raw)
)
if not looks:
return None
if complete:
return {"status": "full", "recognized": [], "missing": []}
recognized: list[str] = []
missing: list[str] = []
hit_name = ""
for name in sorted(names, key=len, reverse=True):
if name and name in raw:
hit_name = name
break
if not hit_name:
for word in _TOTAL_WORDS:
if word in raw:
hit_name = word
break
if hit_name:
recognized.append(f"费用名:{hit_name}")
else:
missing.append("费用名")
pct = ""
for rx in (_PERCENT_UP, _PERCENT_DOWN, _PERCENT_TO):
hit = rx.search(raw)
if hit:
pct = hit.group(0).replace(" ", "")
break
if not pct:
cheng = re.search(r"([一二三四五六七八九十])\s*成", raw)
if cheng:
pct = f"{cheng.group(1)}成({_CHENG_NUM.get(cheng.group(1), '')}%)"
if pct:
recognized.append(f"调整幅度:{pct}")
else:
target = _TARGET.search(raw)
if target:
recognized.append(f"目标金额:{target.group(0).replace(' ', '')}")
else:
missing.append("调整幅度或目标金额")
direction = ""
if _PERCENT_DOWN.search(raw) or any(
x in raw for x in ("下调", "下降", "降低", "减", "降")
):
direction = "下调"
elif _PERCENT_UP.search(raw) or any(
x in raw
for x in ("上调", "上涨", "上升", "上浮", "提高", "提升", "加", "涨", "升")
):
direction = "上调"
elif re.search(r"改[成为到]|调整[到成]|调到", raw):
direction = "改为"
if direction:
recognized.append(f"调整方式:{direction}")
return {
"status": "partial" if recognized else "none",
"recognized": recognized,
"missing": list(dict.fromkeys(missing)),
}
def _local_fee_items(raw: str, names_sorted: list[str]) -> list[AdjustItem]:
"""按分句把点名费目/小计抽成调价项。提升/上调等口令都认。"""
items: list[AdjustItem] = []