From 18660f021632c93f1b1ea6a8ef0d4ed1ae650531 Mon Sep 17 00:00:00 2001 From: KagiamamaHIna Date: Wed, 6 Aug 2025 09:55:20 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=8F=8C=E6=8B=BC=E5=A3=B0=E6=AF=8D?= =?UTF-8?q?=E9=9F=B5=E6=AF=8D=E5=8C=B9=E9=85=8D=E5=A4=B1=E6=95=88=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8CKeyboard=E5=88=87=E5=88=86=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8CStorage=E7=9A=84=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E4=B8=8D=E5=AE=89=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/me/towdium/pinin/Keyboard.java | 36 ++++++++++++++++--- .../me/towdium/pinin/elements/Phoneme.java | 2 +- .../java/me/towdium/pinin/utils/IndexSet.java | 11 ++++-- src/test/java/me/towdium/pinin/PinInTest.java | 4 +-- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/towdium/pinin/Keyboard.java b/src/main/java/me/towdium/pinin/Keyboard.java index 5e3c44b..0904bc4 100644 --- a/src/main/java/me/towdium/pinin/Keyboard.java +++ b/src/main/java/me/towdium/pinin/Keyboard.java @@ -119,11 +119,11 @@ 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 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 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::zeroFirstInitial, true, false); + public static Keyboard ZIGUANG = new Keyboard(null, ZIGUANG_KEYS, Keyboard::zeroOInitial, true, false); final Map local; final Map keys; @@ -175,6 +175,32 @@ public static List zero(String s) { return ss; } + public static List zeroOInitial(String s) { + List ss = standard(s); + if (ss.size() == 2) { + ss.add(0,"o"); + } + return ss; + } + + public static List zeroAInitial(String s) { + List ss = standard(s); + if (ss.size() == 2) { + ss.add(0,"a"); + } + return ss; + } + + public static List zeroFirstInitial(String s) { + List ss = standard(s); + if (ss.size() == 2) { + String finale = ss.get(0); + ss.set(0, Character.toString(finale.charAt(0))); + ss.add(1,finale); + } + return ss; + } + public Collection split(String s) { if (local != null) { String cut = s.substring(0, s.length() - 1); diff --git a/src/main/java/me/towdium/pinin/elements/Phoneme.java b/src/main/java/me/towdium/pinin/elements/Phoneme.java index 352efa4..3ba9e8f 100644 --- a/src/main/java/me/towdium/pinin/elements/Phoneme.java +++ b/src/main/java/me/towdium/pinin/elements/Phoneme.java @@ -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; diff --git a/src/main/java/me/towdium/pinin/utils/IndexSet.java b/src/main/java/me/towdium/pinin/utils/IndexSet.java index 149ff75..9ad4274 100644 --- a/src/main/java/me/towdium/pinin/utils/IndexSet.java +++ b/src/main/java/me/towdium/pinin/utils/IndexSet.java @@ -97,8 +97,11 @@ public void offset(int i) { } static class Storage { - IndexSet tmp = new Immutable(); + ThreadLocal tmp; int[] data = new int[16]; + Storage(){ + tmp = ThreadLocal.withInitial(Immutable::new); + } public void set(IndexSet is, int index) { if (index >= data.length) { @@ -120,8 +123,10 @@ public IndexSet get(int index) { if (index >= data.length) return null; int ret = data[index]; if (ret == 0) return null; - tmp.value = ret - 1; - return tmp; + + IndexSet resultTmp = tmp.get(); + resultTmp.value = ret - 1; + return resultTmp; } } } diff --git a/src/test/java/me/towdium/pinin/PinInTest.java b/src/test/java/me/towdium/pinin/PinInTest.java index 7e8e56e..2327a07 100644 --- a/src/test/java/me/towdium/pinin/PinInTest.java +++ b/src/test/java/me/towdium/pinin/PinInTest.java @@ -181,7 +181,7 @@ 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"); } @@ -192,7 +192,7 @@ 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"); From 5168c0a7d97c338c88d1fc5f492df283ba115a7d Mon Sep 17 00:00:00 2001 From: KagiamamaHIna Date: Wed, 6 Aug 2025 11:08:00 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=BF=98=E6=98=AF=E5=9B=9E=E9=80=80?= =?UTF-8?q?=E5=90=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/me/towdium/pinin/utils/IndexSet.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/towdium/pinin/utils/IndexSet.java b/src/main/java/me/towdium/pinin/utils/IndexSet.java index 9ad4274..149ff75 100644 --- a/src/main/java/me/towdium/pinin/utils/IndexSet.java +++ b/src/main/java/me/towdium/pinin/utils/IndexSet.java @@ -97,11 +97,8 @@ public void offset(int i) { } static class Storage { - ThreadLocal tmp; + IndexSet tmp = new Immutable(); int[] data = new int[16]; - Storage(){ - tmp = ThreadLocal.withInitial(Immutable::new); - } public void set(IndexSet is, int index) { if (index >= data.length) { @@ -123,10 +120,8 @@ public IndexSet get(int index) { if (index >= data.length) return null; int ret = data[index]; if (ret == 0) return null; - - IndexSet resultTmp = tmp.get(); - resultTmp.value = ret - 1; - return resultTmp; + tmp.value = ret - 1; + return tmp; } } } From 04fdf81845a964375248aa02e91f94f970e6076b Mon Sep 17 00:00:00 2001 From: KagiamamaHIna Date: Sat, 9 Aug 2025 13:47:32 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=99=BA=E8=83=BDABC=E9=94=AE=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/me/towdium/pinin/Keyboard.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/me/towdium/pinin/Keyboard.java b/src/main/java/me/towdium/pinin/Keyboard.java index 0904bc4..1676c47 100644 --- a/src/main/java/me/towdium/pinin/Keyboard.java +++ b/src/main/java/me/towdium/pinin/Keyboard.java @@ -120,6 +120,7 @@ public class Keyboard { 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::zeroOInitial, true, false); + public static Keyboard ZHINENG_ABC = new Keyboard(null, ZHINENG_ABC_KEYS, Keyboard::zeroOInitial, true, false); 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::zeroFirstInitial, true, false);