checkpoint: 提交当前工作区代码(同义词配置初版 + 既有流程改动)
- 新增 inq_synonym 表、62组同义词种子与智能体只读接口 - Python 同义词加载/归一化与 1板/2箱 机读 - 同步当前分支既有协作、报价识别、陆运等改动
This commit is contained in:
@@ -621,6 +621,20 @@ def harvest_oral_measures(text: str, facts: dict[str, str] | None = None) -> dic
|
||||
pack = _harvest_packaging(raw)
|
||||
if pack:
|
||||
merged["包装方式"] = pack
|
||||
# 「1板 / 2箱 / 3托」:件数保留原文,包装方式写标准值。
|
||||
# 主账不可用时用内置兜底;异常不能挡住询价。
|
||||
try:
|
||||
from agent.policy.synonym import harvest_package_count
|
||||
|
||||
package_count = harvest_package_count(raw)
|
||||
except Exception:
|
||||
package_count = {}
|
||||
if package_count:
|
||||
if not str(merged.get("件数") or "").strip():
|
||||
merged["件数"] = str(package_count.get("件数") or "")
|
||||
std_pack = str(package_count.get("包装方式") or "").strip()
|
||||
if std_pack:
|
||||
merged["包装方式"] = std_pack
|
||||
labeled_date = _quote_date_labeled_value(raw)
|
||||
if labeled_date:
|
||||
merged["报价日期"] = labeled_date
|
||||
@@ -978,25 +992,58 @@ def _pricing_required_keys(
|
||||
|
||||
_PLACE_KEYS = ("起运港", "目的港")
|
||||
_PACK_IN_PLACE = ("散货", "纸箱", "木箱", "托盘", "卡板", "木托")
|
||||
_PRICE_TAIL = re.compile(r"(的价格|的报价|价格|报价)$")
|
||||
# 地名后面紧贴的运费词:「目的地北京运输费」「吉隆坡运费」。
|
||||
# 运费词是销售在说「查这段运费」,不是地名。只剥运输/空运/陆运/货运的「…费」和
|
||||
# 「运费」,不能把「操作费」「文件费」剥成「操作」「文件」当地名。
|
||||
# 不把「海运」整词列进来:地名为「上海」时,上海运费必须先剥「运费」变上海,
|
||||
# 不能剥「海运费」只剩下「上」。剥完只剩「海/空/陆/货」的,按纯运费词丢。
|
||||
_RE_PLACE_FEE_TAIL = re.compile(
|
||||
r"(?:(?:运输|空运|陆运|货运)费(?:用)?|运费(?:用)?|(?:的)?(?:价格|报价|询价|查价))$"
|
||||
)
|
||||
_PLACE_FEE_REMNANTS = frozenset(
|
||||
{"海", "空", "陆", "货", "运", "空运", "海运", "陆运", "货运", "运输"}
|
||||
)
|
||||
|
||||
|
||||
def strip_place_fee_tail(raw: str) -> str:
|
||||
"""
|
||||
地名后面贴的运费词剥掉,只留地名:北京运输费 → 北京、上海运费 → 上海。
|
||||
|
||||
「运输费用」「运费」「的价格」「报价」可连续出现,剥到不变为止。
|
||||
整段就是运费词时返回空串,调用方按费用栏丢掉。
|
||||
不剥「操作费」「文件费」:那不是地名的尾巴,调用方仍会整段丢弃。
|
||||
副作用:无。
|
||||
"""
|
||||
text = (raw or "").strip()
|
||||
while text:
|
||||
cleaned = _RE_PLACE_FEE_TAIL.sub("", text).strip(" \t,,。;;、::")
|
||||
if cleaned == text:
|
||||
break
|
||||
text = cleaned
|
||||
return "" if text in _PLACE_FEE_REMNANTS else text
|
||||
|
||||
|
||||
def peel_trailing_place_clauses(facts: dict[str, str] | None) -> dict[str, str]:
|
||||
"""
|
||||
起运地/目的地只留逗号前的地名。
|
||||
起运地/目的地只留逗号前的地名,并剥掉贴在地名后的运费词。
|
||||
|
||||
口语「目的地吉隆坡,普货,散货的价格」会被抽成一整串目的地。
|
||||
逗号后面的品名、包装、价格不是地名,拆回去;已有品名/包装不覆盖。
|
||||
「目的地北京运输费」没有逗号时也要剥成北京,否则会被当成整段费用丢掉。
|
||||
"""
|
||||
merged = dict(facts or {})
|
||||
for key in _PLACE_KEYS:
|
||||
raw = (merged.get(key) or "").strip()
|
||||
parts = [p.strip() for p in re.split(r"[,,、]", raw) if p.strip()]
|
||||
if len(parts) <= 1:
|
||||
if not raw:
|
||||
continue
|
||||
place = parts[0]
|
||||
parts = [p.strip() for p in re.split(r"[,,、]", raw) if p.strip()]
|
||||
if not parts:
|
||||
merged.pop(key, None)
|
||||
continue
|
||||
# 地名本身也剥运费词:「北京运输费」不留逗号也照样只留北京。
|
||||
place = strip_place_fee_tail(parts[0])
|
||||
for part in parts[1:]:
|
||||
part = _PRICE_TAIL.sub("", part).strip()
|
||||
part = strip_place_fee_tail(part)
|
||||
if not part or part in {"价格", "报价", "查价"}:
|
||||
continue
|
||||
if part in _PACK_IN_PLACE and not (merged.get("包装方式") or "").strip():
|
||||
@@ -1004,7 +1051,11 @@ def peel_trailing_place_clauses(facts: dict[str, str] | None) -> dict[str, str]:
|
||||
continue
|
||||
if not (merged.get("品名") or "").strip() and not looks_like_container_spec(part):
|
||||
merged["品名"] = part
|
||||
merged[key] = place
|
||||
if place:
|
||||
merged[key] = place
|
||||
else:
|
||||
# 整段就是「运输费/价格」时,这一栏其实是空的,不能当地名往下查价。
|
||||
merged.pop(key, None)
|
||||
return merged
|
||||
|
||||
|
||||
|
||||
@@ -59,6 +59,12 @@ MAX_OPTIONS_PER_QUESTION = 10
|
||||
# 点卡回调靠它认出「这是陆运补问卡」,不按书签里残留的其它运输线去猜。
|
||||
CARD_KIND = "land_options"
|
||||
|
||||
# 多段联运里的陆运补问卡。卡种必须独立:
|
||||
# 回调路由按 task_id 认卡种,普通 land_options 归单聊陆运;
|
||||
# 多段这张要回多段草稿,否则会被单聊陆运当成过期卡或另开一单。
|
||||
# 提交按钮仍复用 land_options_submit,动作枚举不用再加一条。
|
||||
MULTI_CARD_KIND = "multi_land_options"
|
||||
|
||||
# 合并后的两个问题键。回调按 QuestionKey 原样回传,必须与出卡一致。
|
||||
QUESTION_BIZ = "biz_type"
|
||||
QUESTION_SCENARIO = "quote_scenario"
|
||||
@@ -258,6 +264,7 @@ def land_option_card_payload(
|
||||
facts: Mapping[str, Any] | None = None,
|
||||
note: str = "",
|
||||
cargo_missing: Optional[bool] = None,
|
||||
card_kind: str = CARD_KIND,
|
||||
) -> Optional[dict[str, Any]]:
|
||||
"""
|
||||
陆运补问卡载荷(业务类型 + 报价场景 两项)。
|
||||
@@ -270,6 +277,8 @@ def land_option_card_payload(
|
||||
cargo_missing 货物品名是否还缺。缺就把它排进「待补充」清单里一起说,
|
||||
不再单独写一句「提交后回复货物品名」。
|
||||
传 None(默认)时按 facts 里的品名自动判断,调用方忘了传也不会漏。
|
||||
card_kind 卡种前缀。单聊陆运用默认值;多段联运传 MULTI_CARD_KIND,
|
||||
回调按 task_id 认回多段草稿。
|
||||
|
||||
返回:企微 template_card 载荷;两种情况返回 None,由调用方回落到文字:
|
||||
1. 两项都齐、只缺品名——卡片收不了自由文字,空卡只会让销售白点一次提交;
|
||||
@@ -332,7 +341,7 @@ def land_option_card_payload(
|
||||
"template_card": {
|
||||
"card_type": "multiple_interaction",
|
||||
"source": {"desc": "陆运补问", "desc_color": 0},
|
||||
"task_id": copy.card_task_id(CARD_KIND, token),
|
||||
"task_id": copy.card_task_id(card_kind or CARD_KIND, token),
|
||||
"main_title": {"title": head, "desc": desc},
|
||||
"select_list": select_list,
|
||||
"submit_button": {
|
||||
|
||||
@@ -49,7 +49,8 @@ _RE_UNTAXED_RATE = re.compile(
|
||||
)
|
||||
# 只写「未含税」不带点数:税率必须留空,禁止退化成 0。
|
||||
_RE_UNTAXED = re.compile(r"未\s*含\s*税(?!\s*[::=]?\s*\d)")
|
||||
_RE_ZERO_TAX = re.compile(r"含\s*0\s*(?:点)?\s*税")
|
||||
# 「含0税」「含0点税」,以及口语「0税」「0点税」「零税」都算税率 0。
|
||||
_RE_ZERO_TAX = re.compile(r"(?:含)?\s*0\s*(?:点|个点)?\s*税|零\s*税")
|
||||
|
||||
# 剥条件句用:比识别正则更宽松,连同后面的点数一起拿掉,
|
||||
# 防止「含燃油费13%」被费用行正则当成费目「含燃油费:13」。
|
||||
@@ -59,7 +60,7 @@ _RE_STRIP_FUEL = re.compile(
|
||||
_RE_STRIP_TAX = re.compile(
|
||||
r"未\s*含\s*税(?:\s*[::=]?\s*\d+(?:\.\d+)?\s*%?)?"
|
||||
)
|
||||
_RE_STRIP_ZERO_TAX = re.compile(r"含\s*0\s*(?:点)?\s*税")
|
||||
_RE_STRIP_ZERO_TAX = re.compile(r"(?:含)?\s*0\s*(?:点|个点)?\s*税|零\s*税")
|
||||
|
||||
# 主运费费目:只有这些才乘燃油;含提货/送货/报关等杂费词的一律排除。
|
||||
_MAIN_FREIGHT_WORDS = ("运输费", "陆运费", "运费", "干线费", "拖车费", "车费")
|
||||
|
||||
@@ -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] = []
|
||||
|
||||
@@ -0,0 +1,343 @@
|
||||
"""
|
||||
报价识别分级:完整 / 部分 / 全无。
|
||||
|
||||
产品 2026-11-23 口径:
|
||||
* 标准话术完整:解析字段入工单,原话进「原始报价参考」;
|
||||
* 只识别到一部分:回「我识别内容为…,请确认是否正确」;
|
||||
* 全无:回「我无法识别您的内容,请按格式重新报价」,原话仍留档。
|
||||
|
||||
本模块只判断识别程度、生成回执和格式样例;不写主账、不发企微。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Any, Optional
|
||||
|
||||
# 空运航线对:NKG-KUL / NKG/KUL / NKG—KUL。
|
||||
_AIR_ROUTE = re.compile(r"\b([A-Za-z]{3})\s*[-–—/]\s*([A-Za-z]{3})\b")
|
||||
# 空运标签写法:起运地NKG、目的港KUL。
|
||||
_AIR_ROUTE_LABEL = re.compile(
|
||||
r"(?:起运地|起运港|目的地|目的港)\s*([A-Za-z]{3})(?![A-Za-z])", re.I
|
||||
)
|
||||
# 陆运线路:东莞-春疆、深圳--香港、东莞到春疆。
|
||||
_LAND_ROUTE = re.compile(
|
||||
r"(?P<o>[一-鿿]{2,12})\s*(?:--|—|-|-|到|至)\s*(?P<d>[一-鿿]{2,12})"
|
||||
)
|
||||
# 陆运车型:10T、45HQ、7.6米、40GP、45尺柜。
|
||||
_LAND_VEHICLE = re.compile(r"\d+(?:\.\d+)?\s*(?:尺柜|T|吨|HQ|GP|尺|米)", re.I)
|
||||
|
||||
|
||||
def business_line_of(business_line: str = "", transport_mode: str = "") -> str:
|
||||
"""统一成 AIR / LAND / SEA;认不出返回空串。"""
|
||||
line = (business_line or "").strip().upper()
|
||||
if line in {"AIR", "LAND", "SEA"}:
|
||||
return line
|
||||
mode = (transport_mode or "").strip()
|
||||
if mode in {"空运", "AIR", "air"}:
|
||||
return "AIR"
|
||||
if mode in {"陆运", "LAND", "land"}:
|
||||
return "LAND"
|
||||
if mode in {"海运", "SEA", "sea"}:
|
||||
return "SEA"
|
||||
return ""
|
||||
|
||||
|
||||
def quote_format_hint(business_line: str = "", transport_mode: str = "") -> str:
|
||||
"""
|
||||
该业务线要求产品按什么格式重报。
|
||||
|
||||
空运/陆运用产品 2026-11-23 定的样例;海运暂无标准话术,
|
||||
用「费用名+金额+币种」兜底,后续定了再换。
|
||||
"""
|
||||
line = business_line_of(business_line, transport_mode)
|
||||
if line == "AIR":
|
||||
return "工单号,USD11/kg、TH、NKG-KUL、11月2日"
|
||||
if line == "LAND":
|
||||
return "东莞-春疆,危险品,45HQ,CNY18500;都是含0点税"
|
||||
return "费用名+金额+币种,例如“码头操作费100CNY,报关费300CNY”"
|
||||
|
||||
|
||||
def _has_price(quote: dict[str, Any]) -> bool:
|
||||
"""报价里有没有可入账的金额(费用行/车型价/分档价/合计)。"""
|
||||
if not quote:
|
||||
return False
|
||||
if quote.get("vehicleRates") or quote.get("vehicle_rates"):
|
||||
return True
|
||||
if quote.get("weightPrices") or quote.get("weight_prices"):
|
||||
return True
|
||||
for row in quote.get("fee_rows") or quote.get("fee_lines") or []:
|
||||
if isinstance(row, dict) and str(row.get("amount") or "").strip():
|
||||
return True
|
||||
return str(quote.get("total") or "").strip() not in {"", "-", "—", "-"}
|
||||
|
||||
|
||||
def _air_price_line(quote: dict[str, Any]) -> str:
|
||||
"""空运回执的价格行:空运费:USD11/kg。"""
|
||||
ccy = str(quote.get("currency") or "").strip()
|
||||
for row in quote.get("fee_rows") or []:
|
||||
if not isinstance(row, dict):
|
||||
continue
|
||||
name = str(row.get("name") or "空运费").strip() or "空运费"
|
||||
amount = str(row.get("unit_price") or row.get("amount") or "").strip()
|
||||
unit = str(row.get("unit") or "").strip()
|
||||
if not amount:
|
||||
continue
|
||||
if unit.upper() in {"KG", "KGS"}:
|
||||
return f"{name}:{ccy}{amount}/{unit.lower()}"
|
||||
return f"{name}:{ccy}{amount}"
|
||||
total = str(quote.get("total") or "").strip()
|
||||
return f"空运费:{ccy}{total}" if total else ""
|
||||
|
||||
|
||||
def _land_price_lines(quote: dict[str, Any]) -> list[str]:
|
||||
"""陆运回执的价格行:车型价逐档,或普通费用行逐项。"""
|
||||
out: list[str] = []
|
||||
ccy = str(quote.get("currency") or "").strip()
|
||||
rates = quote.get("vehicleRates") or quote.get("vehicle_rates")
|
||||
if isinstance(rates, dict) and rates:
|
||||
for model, amount in rates.items():
|
||||
model_text = str(model or "").strip()
|
||||
amount_text = str(amount or "").strip()
|
||||
if not model_text or not amount_text:
|
||||
continue
|
||||
out.append(f"车型/数量:{model_text}")
|
||||
out.append(f"运输费:{ccy}{amount_text}")
|
||||
return out
|
||||
for row in quote.get("fee_rows") or []:
|
||||
if not isinstance(row, dict):
|
||||
continue
|
||||
name = str(row.get("name") or "").strip()
|
||||
amount = str(row.get("amount") or "").strip()
|
||||
row_ccy = str(row.get("currency") or ccy).strip()
|
||||
unit = str(row.get("unit") or "").strip()
|
||||
if name and amount:
|
||||
out.append(f"{name}:{row_ccy}{amount}{('/' + unit) if unit else ''}")
|
||||
return out
|
||||
|
||||
|
||||
def _land_route_in_text(text: str) -> tuple[str, str]:
|
||||
"""从原话里认「起运地-目的地」。认不出返回空串,不去猜。"""
|
||||
for hit in _LAND_ROUTE.finditer(text or ""):
|
||||
origin = (hit.group("o") or "").strip()
|
||||
dest = (hit.group("d") or "").strip()
|
||||
if not origin or not dest:
|
||||
continue
|
||||
# 排除「2026-11-23」这类被中文包住的时间片段(虽然正则已要求中文)。
|
||||
if any(x in origin for x in ("月", "日", "点", "税", "价")):
|
||||
continue
|
||||
if any(x in dest for x in ("月", "日", "点", "税", "价")):
|
||||
continue
|
||||
return origin, dest
|
||||
return "", ""
|
||||
|
||||
|
||||
def _fact(facts: dict[str, Any], *keys: str) -> str:
|
||||
for key in keys:
|
||||
val = str(facts.get(key) or "").strip()
|
||||
if val:
|
||||
return val
|
||||
return ""
|
||||
|
||||
|
||||
# 其它字段的展示名:从原话里能认到的都列进回执(产品 2026-11-24:尽可能识别)。
|
||||
_EXTRA_LABELS = {
|
||||
"件数": "件数",
|
||||
"毛重": "毛重",
|
||||
"重量": "毛重",
|
||||
"体积": "体积",
|
||||
"包装方式": "包装类型",
|
||||
"包装类型": "包装类型",
|
||||
"品名": "品名",
|
||||
"是否为危险品": "是否为危险品",
|
||||
"是否含电": "是否含电",
|
||||
"是否含磁": "是否含磁",
|
||||
"是否含油": "是否含油",
|
||||
"货好时间": "货好时间",
|
||||
"HS编码": "HS编码",
|
||||
"商品海关编码": "HS编码",
|
||||
"贸易条款": "贸易条款",
|
||||
"货值": "货值",
|
||||
"车型/数量": "车型/数量",
|
||||
"计费重": "计费重",
|
||||
}
|
||||
|
||||
|
||||
def inspect_quote_recognition(
|
||||
text: str,
|
||||
quote: Optional[dict[str, Any]] = None,
|
||||
*,
|
||||
business_line: str = "",
|
||||
transport_mode: str = "",
|
||||
facts: Optional[dict[str, Any]] = None,
|
||||
extra_facts: Optional[dict[str, Any]] = None,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
判断这句话的报价识别程度。
|
||||
|
||||
参数:
|
||||
text:产品原话(已剥 @ 机器人的)。
|
||||
quote:extract_product_quote 的结果;可以传空,用来识别「只有字段没价格」。
|
||||
facts:工单询价字段,用于把话术没写、但工单已有的线路/车型/日期标成「按工单」。
|
||||
|
||||
返回:
|
||||
{"status": "full"|"partial"|"none",
|
||||
"recognized": [回执行], "missing": [缺项名], "hint": 格式样例}
|
||||
|
||||
「部分」以**话术本身**为准:线路/车型/日期没写在原话里,即使工单已有,
|
||||
也算部分识别,回执里标「按工单」,请产品确认。
|
||||
"""
|
||||
raw = (text or "").strip()
|
||||
src = dict(quote or {})
|
||||
facts = dict(facts or {})
|
||||
line = business_line_of(business_line, transport_mode)
|
||||
recognized: list[str] = []
|
||||
missing: list[str] = []
|
||||
in_text = 0
|
||||
|
||||
if line == "AIR":
|
||||
from agent.policy.air_group_ops import _harvest_air_manual_airline
|
||||
from agent.schema.field_validate import _harvest_quote_date
|
||||
|
||||
price = _has_price(src)
|
||||
airline = (
|
||||
str(src.get("airlineCode") or src.get("airline") or "").strip()
|
||||
or _harvest_air_manual_airline(raw)
|
||||
)
|
||||
origin = dest = ""
|
||||
labels = _AIR_ROUTE_LABEL.findall(raw)
|
||||
pair = _AIR_ROUTE.search(raw)
|
||||
if pair:
|
||||
origin, dest = pair.group(1).upper(), pair.group(2).upper()
|
||||
if len(labels) >= 2:
|
||||
origin, dest = labels[0].upper(), labels[1].upper()
|
||||
date = _harvest_quote_date(raw)
|
||||
|
||||
if price:
|
||||
in_text += 1
|
||||
price_line = _air_price_line(src)
|
||||
if price_line:
|
||||
recognized.append(price_line)
|
||||
else:
|
||||
missing.append("单价")
|
||||
# 比例 / 重量等级 / 增值服务也是产品原话里识别到的内容,回执要列全。
|
||||
from agent.schema.added_services import harvest_added_services
|
||||
from agent.schema.field_validate import _harvest_air_ratio
|
||||
|
||||
ratio = _harvest_air_ratio(raw)
|
||||
weight_break = str(src.get("weight_break") or "").strip()
|
||||
if not weight_break:
|
||||
try:
|
||||
from agent.llm.extract_text import _harvest_air_weight_break
|
||||
|
||||
weight_break = _harvest_air_weight_break(raw)
|
||||
except Exception:
|
||||
weight_break = ""
|
||||
added = harvest_added_services(raw)
|
||||
if ratio:
|
||||
in_text += 1
|
||||
recognized.append(f"比例:{ratio}")
|
||||
if weight_break:
|
||||
in_text += 1
|
||||
recognized.append(f"重量等级:{weight_break}")
|
||||
if added:
|
||||
in_text += 1
|
||||
recognized.append("增值服务:" + "/".join(added))
|
||||
if airline:
|
||||
in_text += 1
|
||||
recognized.append(f"航司:{airline}")
|
||||
else:
|
||||
missing.append("航司")
|
||||
if origin and dest:
|
||||
in_text += 1
|
||||
recognized.append(f"线路:{origin}-{dest}")
|
||||
else:
|
||||
origin_fact = _fact(facts, "起运港", "起运地", "始发站")
|
||||
dest_fact = _fact(facts, "目的港", "目的地", "收货地址", "送货地址")
|
||||
if origin_fact and dest_fact:
|
||||
recognized.append(f"线路:{origin_fact}-{dest_fact}")
|
||||
else:
|
||||
missing.append("线路")
|
||||
if date:
|
||||
in_text += 1
|
||||
recognized.append(f"航线日期:{date}")
|
||||
else:
|
||||
date_fact = _fact(facts, "报价日期")
|
||||
if date_fact:
|
||||
recognized.append(f"航线日期:{date_fact}")
|
||||
else:
|
||||
missing.append("报价日期")
|
||||
|
||||
full = price and bool(airline) and bool(origin and dest) and bool(date)
|
||||
status = "full" if full else ("partial" if in_text > 0 else "none")
|
||||
|
||||
elif line == "LAND":
|
||||
price = _has_price(src)
|
||||
origin, dest = _land_route_in_text(raw)
|
||||
vehicle_hit = _LAND_VEHICLE.search(raw)
|
||||
vehicle_in_text = bool(vehicle_hit) or "车型" in raw
|
||||
|
||||
if origin and dest:
|
||||
in_text += 1
|
||||
recognized.append(f"起运地:{origin}")
|
||||
recognized.append(f"目的地:{dest}")
|
||||
else:
|
||||
origin_fact = _fact(facts, "起运港", "始发站", "起运地", "提货地址")
|
||||
dest_fact = _fact(facts, "目的港", "目的地", "收货地址", "送货地址")
|
||||
if origin_fact and dest_fact:
|
||||
recognized.append(f"起运地/目的地:{origin_fact}-{dest_fact}")
|
||||
else:
|
||||
missing.append("线路")
|
||||
if vehicle_in_text:
|
||||
in_text += 1
|
||||
label = (vehicle_hit.group(0) if vehicle_hit else "车型").strip()
|
||||
recognized.insert(0, f"车型/数量:{label}")
|
||||
else:
|
||||
vehicle_fact = _fact(facts, "车型/数量", "车型", "车型数量")
|
||||
if vehicle_fact:
|
||||
recognized.append(f"车型/数量:{vehicle_fact}")
|
||||
else:
|
||||
missing.append("车型/数量")
|
||||
if price:
|
||||
in_text += 1
|
||||
recognized.extend(_land_price_lines(src))
|
||||
else:
|
||||
missing.append("价格")
|
||||
tax = str(src.get("tax_rate") or src.get("taxRate") or "").strip()
|
||||
if tax:
|
||||
recognized.append(f"税率:{tax}")
|
||||
remark = str(src.get("remark") or "").strip()
|
||||
if remark:
|
||||
recognized.append(f"备注:{remark}")
|
||||
|
||||
full = price and bool(origin and dest) and bool(vehicle_in_text)
|
||||
status = "full" if full else ("partial" if in_text > 0 else "none")
|
||||
|
||||
else:
|
||||
# 海运暂无标准话术:有价就算完整,没价且没字段就是全无。
|
||||
price = _has_price(src)
|
||||
if price:
|
||||
recognized.extend(_land_price_lines(src))
|
||||
else:
|
||||
missing.append("价格")
|
||||
status = "full" if price else "none"
|
||||
|
||||
# 其它从原话里识别到的字段(件数/毛重/体积/包装/品名/危险品/含电含磁/计费重…)。
|
||||
for key, val in (extra_facts or {}).items():
|
||||
text_val = str(val or "").strip().strip(",,;;。")
|
||||
if not text_val or text_val in {"-", "—", "-"}:
|
||||
continue
|
||||
label = _EXTRA_LABELS.get(str(key))
|
||||
if not label:
|
||||
continue
|
||||
recognized.append(f"{label}:{text_val}")
|
||||
in_text += 1
|
||||
|
||||
# 车型行可能同时来自「车型在话术里」和车型价明细,去重后回执才不重复。
|
||||
deduped = list(dict.fromkeys(x for x in recognized if x))
|
||||
return {
|
||||
"status": status,
|
||||
"recognized": deduped,
|
||||
"missing": list(dict.fromkeys(x for x in missing if x)),
|
||||
"hint": quote_format_hint(line),
|
||||
}
|
||||
@@ -178,13 +178,24 @@ def volume_cbm_number(raw: str) -> str:
|
||||
|
||||
|
||||
def resolve_airport_code(raw: str) -> str:
|
||||
"""销售原文是地名或三字码时,给出 TMS originCode/destinationCode。"""
|
||||
"""
|
||||
销售原文是地名或三字码时,给出 TMS originCode/destinationCode。
|
||||
|
||||
先查后台 inq_synonym(IT 可维护城市/三字码),查不到再回退本文件 _AIRPORTS。
|
||||
三字码原文优先,禁止把 SZX 再翻成深圳。
|
||||
"""
|
||||
text = (raw or "").strip()
|
||||
if not text:
|
||||
return ""
|
||||
if _IATA.match(text):
|
||||
return text.upper()
|
||||
return _AIRPORTS.get(text, "")
|
||||
try:
|
||||
from agent.policy.synonym import airport_code
|
||||
|
||||
code = airport_code(text)
|
||||
except Exception:
|
||||
code = ""
|
||||
return code or _AIRPORTS.get(text, "")
|
||||
|
||||
|
||||
def harvest_named_air_route(text: str, facts: dict[str, str] | None = None) -> dict[str, str]:
|
||||
@@ -248,6 +259,13 @@ def assemble_air_query(facts: dict[str, Any] | None) -> dict[str, Any]:
|
||||
包装只看销售是否说了,散货等原文原样保留。
|
||||
"""
|
||||
src = dict(facts or {})
|
||||
# 最后一层兜底:工单/旧快照里的卡板、40尺高柜等折成标准值;配置不可用时原样。
|
||||
try:
|
||||
from agent.policy.synonym import apply_value_synonyms
|
||||
|
||||
src = apply_value_synonyms(src, "AIR")
|
||||
except Exception:
|
||||
pass
|
||||
# 摘要占位「-」当空:不能拿去 resolve 机场,否则 TMS 回 1003 起飞机场无法匹配。
|
||||
_dash = frozenset({"-", "—", "-"})
|
||||
origin = str(src.get("起运港") or src.get("起运地") or "").strip()
|
||||
|
||||
@@ -104,14 +104,22 @@ def assemble_land_query(facts: dict[str, Any] | None) -> dict[str, Any]:
|
||||
src = apply_quote_date_default(
|
||||
normalize_facts({str(k): v for k, v in dict(facts or {}).items() if v is not None})
|
||||
)
|
||||
# 最后一层兜底:国内整车→国内运输整车、9米6/1→9.6高栏/1、东兴口岸→东兴。
|
||||
try:
|
||||
from agent.policy.synonym import apply_value_synonyms
|
||||
|
||||
src = apply_value_synonyms(src, "LAND")
|
||||
except Exception:
|
||||
pass
|
||||
raw = {str(k): str(v).strip() for k, v in dict(facts or {}).items() if v is not None}
|
||||
land_type = (raw.get("运输类型") or src.get("运输类型") or "").strip()
|
||||
route = (raw.get("线路类别") or src.get("线路类别") or "").strip()
|
||||
# 标准值优先,原文只兜底:否则「东南亚整车」会绕开同义词表直接出站。
|
||||
land_type = (src.get("运输类型") or raw.get("运输类型") or "").strip()
|
||||
route = (src.get("线路类别") or raw.get("线路类别") or "").strip()
|
||||
origin = (src.get("起运港") or "").strip()
|
||||
dest = (src.get("目的港") or "").strip()
|
||||
cargo = (src.get("品名") or "").strip()
|
||||
quote_date = (src.get("报价日期") or "").strip()
|
||||
customs = (raw.get("通关口岸") or src.get("通关口岸") or "").strip()
|
||||
customs = (src.get("通关口岸") or raw.get("通关口岸") or "").strip()
|
||||
|
||||
missing: list[str] = []
|
||||
if not land_type:
|
||||
|
||||
@@ -59,6 +59,13 @@ def assemble_sea_query(facts: dict[str, Any] | None) -> dict[str, Any]:
|
||||
src = apply_quote_date_default(
|
||||
{str(k): str(v) for k, v in dict(facts or {}).items() if v is not None}
|
||||
)
|
||||
# 最后一层兜底:40尺高柜→40HQ、门到门等标准值;配置不可用时原样。
|
||||
try:
|
||||
from agent.policy.synonym import apply_value_synonyms
|
||||
|
||||
src = apply_value_synonyms(src, "SEA")
|
||||
except Exception:
|
||||
pass
|
||||
origin = str(src.get("起运港") or "").strip()
|
||||
dest = str(src.get("目的港") or "").strip()
|
||||
cargo = str(src.get("品名") or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user