Skip to content

s2t: protect 是只有 / 是只能 from 是只 to 是隻 (#1304, #581) - #1433

Closed
stantheman0128 wants to merge 1 commit into
BYVoid:masterfrom
stantheman0128:fix/1304-zhiyou-conversion
Closed

stantheman0128 wants to merge 1 commit into
BYVoid:masterfrom
stantheman0128:fix/1304-zhiyou-conversion

Conversation

@stantheman0128

@stantheman0128 stantheman0128 commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1304.
Closes #581.

Problem

When 「只有」 is preceded by 「是」, default (non-jieba) conversion turns 「只」 into 「隻」:

s2t / s2tw / s2twp / s2hk: 这是只有一种可能 -> 這是隻有一種可能

Same MaxMatch path also breaks #581-style unquoted inputs such as 「则是只能」 and 「[全都不]是只能」 (both become 「…是隻能…」). The quoted report form 「则是「只」能」 already converts correctly on current master because the quotation marks break the 「是只」 phrase match.

Collaborator frankslin traced this to the STPhrases entry 「是只 -> 是隻」 (measure word). With jieba segmentation the same input converts correctly because 「只有」 is kept as one token; without jieba, MaxMatch takes the shorter 「是只」 first.

Change

Keep 「是只 -> 是隻」 for legitimate measure-word uses such as 「是只猫 -> 是隻貓」.

Add longer identity mappings in STPhrases.txt so MaxMatch prefers the function-word reading:

是只有	是只有
是只要	是只要
是只能	是只能
是只好	是只好
是只得	是只得
是只怕	是只怕

Tradeoff: this is the usual longer-phrase-wins pattern. It does not remove the measure-word entry. Other rare 「是只X」 collisions may still need similar protections later; the issue report and the common 「只*」 function words above are covered.

Dictionary sorted with python data/scripts/sort.py data/dictionary/STPhrases.txt.

Test plan

  • New cases BYVoid_OpenCC_Issue_1304_* in test/testcases/testcases.json
    • reported sentence under s2t / s2tw / s2twp / s2hk
    • measure-word control: 「是只猫 是一只鸟」 still becomes 「是隻…」
    • sibling function words: 是只要 / 是只能 / 是只好 / 是只得 / 是只怕
  • Local verification with OpenCC 1.4.1 wheel + branch text dictionaries (see Evidence)
  • CI Bazel dictionary / command_line tests (authoritative)

Evidence

Repro before (master STPhrases, text-dict s2t harness):

是只有 -> 是隻有
这是只有一种可能 -> 這是隻有一種可能
是只要 -> 是隻要
是只猫 -> 是隻貓
则是只能 -> 則是隻能
[全都不]是只能 -> [全都不]是隻能
则是「只」能 -> 則是「只」能

After this branch:

是只有 -> 是只有
这是只有一种可能 -> 這是只有一種可能
是只要 -> 是只要
是只猫 -> 是隻貓
则是只能 -> 則是只能
[全都不]是只能 -> [全都不]是只能
则是「只」能 -> 則是「只」能

A/B of all existing s2t expectations (master vs this STPhrases): only the new #1304 cases differ, as intended.

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.

…#1304)

Keep the measure-word mapping 是只 -> 是隻, and add longer STPhrases
entries so MaxMatch prefers 是只有 / 是只要 / 是只能 / 是只好 / 是只得 /
是只怕 over the two-character measure-word entry.

Co-authored-by: Cursor <cursoragent@cursor.com>
@stantheman0128 stantheman0128 changed the title s2t: protect 是只有 from 是只 to 是隻 measure-word match (#1304) s2t: protect 是只有 / 是只能 from 是只 to 是隻 (#1304, #581) Jul 17, 2026
@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