双拼声母韵母匹配失效问题,Keyboard切分函数的问题#14
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes two bugs in the PinIn double-pinyin (shuangpin) input system: (1) a partial match false-positive in Phoneme.java caused by not checking the return value of strCmp for zero, and (2) incorrect zero-initial (零声母) split rules for several keyboard layouts. It also adds the previously missing ZHINENG_ABC keyboard layout.
Changes:
- Fix partial-match logic in
Phoneme.match()to guard againststrCmpreturning 0 whenstartequalssource.length() - Add three new zero-initial split functions (
zeroOInitial,zeroAInitial,zeroFirstInitial) and apply them correctly to each double-pinyin keyboard layout; addZHINENG_ABCkeyboard - Update test assertions for XIAOHE and ZIRANMA to reflect the corrected matching behavior for "hej" against "合金炉"
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/main/java/me/towdium/pinin/elements/Phoneme.java |
Fixes false partial match when strCmp returns 0 (no chars matched) |
src/main/java/me/towdium/pinin/Keyboard.java |
Adds zeroOInitial, zeroAInitial, zeroFirstInitial split functions; applies them to correct keyboard layouts; adds ZHINENG_ABC |
src/test/java/me/towdium/pinin/PinInTest.java |
Corrects two test assertions to reflect the fixed matching behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public static Keyboard PINYINPP = new Keyboard(null, PINYINPP_KEYS, Keyboard::zero, true, false); | ||
| public static Keyboard ZIGUANG = new Keyboard(null, ZIGUANG_KEYS, Keyboard::zero, true, false); | ||
| public static Keyboard SOUGOU = new Keyboard(null, SOUGOU_KEYS, Keyboard::zeroOInitial, true, false); | ||
| public static Keyboard ZHINENG_ABC = new Keyboard(null, ZHINENG_ABC_KEYS, Keyboard::zeroOInitial, true, false); |
There was a problem hiding this comment.
The ZHINENG_ABC keyboard is newly added in this PR but has no test coverage. The existing keyboard implementations (XIAOHE, ZIRANMA) each have dedicated test methods that verify correct matching behavior. A test method for ZHINENG_ABC should be added to ensure that both the keyboard key mappings and the zeroOInitial split function work correctly together for this layout.
修正国标方案中缺失的ue->x的映射 修正拼音加加的零声母方案,此方案应和自然码,小鹤一致 新增关于自然码等零声母方案中的特例的测试样例,即当字零声母,韵母为3字母韵母时,应当为韵母第一个字符+韵母键位(昂撒人)
|
新增搜狗。智能ABC,国标,微软,拼音加加,紫光双拼方案的测试样例 |
如标题所述
1.双拼声母韵母匹配失效问题
双拼匹配要求声母韵母同时存在,但是存在失效问题
双拼声母韵母匹配失效问题来源于没有检查strCmp返回的是否为0
有时候start如果等于了source.length()就会导致双拼要求的声母韵母同时存在的规则失效
要检查strCmp返回的是否为0,如果为0,那么代表没有匹配成功的字符串
2.Keyboard切分函数的问题
之前添加的Keyboard的一些新键位设计,没有去考虑到其对应的零声母规则,我已经实现了他们对应的零声母规则:
zeroOInitial: 如果没有声母,则用o作为声母 (搜狗,微软,紫光)
zeroAInitial: 如果没有声母,则用a作为声母 (国标)
zeroFirstInitial: 如果没有声母,则是韵母第一个字母作为声母 (拼音加加)
额外:原本智能ABC双拼打了表但是忘记填写字段了,现在加上了
这里也发一个(x)