From 383158a03d450e937483c22b12d7a44776312250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Thu, 8 Oct 2026 11:39:36 +0800 Subject: [PATCH] =?UTF-8?q?test:=20Task1=E8=B4=A8=E9=87=8F=E5=AE=A1?= =?UTF-8?q?=E6=9F=A5=E8=A1=A5=E6=B5=8B=E2=80=94=E2=80=94=E2=91=A3=E7=9C=9F?= =?UTF-8?q?=E8=A6=86=E7=9B=96/=E2=91=A2=E4=BF=9D=E5=BA=95=E8=A6=86?= =?UTF-8?q?=E7=9B=96/=E5=88=86=E7=BB=84=E6=B3=A8=E9=87=8A/=E6=B8=A0?= =?UTF-8?q?=E9=81=93=E6=98=A0=E5=B0=84=E6=9F=A5=E8=A1=A8=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Code --- app/services/boundary_filter.py | 15 +++++++++++---- tests/test_boundary_filter.py | 9 ++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/services/boundary_filter.py b/app/services/boundary_filter.py index 22f7b45..1e4ed7b 100644 --- a/app/services/boundary_filter.py +++ b/app/services/boundary_filter.py @@ -276,17 +276,24 @@ REASK_PATTERNS = [ # 渠道精确化(2026-10-08 spec §4.4): REASK 模式命中后按渠道词分辨—— # 索要已在手的渠道才丢,索要缺失渠道放行(双要补邮箱场景);泛渠道词 # 只要手上有任何号码渠道即丢(宁丢勿放);精确+泛同句共存时按①②自然 -# 实现任一命中判丢。中文泛词不用 \b(CJK 无词边界,"电话"前 \b 永不成立)。 +# 实现任一命中判丢。中文泛词不用 \b(CJK 无词边界,"电话"前 \b 在 +# 主流 CJK 连写形态下不成立)。 _PRECISE_CHANNEL_RE = re.compile(r"whatsapp|e-?mail|邮箱|微信|wechat", re.I) +# 匹配形态→渠道键查表(对齐 contact_pipeline._NUMBER_FIRST_CHANNEL 先例: +# 未来扩 _PRECISE_CHANNEL_RE 加新渠道词而漏配此表 → KeyError 显性失败, +# 而非链式三元静默兜到 whatsapp) +_PRECISE_CHANNEL_MAP = { + "whatsapp": "whatsapp", + "e-mail": "email", "email": "email", "邮箱": "email", + "wechat": "wechat", "微信": "wechat", +} _GENERIC_CONTACT_RE = re.compile(r"\b(?:number|phone|contact)\b|电话|联系方式|号码", re.I) def _precise_channels_in(s: str) -> set: out = set() for m in _PRECISE_CHANNEL_RE.finditer(s): - w = m.group(0).lower() - out.add("email" if w in ("e-mail", "email", "邮箱") - else "wechat" if w in ("微信", "wechat") else "whatsapp") + out.add(_PRECISE_CHANNEL_MAP[m.group(0).lower()]) return out diff --git a/tests/test_boundary_filter.py b/tests/test_boundary_filter.py index 12498a3..a36e636 100644 --- a/tests/test_boundary_filter.py +++ b/tests/test_boundary_filter.py @@ -200,14 +200,21 @@ def test_reask_wall_channel_precision(): 索要缺失渠道放行;泛渠道词只要手上有任何号码渠道即丢(宁丢勿放)。""" wa = {"whatsapp"} em = {"email"} + # 精确渠道词: ①在手→丢 / ④缺失→放行 assert asks_contact("What's your WhatsApp number?", wa) is True assert asks_contact("留个邮箱吧", em) is True - assert asks_contact("And an email address would help too", wa) is False + assert asks_contact("What's your email address?", wa) is False assert asks_contact("你WhatsApp多少?", em) is False + # 泛渠道词: ②手上有号码渠道→丢 / ④无号码渠道(只 email)→放行 assert asks_contact("What's your number?", wa) is True assert asks_contact("留个电话呗", wa) is True assert asks_contact("What's your number?", em) is False + # 精确+泛同句共存: 按①②自然实现,任一命中判丢 assert asks_contact("leave your number or email", wa) is True + # ③保底: 命中 REASK 但无任何渠道词("Drop yours too"式重复纠缠)→保守丢 + assert asks_contact("Drop yours too and our manager will send the quote!", + {"phone"}) is True + # 无参: 原行为向后兼容(命中即丢/未命中放行) assert asks_contact("What's your WhatsApp number?") is True assert asks_contact("hello there") is False