Hold ambiguous English words (up = 因) until the next word decides
"up " also reads as ㄧㄣ (因). Instead of committing English on space, keep the word composing: "up jo4" becomes 因為, "up the" stays English. Only applies when the reading is a common single syllable (lexicon score >= -3.5): up, url. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -428,6 +428,40 @@ final class FirstToneAfterEnglishTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
final class HeldWordTests: XCTestCase {
|
||||
func makeEngine() -> CompositionEngine {
|
||||
CompositionEngine(classifier: Classifier(lexicon: sharedLexicon, english: sharedEnglish, weights: sharedWeights))
|
||||
}
|
||||
|
||||
func type(_ s: String, into e: CompositionEngine) -> String {
|
||||
var out = ""
|
||||
for c in s {
|
||||
let key: KeyInput = c == "\n" ? .enter : .character(c)
|
||||
let r = e.handle(key)
|
||||
if let t = r.commit { out += t } else if !r.handled { out.append(c) }
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/// "up " is also ㄧㄣ (因): the next word decides.
|
||||
func testNextWordDecides() {
|
||||
let cases = ["up jo4 ": "因為", "up the ": "up the ", "pick up the ": "pick up the ",
|
||||
"up\n": "up", "i love ": "i love "]
|
||||
for (keys, want) in cases {
|
||||
XCTAssertEqual(type(keys, into: makeEngine()), want, keys)
|
||||
}
|
||||
}
|
||||
|
||||
func testHeldWordStaysComposing() {
|
||||
let e = makeEngine()
|
||||
XCTAssertEqual(type("up ", into: e), "")
|
||||
XCTAssertEqual(e.markedText, "up ")
|
||||
_ = e.handle(.backspace)
|
||||
XCTAssertEqual(e.markedText, "up")
|
||||
XCTAssertEqual(type(" the ", into: e), "up the ")
|
||||
}
|
||||
}
|
||||
|
||||
final class StartupTimingTests: XCTestCase {
|
||||
func testStartupTiming() throws {
|
||||
var t = Date()
|
||||
|
||||
Reference in New Issue
Block a user