Skip to content

s2t: protect 前头发生 from 头发 to 頭髮 MaxMatch (#586) - #1450

Closed
stantheman0128 wants to merge 1 commit into
BYVoid:masterfrom
stantheman0128:fix/586-qiantou-fa
Closed

stantheman0128 wants to merge 1 commit into
BYVoid:masterfrom
stantheman0128:fix/586-qiantou-fa

Conversation

@stantheman0128

Copy link
Copy Markdown
Contributor

Closes #586.

Problem

Default (non-jieba) MaxMatch matches the shorter STPhrases entry 头发 -> 頭髮 inside 前头发生:

s2t / s2tw / s2twp / s2hk: 前头发生 -> 前頭髮生

Expected (issue body): 前頭發生.

Same A(A/B)(B/C)C overlap pattern as #578 / #581 / #890 / #1304: 前 + 头发 + 生 wins over 前头 + 发生.

Change

Keep 头发 -> 頭髮 (and hair compounds such as 剪头发).

Add one longer STPhrases entry so MaxMatch prefers the reported phrase:

前头发生	前頭發生

Same longer-phrase-wins pattern as #1433 (是只有 vs 是只) and #1440 (人参加 vs 人参). Dictionary sorted with python data/scripts/sort.py data/dictionary/STPhrases.txt.

Test plan

  • New cases BYVoid_OpenCC_Issue_586_* in test/testcases/testcases.json
    • reported 前头发生 under s2t / s2tw / s2twp / s2hk
    • hair control: 前头发 / 剪头发 / 头发 still map to 頭髮
    • sibling control: 喉头发干 / 不断发生 unchanged
  • Local verification with OpenCC 1.4.x wheel + branch text dictionaries (see Evidence)
  • CI Bazel dictionary / command_line tests (authoritative)

Evidence

Repro before (packaged wheel dictionaries = current published behavior):

s2t: 前头发生 -> 前頭髮生
s2t: 前头发 -> 前頭髮
s2t: 头发 -> 頭髮

After this branch (config JSONs with ocd2 refs switched to text, driving data/dictionary/*.txt on the branch):

s2t: 前头发生 -> 前頭發生
s2t: 前头发 -> 前頭髮
s2t: 头发 -> 頭髮
s2t: 剪头发 -> 剪頭髮
s2t: 喉头发干 -> 喉頭發乾
s2t: 不断发生 -> 不斷發生

A/B of existing s2t expectations in testcases.json (branch STPhrases vs expectations, excluding the new #586 cases): 92/92 same, 0 diffs.

sort.py idempotence on STPhrases.txt: no diff.

Please treat CI Bazel tests as authoritative; no local C++/Bazel toolchain was available here.

AI assistance

This fix was developed with AI assistance (Cursor / Grok) and verified locally as shown above.

Add a longer STPhrases entry so 前头发生 becomes 前頭發生 instead of matching 头发 in the middle.

Co-authored-by: Cursor <cursoragent@cursor.com>
@frankslin frankslin closed this Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

前头「发」生 -> 前頭「髮」生

2 participants