emoji: search the dictionary by prefix in the engine, not in the data

mkemoji wrote a row for every prefix of every alias, so that a query
matched as it was typed; the trie is a prefix index already, and with a
real emoji list those rows would be four times the aliases themselves.
Now emoji.dict has one row per alias, trienode() names a key's node, and
dictlookup walks the entries at and below it, the key's own first, up to
Maxkouho.  Trie children are appended rather than pushed, so the walk
keeps the file's order and a bare digit still picks the superscript or
subscript it always did.

The hand-written symbol rows move to symbol.src; emoji.src is left to
the emoji.  mkemoji reads both by default, or the files it is given.
This commit is contained in:
2026-08-17 01:07:10 +09:00
parent 221117f93d
commit abff5ed122
9 changed files with 275 additions and 386 deletions

View File

@@ -1331,13 +1331,14 @@ engine_emoji_queries(struct ct *t)
CT_CHECK(t, keystroke('e', Mctrl, &com));
CT_CHECK(t, keystroke('a', 0, &com));
checkstr(t, "raw query wins", "a", &search.text);
CT_EQ_INT(t, 3, im.nkouho);
CT_EQ_INT(t, 4, im.nkouho);
checkstr(t, "raw candidate", "A", &im.kouho[0]);
checkstr(t, "deduplicated candidate", "B", &im.kouho[1]);
checkstr(t, "local candidate", "C", &im.kouho[2]);
checkstr(t, "raw prefix candidate", "α", &im.kouho[2]);
checkstr(t, "local candidate", "C", &im.kouho[3]);
CT_CHECK(t, draindraw(&dc) > 0);
checkstr(t, "prefix popup query", "a", &dc.pre);
CT_EQ_INT(t, 3, dc.nkouho);
CT_EQ_INT(t, 4, dc.nkouho);
CT_CHECK(t, keystroke(Kesc, 0, &com));
CT_CHECK(t, keystroke('e', Mctrl, &com));

View File

@@ -12,10 +12,8 @@ MKEMOJI = ROOT / "map" / "mkemoji"
TIMEOUT = 10
def generate(source=None):
args = [sys.executable, "-B", str(MKEMOJI)]
if source is not None:
args.append(str(source))
def generate(*sources):
args = [sys.executable, "-B", str(MKEMOJI)] + [str(s) for s in sources]
return subprocess.run(
args, capture_output=True, text=True, check=False, timeout=TIMEOUT
)
@@ -37,27 +35,32 @@ class MkemojiTest(unittest.TestCase):
result = generate()
self.assertEqual(result.returncode, 0, result.stderr)
data = table(result.stdout)
self.assertEqual(data["^"].split()[:9], list("¹²³⁴⁵⁶⁷⁸⁹"))
self.assertEqual(data["_"].split()[:9], list("₁₂₃₄₅₆₇₈₉"))
self.assertEqual(data["<"].split()[2], "")
keys = list(data)
self.assertEqual([k for k in keys if k[:1] == "^"][:9],
[f"^{d}" for d in range(1, 10)])
self.assertEqual([k for k in keys if k[:1] == "_"][:9],
[f"_{d}" for d in range(1, 10)])
self.assertEqual([k for k in keys if k[:1] == "<"][2], "<3")
self.assertEqual(data["^1"], "¹")
self.assertEqual(data["_2"], "")
self.assertEqual(data["<3"], "")
self.assertEqual(data["<3"].split()[0], "")
self.assertIn("😀", data["smile"].split())
self.assertIn("😀", data["웃음"].split())
def test_fold_normalize_and_exact_first(self):
def test_fold_normalize_and_source_order(self):
source = self.source(
"β\tALPHABET\n"
"β\tALPHABET\talpha\n"
"α\talpha\n"
"e\u0301\tE\u0301\n"
"é\t\n"
"#\thash\n"
)
first = generate(source)
second = generate(source)
second = generate(source, source)
self.assertEqual(first.returncode, 0, first.stderr)
self.assertEqual(first.stdout, second.stdout)
data = table(first.stdout)
self.assertEqual(data["alpha"].split(), ["α", "β"])
self.assertEqual(data["al"].split(), ["β", "α"])
self.assertEqual(list(data), ["alphabet", "alpha", "é", "hash"])
self.assertEqual(data["alpha"].split(), ["β", "α"])
self.assertEqual(data["é"], "é")
self.assertEqual(data["hash"], "#")