From 68e0b6fa217c9f2ea82a79f073113c8c5ff6e6c5 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 8 Dec 2022 17:58:56 +0300 Subject: [PATCH] Slightly improved language detection from cld3. --- spellcheck/third_party/language_cld3.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spellcheck/third_party/language_cld3.cpp b/spellcheck/third_party/language_cld3.cpp index 0b57438..d0aea2f 100644 --- a/spellcheck/third_party/language_cld3.cpp +++ b/spellcheck/third_party/language_cld3.cpp @@ -21,11 +21,12 @@ RecognitionResult Recognize(QStringView text) { const auto string = std::string(text.toUtf8().constData()); const auto results = lang_id.FindTopNMostFreqLangs(string, kMaxLangs); - auto maxProbability = 0.; + auto maxRatio = 0.; auto final = NNetLanguageIdentifier::Result(); for (const auto &result : results) { - if (result.probability > maxProbability) { - maxProbability = result.probability; + const auto ratio = result.probability * result.proportion; + if (ratio > maxRatio) { + maxRatio = ratio; final = result; } }