feat(keyboard): rank pinyin by habit and persist user dictionaries

Erase dialect syllables before abbrev so wom prefers 我们, flush librime
on leave, and add a settings action to forget learned Chinese and English order.
This commit is contained in:
Rocky
2026-08-14 21:49:03 +08:00
parent 2c3a3f80f3
commit b13a1e904b
15 changed files with 588 additions and 5 deletions
@@ -43,7 +43,9 @@ public enum RimeSchemaGenerator {
let alphabet = inputSchema == .fullPinyin
? "zyxwvutsrqponmlkjihgfedcba"
: "zyxwvutsrqponmlkjihgfedcba;"
let algebra = fuzzyRules(fuzzyPairs) + algebraRules(for: inputSchema)
// Dialect single-letter syllables must be erased before fuzzy/abbrev
// so `n/l` cannot revive as `l`, and `wom` cannot exact-match .
let algebra = dialectEraseRules + fuzzyRules(fuzzyPairs) + algebraRules(for: inputSchema)
let algebraYAML = algebra.map { " - '\($0)'" }.joined(separator: "\n")
return """
@@ -112,6 +114,16 @@ public enum RimeSchemaGenerator {
"""
}
/// Drop Wu/dialect exact spellings (` m`, ` n/ng`, ` hm`) before
/// first-letter abbrev, matching rime-pinyin-simp. Keep the dictionary
/// rows; remains reachable as `en`, as `mu`.
public static let dialectEraseRules: [String] = [
"erase/^hm$/",
"erase/^m$/",
"erase/^n$/",
"erase/^ng$/"
]
/// Rules run against full-pinyin dictionary codes before double-pinyin
/// transforms, so fuzzy pairs work consistently in all three schemas.
public static func fuzzyRules(_ enabled: Set<PinyinFuzzyPair>) -> [String] {
@@ -144,7 +156,9 @@ public enum RimeSchemaGenerator {
case .fullPinyin:
return [
"derive/^([jqxy])u$/$1v/",
"abbrev/^([a-z]).+$/$1/"
"abbrev/^([a-z]).+$/$1/",
// Two-letter initials; do not add this to double pinyin.
"abbrev/^([zcs]h).+$/$1/"
]
case .microsoftDoublePinyin, .sogouDoublePinyin: