Remember picked candidates (user history)

Candidates chosen with the arrow-down list are recorded on commit as
toneless reading -> phrase with a count. The converter lifts a picked phrase just
above the best lexicon entry for that reading (more for more picks), so it
comes first next time without overriding longer phrases. Up to 2000 pairs,
least recently used evicted. Stored as user-history.json on every platform; the
Mac menu's clear item clears it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 14:30:55 +08:00
co-authored by Claude Opus 5.5
parent 815dcf979d
commit 2cebf0e700
19 changed files with 414 additions and 39 deletions
+16
View File
@@ -8,6 +8,9 @@ import types
import unittest
LINUX = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
import tempfile # noqa: E402
os.environ["XDG_CONFIG_HOME"] = tempfile.mkdtemp(prefix="autozhuyin-test-") # learned / history files
sys.path.insert(0, os.path.join(os.path.dirname(LINUX), "windows")) # autozhuyin package
sys.path.insert(0, LINUX)
@@ -107,6 +110,8 @@ def press(e, keys):
class IBusEngineTests(unittest.TestCase):
def setUp(self):
autozhuyin_ibus.shared_classifier().history.clear()
autozhuyin_ibus.shared_classifier().learned.clear()
self.e = autozhuyin_ibus.AutoZhuyinEngine()
def test_mixed_sentence(self):
@@ -157,6 +162,17 @@ class IBusEngineTests(unittest.TestCase):
press(self.e, "rup fu4←wu0 \n")
self.assertEqual(self.e.committed, "今天氣")
def test_picked_candidate_saved(self):
press(self.e, "su3↓")
second = self.e.shown[1]
self.e.do_candidate_clicked(1, 1, 0)
press(self.e, "\n")
path = os.path.join(os.environ["XDG_CONFIG_HOME"], "autozhuyin", "user-history.json")
with open(path, encoding="utf-8") as f:
self.assertIn(second, f.read())
press(self.e, "su3 \n")
self.assertTrue(self.e.committed.endswith(second))
def test_focus_out_resets(self):
press(self.e, "su3")
self.e.do_focus_out()