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()) {