From c21f890ae9f328d8ab5fd6969aea90c0a4e8d83b Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sat, 26 Feb 2022 13:46:37 +0800 Subject: [PATCH] Zonble: KeyHandler // Don't let UOM remember symbols. - This feature is okay to be enabled since we have introduced SymbolLM. --- Source/Modules/ControllerModules/KeyHandler.mm | 12 +++++++++++- .../Modules/LanguageParsers/Gramambular/Node.h | 18 +++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Source/Modules/ControllerModules/KeyHandler.mm b/Source/Modules/ControllerModules/KeyHandler.mm index 82770558..78e760e8 100644 --- a/Source/Modules/ControllerModules/KeyHandler.mm +++ b/Source/Modules/ControllerModules/KeyHandler.mm @@ -208,7 +208,17 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; // If the length of the readings and the characters do not match, // it often means it is a special symbol and it should not be stored // in the user override model. - if (selectedNode.spanningLength == [value count]) { + BOOL addToOverrideModel = YES; + if (selectedNode.spanningLength != [value count]) { + addToOverrideModel = NO; + } + if (addToOverrideModel) { + double score = selectedNode.node->scoreForCandidate(stringValue); + if (score <= -12) { // 威注音的 SymbolLM 的 Score 是 -12。 + addToOverrideModel = NO; + } + } + if (addToOverrideModel) { _userOverrideModel->observe(_walkedNodes, cursorIndex, stringValue, [[NSDate date] timeIntervalSince1970]); } } diff --git a/Source/Modules/LanguageParsers/Gramambular/Node.h b/Source/Modules/LanguageParsers/Gramambular/Node.h index ff1d3fd2..dfc961c5 100644 --- a/Source/Modules/LanguageParsers/Gramambular/Node.h +++ b/Source/Modules/LanguageParsers/Gramambular/Node.h @@ -184,15 +184,15 @@ inline const std::string& Node::key() const { return m_key; } inline double Node::score() const { return m_score; } -// Prevents the override model to remember symbols with scode -X or lower. -//inline double Node::scoreForCandidate(const std::string& candidate) const { -// for (auto unigram : m_unigrams) { -// if (unigram.keyValue.value == candidate) { -// return unigram.score; -// } -// } -// return 0.0; -//} + +inline double Node::scoreForCandidate(const std::string& candidate) const { + for (auto unigram : m_unigrams) { + if (unigram.keyValue.value == candidate) { + return unigram.score; + } + } + return 0.0; +} inline double Node::highestUnigramScore() const { if (m_unigrams.empty()) {