Skip to content

feat(android): 笔画/英文/联想改用 Rime,删除自家词库 - #1455

Merged
HKLHaoBin merged 10 commits into
Open-Less:betafrom
aeoform:feat/android-rime-dictionaries
Dec 1, 2026
Merged

HKLHaoBin merged 10 commits into
Open-Less:betafrom
aeoform:feat/android-rime-dictionaries

Conversation

@aeoform

@aeoform aeoform commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

改动

  • 笔画候选走 Rime stroke,保留宿主侧通配展开和个人选字优先。
  • 英文候选走 rime-ice melt_eng,保留个人词频和自定义词。
  • 联想不再在提交后单独显示一行。输入下一段编码时,使用 librime-predict 的数据库实现,从 rime-ice 构建预测索引,对已经匹配当前编码的候选重新排序;不改默认首选,不在私密模式启用。
  • 删除 Android 的四份自带 TSV;增量构建也会从生成目录移除这些旧文件。APK 仍携带上游 Rime 数据和构建生成的 predict.db。

验证

  • 本地 Android x86_64 JNI 编译通过。
  • 桌面原生冒烟验证了简体预测、笔画与英文候选。
  • Android APK、Kotlin 与真机交互待验证。重点检查笔画通配、英文自造词与忘记、开启和关闭预测、私密模式,以及从旧版本升级后的数据解包。

Android 输入法里"拼音已上 Rime、笔画/英文/联想还压着自家词库"是半迁移状态。
这一步先把 Rime 侧准备好:

- `build-mobile-rime.py`:`schema_list` 启用 `stroke` 与 `melt_eng`(以前只启用
  pinyin_simp,所以 stroke schema 打进去也不会部署);同时从已 vendored 的
  rime-ice 拷入 `melt_eng.schema.yaml` / `melt_eng.dict.yaml` / `en_dicts/`
  —— 英文词库直接复用现有依赖,不需要我们自己的 `english-frequency.tsv`。
- `mobile-ime/rime_engine.cpp`:`create` 按用途选方案(默认/learning/stroke/
  english),部署清单加入 `stroke`、`melt_eng`。
  已用真实 `rime_api.h`(mobile-rime 缓存里的 1.17.0)做过语法校验。

依赖结论(对应"能不能找依赖"):
- 英文:**不用新增**,rime-ice 自带 melt_eng(en.dict.yaml 2.3 万条 + en_ext)。
- 联想:`rime/librime-predict`(librime 1.17 已支持 predict 插件;
  `predict.db` 可在构建期由 essay.txt + 词典文本生成,仓库不新增数据;
  若想边走边学,用 `fxliang/librime-predict-leveldb`,无需预生成库)。

后续(未在本提交):Kotlin 侧笔画/英文/联想改调 Rime、接入 predict 插件、
删除 android/assets 下的 4 个 TSV(43 万行)。
- `StrokeInput.kt` 不再加载/索引 TSV:查询改成向 Rime 的 `stroke` 会话喂
  h/s/p/n/z 取候选;`*` 通配符由宿主侧展开成具体编码(Rime table 只做精确/
  前缀匹配,没有通配),每次通配 5 条查询、上限 25 条。
- 保留两部分我们自己的逻辑(不是语料):个人选字优先(`StrokeUserFrequency`,
  存在偏好里)和候选排序 `rankStrokeCandidates`;Rime 负责词频与用户词典学习。
- 删除 `assets/stroke.dict.tsv`(17 万行)与 `assets/stroke-frequency.tsv`
  (1.7 万行),以及只用于生成它们的 `scripts/generate-stroke-frequency.mjs`。
- 契约测试保留:`input_target` 与 Kotlin 单测里的 `rankStrokeCandidates` /
  `strokeCodeMatches` 语义未变,仍按原样跑。
- `EnglishCandidateProvider` 不再加载/索引词表:查询改成向 Rime 的 `melt_eng`
  会话喂字母取候选;词表本身来自 rime-ice(已 vendored 的 `en_dicts/en.dict.yaml`,
  2.3 万条)。
- 保留三处自有逻辑(都不是语料):个人选词权重 `EnglishUserFrequency`;
  用户自造的、词典里没有的词(内存集合 + 前缀匹配,冷启动从偏好恢复);
  长按"忘记"的排除集合。
- `recordCommit` 通过"Rime 是否认识这个词"判断要不要记成自定义词,不再依赖
  本地 trie 的 `indexedWords`。
- 删除 `android/assets/english-frequency.tsv`(2 万行)、它的 LICENSE 与
  `scripts/generate-english-dictionary.mjs`。
@aeoform

aeoform commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator Author

@aeoform
aeoform marked this pull request as ready for review November 19, 2026 14:30
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T02:16:21.632313Z b0787a3 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca2e7128bb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d827480759

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +109 to +111
for (code in expandStrokePattern(pattern)) {
if (merged.size >= MAX_CANDIDATES) break
merged += queryCode(code)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Cancel superseded wildcard replays on the shared input queue

When the user types past a sparse four-wildcard pattern, queryEpoch invalidates only the callback; this entire loop still runs inside one RimeTaskQueue task. For example, ****hhspnpphs has only eight matches in the bundled table but requires 625 replays—at least 9,375 native requests—even after a newer query supersedes it. Obsolete queued patterns are also processed in full, while pinyin keys and commit delivery share this queue, so continued typing or switching to pinyin leaves input waiting behind discarded work. Check cancellation before starting and between concrete codes, and propagate mode/session invalidation to the repository.

Useful? React with 👍 / 👎.

Comment on lines +42 to +43
(assetMarker in files && !File(selected, assetMarker).isFile))) {
selected = shared.absolutePath

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Rebase cached dictionaries when rejecting their asset format

When upgrading an installation that already cached the current public rime-ice revision, its snapshot lacks the new marker, so this fallback selects the bundled dictionaries without invalidating or migrating the cached snapshot. ime_dictionary::select() has already marked that snapshot active, and update() in openless-all/app/crates/openless-core/src/ime_dictionary.rs:274–279 returns immediately while the upstream SHA equals state.ready. Consequently, successful update checks cannot restore the downloaded tables, and the IME keeps using older bundled data until a different upstream revision is downloaded. Version or migrate these snapshots, or arrange for the updater to rebuild an incompatible snapshot even when its upstream SHA is unchanged.

Useful? React with 👍 / 👎.

@HKLHaoBin
HKLHaoBin marked this pull request as draft November 19, 2026 18:14
@HKLHaoBin
HKLHaoBin marked this pull request as ready for review November 19, 2026 18:17

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d827480759

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

ensureSession()
val merged = LinkedHashSet<String>()
for (code in expandStrokePattern(pattern)) {
if (merged.size >= MAX_CANDIDATES) break

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve wildcard branches before applying the result cap

The expansion fix covers the earlier three-wildcard example, but a * query can still lose branches here: its first code is h, and queryCode can return up to 40 candidates from the bundled table’s 48,405 h-prefixed entries, reaching the 36-candidate cap before s, p, n, or z are queried. Keep the cap after sampling across concrete codes so the wildcard does not silently become a literal first stroke.

Useful? React with 👍 / 👎.

HKLHaoBin
HKLHaoBin previously approved these changes Nov 28, 2026
@aeoform

aeoform commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

已按用户要求仅解决与当前beta的合并冲突并推回本PR原分支,提交 ce8cc19(parents: 原head d827480 + beta b471f2a)。

12项均为Android目录迁移引起的rename/delete或新增文件位置冲突:保留本PR既有删除意图,3个新增Kotlin/测试文件落到新android目录且与原PR字节一致。相对beta最终仍恰好原PR的24个文件;无额外功能修复、无鸿蒙输入法提交。

验证:无未解决index项;PR相对beta diff --check通过;copy-android-scaffolding string/debug-manifest/instrumentation fixture测试通过;JS与Python相关脚本语法检查通过。未宣称全量Android构建或设备测试。GitHub当前mergeable=MERGEABLE;PR仍OPEN,未执行合并、未push beta,剩余检查/保护规则照常。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4131461c6b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

for ((character, code) in entries) {
if (strokeCodeMatches(pattern, code)) {
merged += character
if (merged.size >= limit) break

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Cover wildcard branches before applying the result cap

The new table-filter path fixes the bare * example, but fresh *s evidence shows the cap still drops valid branches: the bundled table has matches for all five first strokes, yet its first 36 unique matches contain only h and p. Because this stops in raw table order, candidates from the n, s, and z branches are never offered; sample or rank across the wildcard alternatives before enforcing the limit.

Useful? React with 👍 / 👎.

} else {
strokeCandidates?.removeAllViews()
}
confirmedText = ""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retain the remaining prediction context after one backspace

With personalized learning and association ranking enabled, if a user commits stroke text and then backspaces with no active code or segment and no editor selection, deleteBackward() removes one character but this assignment discards the entire confirmedText buffer. The next stroke query therefore has no context to promote continuations from the remaining text until another commit; retain the remaining code points and clear the buffer only when a deletion removes the whole tracked context.

Useful? React with 👍 / 👎.

HKLHaoBin
HKLHaoBin previously approved these changes Nov 29, 2026

@HKLHaoBin HKLHaoBin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

修复已完成,独立 review-diff-bugs 复审无 bug;PR head 4131461 的 CI 已全部适用检查通过。

Integrate the Rime candidate backends with the rewritten Android keyboard panels, preserving pinyin readiness and preedit handling and versioning the bundled prebuilt tables.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b0787a3577

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

val fromRime = queryRime(normalized)
val fromCustom = customWords.filter { it.startsWith(normalized) }
(fromCustom + fromRime)
.filter { it !in excludedWords }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Case-fold native candidates before filtering forgotten words

When an upgrade retains a custom word that melt_eng now returns with capital letters, long-pressing “Forget” leaves the native suggestion visible. forgetCustomWord() stores the lowercase spelling in excludedWords, but strings() preserves Rime’s capitalization and this comparison is case-sensitive. A provider-level fixture with saved myterm and native MyTerm reproduces the failure: the next query still returns MyTerm. Compare using the same normalized word key used by the custom-word store so forgetting also excludes the native spelling.

Useful? React with 👍 / 👎.

@HKLHaoBin
HKLHaoBin merged commit 29d6e49 into Open-Less:beta Dec 1, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android Android-specific area:ime IME area P2 Medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants