65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
"""
|
||
海运运输分类:只认 Port to Port、其他。
|
||
|
||
本文件职责:从原话收成标准词、生成补问清单。
|
||
禁止:发明第三项;把分类带去 TMS;改六态。
|
||
线程:纯函数,可在 Worker 槽调用。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
SEA_CLASSES = ("Port to Port", "其他")
|
||
|
||
# 长词优先,避免 P2P 误伤其它词;门到门不在名单里。
|
||
_ALIASES = (
|
||
("port to port", "Port to Port"),
|
||
("港到港", "Port to Port"),
|
||
("p2p", "Port to Port"),
|
||
("其它", "其他"),
|
||
("其他", "其他"),
|
||
)
|
||
|
||
|
||
def canonicalize_sea_class(raw: str) -> str:
|
||
"""
|
||
把销售原话收成 Port to Port 或 其他;对不上返回空串。
|
||
|
||
「门到门」不算。先匹配更长别名。副作用:无。
|
||
"""
|
||
text = (raw or "").strip()
|
||
if not text:
|
||
return ""
|
||
lowered = text.lower()
|
||
for needle, canon in _ALIASES:
|
||
if needle in lowered or needle in text:
|
||
return canon
|
||
stripped = text.replace("运输分类", "").replace(":", "").replace(":", "").strip()
|
||
if stripped in SEA_CLASSES:
|
||
return stripped
|
||
return ""
|
||
|
||
|
||
def harvest_sea_class(text: str, current: dict[str, str] | None = None) -> dict[str, str]:
|
||
"""
|
||
当前句能认则覆盖;认不出则保留已有标准值。
|
||
|
||
参数:本轮原文、已有 facts。返回合并后的 facts 副本。
|
||
非法旧值会丢掉,避免「门到门」一直占着必填位。
|
||
"""
|
||
merged = dict(current or {})
|
||
found = canonicalize_sea_class(text or "")
|
||
if found:
|
||
merged["运输分类"] = found
|
||
return merged
|
||
kept = canonicalize_sea_class(str(merged.get("运输分类") or ""))
|
||
if kept:
|
||
merged["运输分类"] = kept
|
||
else:
|
||
merged.pop("运输分类", None)
|
||
return merged
|
||
|
||
|
||
def sea_class_prompt() -> str:
|
||
"""缺运输分类时只列两项,不再追问「其他是什么」。"""
|
||
return "运输分类(必填):请回复 Port to Port 或 其他。"
|