Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/main/java/me/towdium/pinin/Keyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class Keyboard {
{"ing", "j"}, {"iong", "s"}, {"iu", "y"}, {"ong", "s"}, {"ou", "p"},
{"sh", "u"}, {"ua", "q"}, {"uai", "y"}, {"uan", "w"}, {"uang", "n"},
{"ui", "v"}, {"un", "z"}, {"uo", "o"}, {"van", "w"}, {"ve", "x"},
{"vn", "z"}, {"zh", "v"},
{"ue", "x"}, {"vn", "z"}, {"zh", "v"},
}).collect(Collectors.toMap(d -> d[0], d -> d[1]));

private static Map<String, String> MICROSOFT_KEYS = Stream.of(new String[][]{
Expand Down Expand Up @@ -119,11 +119,12 @@ public class Keyboard {
public static Keyboard DAQIAN = new Keyboard(PHONETIC_LOCAL, DAQIAN_KEYS, Keyboard::standard, false, false);
public static Keyboard XIAOHE = new Keyboard(null, XIAOHE_KEYS, Keyboard::zero, true, false);
public static Keyboard ZIRANMA = new Keyboard(null, ZIRANMA_KEYS, Keyboard::zero, true, false);
public static Keyboard SOUGOU = new Keyboard(null, SOUGOU_KEYS, Keyboard::zero, true, false);
public static Keyboard GUOBIAO = new Keyboard(null, GUOBIAO_KEYS, Keyboard::zero, true, false);
public static Keyboard MICROSOFT = new Keyboard(null, MICROSOFT_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);
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
public static Keyboard GUOBIAO = new Keyboard(null, GUOBIAO_KEYS, Keyboard::zeroAInitial, true, false);
public static Keyboard MICROSOFT = new Keyboard(null, MICROSOFT_KEYS, Keyboard::zeroOInitial, true, false);
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 ZIGUANG = new Keyboard(null, ZIGUANG_KEYS, Keyboard::zeroOInitial, true, false);

final Map<String, String> local;
final Map<String, String> keys;
Expand Down Expand Up @@ -175,6 +176,22 @@ public static List<String> zero(String s) {
return ss;
}

public static List<String> zeroOInitial(String s) {
List<String> ss = standard(s);
if (ss.size() == 2) {
ss.add(0,"o");
}
return ss;
}

public static List<String> zeroAInitial(String s) {
List<String> ss = standard(s);
if (ss.size() == 2) {
ss.add(0,"a");
}
return ss;
}

public Collection<String> split(String s) {
if (local != null) {
String cut = s.substring(0, s.length() - 1);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/towdium/pinin/elements/Phoneme.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public IndexSet match(String source, int start, boolean partial) {
if (strs.length == 1 && strs[0].isEmpty()) return ret;
for (String str : strs) {
int size = strCmp(source, str, start);
if (partial && start + size == source.length()) ret.set(size); // ending match
if (partial && size != 0 && start + size == source.length()) ret.set(size); // ending match
else if (size == str.length()) ret.set(size); // full match
}
return ret;
Expand Down
79 changes: 77 additions & 2 deletions src/test/java/me/towdium/pinin/PinInTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ public void xiaohe() {
assert p.contains("测试文本", "ceuiwfbf");
assert p.contains("测试文本", "ceuiwf2");
assert !p.contains("测试文本", "ceuiw2");
assert p.contains("合金炉", "hej");
assert !p.contains("合金炉", "hej");
assert p.contains("洗矿场", "xikl4");
assert p.contains("月球", "ytqq");
assert p.contains("昂撒人", "ahsarf");
}

@Test
Expand All @@ -192,10 +193,84 @@ public void ziranma() {
assert p.contains("测试文本", "ceuiwfbf");
assert p.contains("测试文本", "ceuiwf2");
assert !p.contains("测试文本", "ceuiw2");
assert p.contains("合金炉", "hej");
assert !p.contains("合金炉", "hej");
assert p.contains("洗矿场", "xikd4");
assert p.contains("月球", "ytqq");
assert p.contains("安全", "anqr");
assert p.contains("昂撒人", "ahsarf");
}

@Test
public void sougou() {
PinIn p = new PinIn().config().keyboard(SOUGOU).commit();
assert p.contains("测试文本", "ceuiwfbf");
assert p.contains("测试文本", "ceuiwf2");
assert !p.contains("测试文本", "ceuiw2");
assert !p.contains("合金炉", "hej");
assert p.contains("洗矿场", "xikd4");
assert p.contains("月球", "ytqq");
assert p.contains("安全", "ojqr");
}

@Test
public void zhineng_abc() {
PinIn p = new PinIn().config().keyboard(ZHINENG_ABC).commit();
assert p.contains("测试文本", "ceviwfbf");
assert p.contains("测试文本", "ceviwf2");
assert !p.contains("测试文本", "ceviw2");
assert !p.contains("合金炉", "hej");
assert p.contains("洗矿场", "xikt4");
assert p.contains("月球", "ymqr");
assert p.contains("安全", "ojqp");
}

@Test
public void guobiao() {
PinIn p = new PinIn().config().keyboard(GUOBIAO).commit();
assert p.contains("测试文本", "ceuiwrbr");
assert p.contains("测试文本", "ceuiwr2");
assert !p.contains("测试文本", "ceuiw2");
assert !p.contains("合金炉", "hej");
assert p.contains("洗矿场", "xikn4");
assert p.contains("月球", "yxqy");
assert p.contains("安全", "afqw");
}

@Test
public void microsoft() {
PinIn p = new PinIn().config().keyboard(MICROSOFT).commit();
assert p.contains("测试文本", "ceuiwfbf");
assert p.contains("测试文本", "ceuiwf2");
assert !p.contains("测试文本", "ceuiw2");
assert !p.contains("合金炉", "hej");
assert p.contains("洗矿场", "xikd4");
assert p.contains("月球", "ytqq");
assert p.contains("安全", "ojqr");
}

@Test
public void pinyinpp() {
PinIn p = new PinIn().config().keyboard(PINYINPP).commit();
assert p.contains("测试文本", "ceiiwrbr");
assert p.contains("测试文本", "ceiiwr2");
assert !p.contains("测试文本", "ceiiw2");
assert !p.contains("合金炉", "hej");
assert p.contains("洗矿场", "xikh4");
assert p.contains("月球", "yxqn");
assert p.contains("安全", "anqc");
assert p.contains("昂撒人", "agsarr");
}

@Test
public void ziguang() {
PinIn p = new PinIn().config().keyboard(ZIGUANG).commit();
assert p.contains("测试文本", "ceiiwwbw");
assert p.contains("测试文本", "ceiiww2");
assert !p.contains("测试文本", "ceiiw2");
assert !p.contains("合金炉", "hej");
assert p.contains("洗矿场", "xikg4");
assert p.contains("月球", "ynqj");
assert p.contains("安全", "orql");
}

@Test
Expand Down