From 5800ddea912c24eda145e05c4afe2bec4b7485c3 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Mon, 30 May 2022 15:39:25 +0800 Subject: [PATCH] KeyHandler // Cope with changes introduced in Megrez v1.1.8 update. - Also use dumpDOT when debug mode is enabled. --- .../ControllerModules/KeyHandler_Core.swift | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Source/Modules/ControllerModules/KeyHandler_Core.swift b/Source/Modules/ControllerModules/KeyHandler_Core.swift index 161b0455..82789d2f 100644 --- a/Source/Modules/ControllerModules/KeyHandler_Core.swift +++ b/Source/Modules/ControllerModules/KeyHandler_Core.swift @@ -48,6 +48,7 @@ protocol KeyHandlerDelegate { class KeyHandler { let kEpsilon: Double = 0.000001 + let kMaxComposingBufferNeedsToWalkSize: Int = 10 var _composer: Tekkon.Composer = .init() var _inputMode: String = "" var _languageModel: vChewing.LMInstantiator = .init() @@ -111,10 +112,21 @@ class KeyHandler { // Retrieve the most likely grid, i.e. a Maximum Likelihood Estimation // of the best possible Mandarin characters given the input syllables, // using the Viterbi algorithm implemented in the Megrez library. - // The walk() traces the grid to the end, hence no need to use .reversed() here. - _walkedNodes = _builder.walk( - at: _builder.grid.width, nodesLimit: 10, balanced: mgrPrefs.useScoreBalancing - ) + // The walk() traces the grid to the end. + _walkedNodes = _builder.walk() + + // if DEBUG mode is enabled, a GraphViz file is written to kGraphVizOutputfile. + if mgrPrefs.isDebugModeEnabled { + let result = _builder.grid.dumpDOT + do { + try result.write( + toFile: "/private/var/tmp/vChewing-visualization.dot", + atomically: true, encoding: .utf8 + ) + } catch { + IME.prtDebugIntel("Failed from writing dumpDOT results.") + } + } } var popOverflowComposingTextAndWalk: String {