From b5d9ce60bf3aafc0f4275a1eff69e36a1c18a6f2 Mon Sep 17 00:00:00 2001 From: zonble Date: Mon, 14 Feb 2022 01:38:26 +0800 Subject: [PATCH] Prevents the override model to remember symbols with scode -8 or lower. --- Source/Engine/Gramambular/Node.h | 11 +++++++++++ Source/KeyHandler.mm | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Gramambular/Node.h b/Source/Engine/Gramambular/Node.h index 6e2bf45e..a877d27c 100644 --- a/Source/Engine/Gramambular/Node.h +++ b/Source/Engine/Gramambular/Node.h @@ -51,6 +51,7 @@ namespace Formosa { const string& key() const; double score() const; + double scoreForCandidate(string &candidate) const; const KeyValuePair currentKeyValue() const; double highestUnigramScore() const; @@ -198,6 +199,16 @@ namespace Formosa { return m_score; } + inline double Node::scoreForCandidate(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()) { return 0.0; diff --git a/Source/KeyHandler.mm b/Source/KeyHandler.mm index 1a00430f..8209ebc5 100644 --- a/Source/KeyHandler.mm +++ b/Source/KeyHandler.mm @@ -202,7 +202,17 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-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 <= -8) { + addToOverrideModel = NO; + } + } + if (addToOverrideModel) { _userOverrideModel->observe(_walkedNodes, cursorIndex, stringValue, [[NSDate date] timeIntervalSince1970]); } }