KeyHandler_Core // Use walk() in lieu of reverseWalk().

This commit is contained in:
ShikiSuen 2022-05-17 16:00:45 +08:00
parent 2b38dd28e6
commit 461f94fec4
1 changed files with 5 additions and 10 deletions

View File

@ -117,15 +117,11 @@ class KeyHandler: NSObject {
func walk() { func walk() {
// Retrieve the most likely grid, i.e. a Maximum Likelihood Estimation // Retrieve the most likely grid, i.e. a Maximum Likelihood Estimation
// of the best possible Mandarin characters given the input syllables, // of the best possible Mandarin characters given the input syllables,
// using the Viterbi algorithm implemented in the Megrez library // using the Viterbi algorithm implemented in the Megrez library.
let walker = Megrez.Walker(grid: _builder.grid()) // The walk() traces the grid to the end, hence no need to use .reversed() here.
_walkedNodes = Megrez.Walker(
// the reverse walk traces the grid from the end grid: _builder.grid()
let walked = walker.reverseWalk(at: _builder.grid().width(), nodesLimit: 3, balanced: true) ).walk(at: _builder.grid().width(), nodesLimit: 3, balanced: true)
// then we use ".reversed()" to reverse the nodes so that we get the forward-walked nodes
_walkedNodes.removeAll()
_walkedNodes.append(contentsOf: walked.reversed())
} }
func popOverflowComposingTextAndWalk() -> String { func popOverflowComposingTextAndWalk() -> String {
@ -365,5 +361,4 @@ class KeyHandler: NSObject {
} }
_composer.clear() _composer.clear()
} }
} }