AI candidate selection on Windows and Linux

Python port of the reranker: core/lm.py runs the same CKIP gpt2-tiny-chinese
model with numpy (batched per candidate length, scores match the Swift and
reference implementations), Converter.kbest, core/reranker.py (modes, time
budget, pause after overruns, cache), core/system_monitor.py (Windows: CPU usage
and battery saver; Linux: load average, thermal zones, low-power profile and low
battery) and core/ai.py (settings.json, background model loading, status line).

Windows: numpy wheels for PIME's 32-bit Python 3.8 (PIME 1.3) and 3.15 (PIME 2)
are bundled under autozhuyin/vendor and picked by Python version; a settings menu
on the taskbar IME icon and the language bar (left click on the icon toggles
English mode). Linux: install.sh uses the system numpy or downloads the matching
wheel from PyPI (tools/fetch_numpy.py, SHA-256 checked); an IBus settings menu.
Without numpy or the model the input method works as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 16:51:41 +08:00
co-authored by Claude Opus 5.5
parent 38e0758a13
commit c8b3c4ae6f
20 changed files with 900 additions and 20 deletions
+20 -4
View File
@@ -54,9 +54,10 @@ class LookupTable:
class Property:
def __init__(self, **kw): self.label = kw["label"].text
def __init__(self, **kw): self.key, self.label, self.state = kw["key"], kw["label"].text, kw.get("state", 0)
def set_label(self, t): self.label = t.text
def set_symbol(self, t): pass
def set_state(self, s): self.state = s
class Engine:
@@ -71,7 +72,9 @@ class Engine:
def update_lookup_table(self, table, visible): self.shown = list(table.items)
def hide_lookup_table(self): self.shown = None
def register_properties(self, p): pass
def update_property(self, p): self.mode_label = p.label
def update_property(self, p):
if p.key == "mode":
self.mode_label = p.label
IBus.Text, IBus.AttrList, IBus.LookupTable, IBus.Property, IBus.Engine = Text, AttrList, LookupTable, Property, Engine
@@ -80,8 +83,8 @@ IBus.attr_underline_new = lambda kind, a, b: ("underline", a, b)
IBus.attr_foreground_new = lambda color, a, b: ("color", a, b)
IBus.AttrUnderline = types.SimpleNamespace(SINGLE=1)
IBus.Orientation = types.SimpleNamespace(VERTICAL=1)
IBus.PropType = types.SimpleNamespace(NORMAL=0)
IBus.PropState = types.SimpleNamespace(UNCHECKED=0)
IBus.PropType = types.SimpleNamespace(NORMAL=0, TOGGLE=1, RADIO=2, MENU=3)
IBus.PropState = types.SimpleNamespace(UNCHECKED=0, CHECKED=1)
IBus.PreeditFocusMode = types.SimpleNamespace(COMMIT=1)
gi = types.ModuleType("gi")
@@ -173,6 +176,19 @@ class IBusEngineTests(unittest.TestCase):
press(self.e, "su3 \n")
self.assertTrue(self.e.committed.endswith(second))
def test_ai_menu(self):
e = self.e
self.assertEqual(e.ai_props["standard"].state, 1)
e.do_property_activate("ai.saver", 1)
self.assertEqual(autozhuyin_ibus.shared_ai().reranker.mode, "saver")
self.assertEqual(e.ai_props["saver"].state, 1)
self.assertEqual(e.ai_props["standard"].state, 0)
e.do_property_activate("ai.autopause", 0)
self.assertFalse(autozhuyin_ibus.shared_ai().auto_pause)
self.assertTrue(e.status_prop.label)
e.do_property_activate("ai.standard", 1)
e.do_property_activate("ai.autopause", 1)
def test_focus_out_resets(self):
press(self.e, "su3")
self.e.do_focus_out()