redact: 文案 and words like it are no Chinese names (zeewell on X)

zeewell on X: tasks kept going wrong because 文案 was masked as a name,
so they turned names (and birthdays) off. 文 is a surname, and zhName
took a cue around 文案 that says nothing about a person. Probing words
that start with a surname (文档, 方案, 关键, 项目, 成本, 段落, 颜色, 查询,
时区, 简历, 林间, …, ~130 of them) in the places a prompt has 文案, about
110 were masked, through two cues:

- 一下 before it (改一下文案, 检查一下文案,) counted as "a person comes
  next". 一下 follows any verb, so it now counts only after one that asks
  a person (zhAskVerbs: 问, 找, 联系, 通知, 提醒, 回复, …): 问一下张伟
  still is one, 改一下文案 is not.
- At a sentence's start, a word after it that any subject takes (已经,
  明天, 今天, 昨天, 他, 她, 提交, 负责, 回复) counted alone: 文案已经改好了,
  文案明天给你, 文案他们说. Those (zhAnyAfter) now count only with a
  person's cue before (客户张伟已经到了). 说明, 说法, 讲解, 讲座, 讲义, 讲究
  are words, not 说 (文案说明), but for 说明天 (张伟说明天来).
- zhWords gets ~150 more common words (文案, 文风, 关键, 项目, 段落, 林间,
  …) for where a real cue is before a word (发给文案, 请文案), and is a
  set looked up by a candidate's first two characters rather than a scan.
- The model's own PERSON span that is such a word whole (文案) is
  dropped too (modelTakes), the other route a word reaches a name.

Old data: masked values are remembered in memory only, and 文案 (6
bytes) is under minKnown, so nothing stays masked after the update.

Fixtures are prompts with 文案 where the report gives no sentence (帮我
改一下这段文案, 文案:…, 把首页文案换成英文, ### 文案, 文案和图片, 文案已经改好了,
文案说明要简短, 这张图发给文案。), beside names in the same places that
still mask (问一下张伟,, 张伟说明天来, 客户张伟已经到了, 发给张伟。);
TestChineseWordsAreNoNames runs 25 listed words in 10 shapes plus the
model's label, and 5 unlisted ones (文创, 方位, 高铁, 安防, 林荫) through the
cue shapes alone. Every TestChineseNames case stays green.

Run (mote, mote-run, at this tree): go vet ./internal/redact for darwin,
linux and windows ok; gofmt clean; go test -timeout 45m of
internal/redact, masking, pii/..., otlp, sessions, settings, gateway
ok; internal/gui red on TestMainWindowCorners/macOS_26_SDK only, the
macOS 27 red filed as #3949 (no redact in it).
After rebasing onto 8edb9dbb7 (gateway, provider only): redact and
masking again ok at the pushed head.
Broken by hand, each red: the 一下 rule always true (改一下文创), the
zhAnyAfter check off (文创已经好了, 文创明天给你, 文创他们定), the 说明 words
off (文创说明), the model's word check off (the model's 文案, 文档, …), 文案
out of zhWords (发给文案, 请文案).
Not tried: the real model on zeewell's prompts (they gave none). Now
left: a two-character name at a sentence's start before only 已经/明天/
他 (张伟已经到了。), and an unlisted word after a person's verb at a
clause's end (发给文创。). Birthdays: the report names no birthday that
was masked wrongly, so they are unchanged.
This commit is contained in:
yetone
2026-10-28 15:15:31 +08:00
parent 8edb9dbb75
commit bc3ddc661a
4 changed files with 127 additions and 15 deletions
File diff suppressed because one or more lines are too long
+2 -1
View File
@@ -122,7 +122,8 @@ func modelTakes(kind, v string) bool {
case "SECRET":
return len(v) >= 8 && !madeID(v) && !namesThing(v)
case "PERSON":
return utf8.RuneCountInString(v) >= 2 && strings.IndexFunc(v, unicode.IsLetter) >= 0 && !snakeWord(v)
// nor a word that starts with a surname, as a whole (文案)
return utf8.RuneCountInString(v) >= 2 && strings.IndexFunc(v, unicode.IsLetter) >= 0 && !snakeWord(v) && !zhWords[v]
case "ACCOUNT":
return !madeID(v)
case "EMAIL":
+70 -13
View File
@@ -28,8 +28,33 @@ const zhNickSurnames = "王李张刘陈杨黄赵吴周徐孙马朱胡郭何高
// with after a name.
const zhNotGiven = "的了在是和与跟同说他她它我你您们这那个不也都就还把被给到对从向为以等及或并而吗呢吧啊去来有没要会能让请已将再又很更最先后上下里外时年日号发打回写问讲叫找用做看想知道得地着过之其此每各某该所反表认提负"
// zhWords begin with a surname but are words, not names.
var zhWords = []string{"张量", "张开", "张贴", "高度", "高效", "高级", "高速", "高亮", "高手", "高兴", "王国", "王者", "黄河", "黄色", "方法", "方向", "方式", "方案", "方便", "方面", "程序", "程度", "温度", "白色", "金额", "金融", "江湖", "石头", "马上", "周期", "周末", "周围", "周边", "文件", "文本", "文档", "文字", "文章", "余额", "安全", "安装", "安排", "钱包", "叶子", "毛病", "万一", "雷达", "宋体", "常量", "常用", "常见", "向量", "向上", "全部", "全局", "全面", "史上", "易用", "武器", "时间", "时候", "明天", "明确", "明白", "任何", "任务", "任意", "华为", "管理", "简单", "简介", "范围", "许多", "许可", "包括", "包含", "关于", "关系", "关闭", "连接", "成功", "成为", "应用", "应该", "单位", "单元", "单独", "司机", "车辆", "车子", "路径", "路由", "林业", "龙头", "柏林", "米饭", "宁可", "师傅", "老师", "老板", "老婆", "老公", "老家", "小时", "小心", "小说", "小姐", "小孩", "小组", "周一", "周二", "周三", "周四", "周五", "周六", "周日", "周天"}
// zhWords begin with a surname but are words, not names: 文案 in
// "改一下文案" is no one (zeewell on X). Each is two characters, so a
// candidate's first two are looked up (zhWord).
var zhWords = runes2(
"张量", "张开", "张贴", "高度", "高效", "高级", "高速", "高亮", "高手", "高兴", "王国", "王者",
"黄河", "黄色", "方法", "方向", "方式", "方案", "方便", "方面", "程序", "程度", "温度", "白色",
"金额", "金融", "江湖", "石头", "马上", "周期", "周末", "周围", "周边", "文件", "文本", "文档",
"文字", "文章", "余额", "安全", "安装", "安排", "钱包", "叶子", "毛病", "万一", "雷达", "宋体",
"常量", "常用", "常见", "向量", "向上", "全部", "全局", "全面", "史上", "易用", "武器", "时间",
"时候", "明天", "明确", "明白", "任何", "任务", "任意", "华为", "管理", "简单", "简介", "范围",
"许多", "许可", "包括", "包含", "关于", "关系", "关闭", "连接", "成功", "成为", "应用", "应该",
"单位", "单元", "单独", "司机", "车辆", "车子", "路径", "路由", "林业", "龙头", "柏林", "米饭",
"宁可", "师傅", "老师", "老板", "老婆", "老公", "老家", "小时", "小心", "小说", "小姐", "小孩",
"小组", "周一", "周二", "周三", "周四", "周五", "周六", "周日", "周天", "文案", "文风", "文化",
"文学", "文明", "文献", "文法", "文具", "方块", "方针", "方程", "方框", "关键", "关注", "关联",
"关心", "关掉", "项目", "成本", "成员", "成果", "成绩", "成熟", "成就", "解决", "解析", "解释",
"解码", "段落", "章节", "颜色", "蓝色", "查询", "查看", "查找", "单词", "单个", "单击", "包装",
"包名", "时区", "时长", "时段", "时刻", "时代", "季度", "严格", "严重", "曾经", "麻烦", "安卓",
"谷歌", "常规", "常数", "边框", "边界", "边缘", "付费", "付款", "路线", "简洁", "简历", "简化",
"范例", "游戏", "游客", "商品", "商店", "商业", "左边", "左侧", "焦点", "毕竟", "尚未",
"陆续", "连续", "连线", "林间", "林区", "谢谢", "顾客", "顾问", "房间", "房子", "高端", "高层",
"古代", "古典", "农业", "司法", "施工", "卫生", "荣誉", "宗旨", "齐全", "凌晨", "冷却", "蒙版",
"曲线", "黄金", "白天", "白板", "金钱", "石油", "夏天", "夏季", "唐朝", "宋朝", "秦朝", "申请",
"符号", "景色", "费用", "舒服", "辛苦", "纪律", "席位", "车间", "管道", "何时", "何况", "于是",
"余下", "杜绝", "罗列", "程式", "叶片", "涂层", "沙发", "池子", "巩固", "迟到", "仲裁", "钟点",
"钟表", "向导", "史诗", "易懂", "马路", "马虎", "汤汁", "朱红", "阳光", "任职", "董事",
)
// zhRoles before a name say it is one: 客户陈建国, 联系人:赵丽颖,
// 我叫黄晓明, 提交者是欧阳娜娜.
@@ -42,6 +67,17 @@ var zhBefore = []string{"给", "找", "问", "让", "告诉", "通知", "联系"
// zhAfter are words that follow a person (张伟先生, 马云说, 张三反馈).
var zhAfter = []string{"先生", "女士", "小姐", "老师", "同学", "同志", "经理", "总监", "主任", "师傅", "医生", "律师", "教授", "博士", "说", "讲", "表示", "认为", "反馈", "提到", "提交", "负责", "告诉", "回复", "发", "打", "明天", "今天", "昨天", "已经", "他", "她"}
// zhAnyAfter are those of zhAfter that follow any subject, a thing as
// well as a person (文案已经改好了, 文案明天给你, 文档提交): at a
// sentence's start, with nothing before it that says a person, they say
// nothing.
var zhAnyAfter = []string{"提交", "负责", "回复", "明天", "今天", "昨天", "已经", "他", "她"}
// zhAskVerbs take a person before 一下 (问一下张伟, 联系一下李娜); after
// any other verb what 一下 is followed by is a thing (改一下文案,
// 检查一下文档).
var zhAskVerbs = []string{"问", "找", "叫", "喊", "催", "请", "联系", "通知", "告诉", "提醒", "回复", "答复", "拜访", "采访", "抄送", "转告", "感谢", "谢谢", "艾特", "@"}
// zhTitles are what the model takes in after a name and isn't it.
var zhTitles = []string{"先生", "女士", "小姐", "老师", "同学", "同志", "经理", "总监", "主任", "师傅", "医生", "律师", "教授", "博士"}
@@ -52,6 +88,22 @@ var (
mayStart = runes(zhSurnames + zhFirsts() + "小老")
)
// runes2 is a set of two-character words.
func runes2(ws ...string) map[string]bool {
m := map[string]bool{}
for _, w := range ws {
m[w] = true
}
return m
}
// zhWord says s starts with a word of zhWords.
func zhWord(s string) bool {
_, n := utf8.DecodeRuneInString(s)
_, n2 := utf8.DecodeRuneInString(s[n:])
return zhWords[s[:n+n2]]
}
func runes(s string) map[rune]bool {
m := map[rune]bool{}
for _, r := range s {
@@ -178,10 +230,8 @@ func zhName(s string, i int) (a, b int, ok bool) {
if len(ends) == 0 {
return 0, 0, false
}
for _, w := range zhWords {
if strings.HasPrefix(rest, w) {
return 0, 0, false
}
if zhWord(rest) {
return 0, 0, false
}
// a Han character before it that is no cue makes it part of a word
// (建国路), unless a cue ends there
@@ -194,6 +244,11 @@ func zhName(s string, i int) (a, b int, ok bool) {
verb = personBefore(t)
}
}
// 一下 takes a person only after a verb that asks one (问一下张伟),
// not 改一下文案
if t, ok := strings.CutSuffix(before, "一下"); ok && verb {
verb = endsAny(t, zhAskVerbs, false)
}
start := sentenceStart(before)
if !role && !verb && !start {
return 0, 0, false
@@ -209,7 +264,7 @@ func zhName(s string, i int) (a, b int, ok bool) {
// the longest that ends where something after it says so
for k := len(ends) - 1; k >= 0; k-- {
e := ends[k]
if after := s[e:]; startsAny(after, zhAfter) && !wordAfter(after) {
if after := s[e:]; startsAny(after, zhAfter) && !wordAfter(after) && (role || verb || !startsAny(after, zhAnyAfter)) {
return i, e, true
} else if (role || verb) && endsWord(after) {
return i, e, true
@@ -276,8 +331,14 @@ func sentenceStart(s string) bool {
}
// wordAfter says the 发 or 打 that s starts with begins a word (发现,
// 打开), not the verb a person does (发了个消息, 打给他).
// 打开), not the verb a person does (发了个消息, 打给他); and so do
// 说明 and 讲解 (文案说明要简短), but for 说明天 (张伟说明天来).
func wordAfter(s string) bool {
for _, w := range []string{"说明", "说法", "讲解", "讲座", "讲义", "讲究"} {
if strings.HasPrefix(s, w) {
return !strings.HasPrefix(s, "说明天")
}
}
for _, v := range []string{"发", "打"} {
if t, ok := strings.CutPrefix(s, v); ok {
r, _ := utf8.DecodeRuneInString(t)
@@ -300,11 +361,7 @@ func personBefore(s string) bool {
if !mayStart[rs[len(rs)-n]] || !hasHan(u) {
continue
}
word := false
for _, w := range zhWords {
word = word || strings.HasPrefix(u, w)
}
if !word {
if !zhWord(u) {
return true
}
}
+54
View File
@@ -70,6 +70,26 @@ func TestChineseNames(t *testing.T) {
{"### 张伟发了个消息", []string{"张伟"}, []string{"发了个消息"}},
{"我和张伟,还有他。", []string{"张伟"}, []string{"我和"}},
{"这件事。 李娜说过。", []string{"李娜"}, []string{"说过"}},
// zeewell on X: 文案 (文 a surname) masked as a name; prompts it
// is in, each with a cue that was taken for a person's: 一下
// before it, 已经, 明天 or 他们 after it at a sentence's start, 说
// of 说明 after it
{"帮我改一下这段文案", nil, []string{"文案"}},
{"润色一下文案。", nil, []string{"文案"}},
{"检查一下文案,看看有没有错别字", nil, []string{"文案"}},
{"文案:首页标题换成「更快的网关」", nil, []string{"文案"}},
{"把首页文案换成英文", nil, []string{"文案"}},
{"### 文案\n\n- 文案和图片都要改", nil, []string{"文案"}},
{"文案已经改好了,你再看看。", nil, []string{"文案"}},
{"文案明天给你,图片今天先发。", nil, []string{"文案"}},
{"文案说明要简短,不超过两行。", nil, []string{"文案说明"}},
{"文案他们说下午定稿", nil, []string{"文案他们"}},
{"这张图发给文案。", nil, []string{"文案"}},
// and names in the same places still are
{"问一下张伟,这段谁来写", []string{"张伟"}, []string{"问一下"}},
{"张伟说明天来改。", []string{"张伟"}, []string{"说明天"}},
{"客户张伟已经到了。", []string{"张伟"}, []string{"已经到了"}},
{"这张图发给张伟。", []string{"张伟"}, []string{"发给"}},
} {
out, _ := Mask(c.s, o)
for _, n := range c.names {
@@ -88,6 +108,40 @@ func TestChineseNames(t *testing.T) {
}
}
// A word that starts with a surname is no name in the places 文案 was
// taken for one (zeewell on X), whichever word it is: zhName's cues, and
// the model's own PERSON label on the word as a whole.
func TestChineseWordsAreNoNames(t *testing.T) {
words := []string{"文案", "文档", "文风", "方案", "高度", "安全", "马上", "程序", "林间", "关键", "项目", "成本", "段落", "颜色", "查询", "时区", "季度", "边框", "简历", "游戏", "严格", "曾经", "谢谢", "解析", "付费"}
shapes := []string{"改一下%s", "检查一下%s。", "%s已经好了", "%s明天给你", "%s说明", "%s他们定", "请%s", "发给%s", "%s:", "把%s换成英文"}
f := &fakeModel{values: map[string]string{}}
o := Options{Personal: true, Model: f.find}
for _, w := range words {
for _, sh := range shapes {
s := strings.ReplaceAll(sh, "%s", w)
if out, _ := Mask(s, o); out != s {
t.Errorf("%q masked: %q", s, out)
}
}
f.values = map[string]string{w: "private_person"}
s := "帮我改一下这段" + w + ",谢谢"
if out, _ := Mask(s, o); out != s {
t.Errorf("%q, the model's: masked: %q", s, out)
}
f.values = map[string]string{}
}
// words not in zhWords are left by the cues alone, but for one
// a person's verb is before (请文创, 发给文创)
for _, w := range []string{"文创", "方位", "高铁", "安防", "林荫"} {
for _, sh := range shapes[:6] {
s := strings.ReplaceAll(sh, "%s", w)
if out, _ := Mask(s, o); out != s {
t.Errorf("%q masked: %q", s, out)
}
}
}
}
// Without the model, or with personal data off, no Chinese name is
// looked for.
func TestChineseNamesNeedModel(t *testing.T) {