Prevents the override model to remember symbols with scode -8 or lower.

This commit is contained in:
zonble 2022-02-14 01:38:26 +08:00
parent 4d94bb0cd2
commit b5d9ce60bf
2 changed files with 22 additions and 1 deletions

View File

@ -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;

View File

@ -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]);
}
}