From 464dde2ac7a1b1a66a2312b72fb216b49161a55c Mon Sep 17 00:00:00 2001 From: computermacgyver Date: Thu, 26 Sep 2024 11:30:34 +0100 Subject: [PATCH] make codeclimate happy --- app/main/lib/langid.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/main/lib/langid.py b/app/main/lib/langid.py index 5f1daa7e..fd0ad836 100644 --- a/app/main/lib/langid.py +++ b/app/main/lib/langid.py @@ -112,30 +112,30 @@ def test(): class HybridLangidProvider: @staticmethod def langid(text): - fasttext = FastTextLangidProvider.langid(text) - cld = Cld3LangidProvider.langid(text) - max_confidence = max(fasttext['result']['confidence'], cld['result']['confidence']) + fasttext_result = FastTextLangidProvider.langid(text) + cld_result = Cld3LangidProvider.langid(text) + max_confidence = max(fasttext_result['result']['confidence'], cld_result['result']['confidence']) - if fasttext['result']['language']==cld['result']['language'] or max_confidence>=0.8: + if fasttext_result['result']['language'] == cld_result['result']['language'] or max_confidence >= 0.8: # FastText and CLD agree or one of them is more than 80% confident. # Return the higher confidence result - if fasttext['result']['language']!=cld['result']['language']: + if fasttext_result['result']['language'] != cld_result['result']['language']: # Log when there is disagreement app.logger.debug(json.dumps({ 'service':'LangId', 'message': 'Disagreement between fasttext and cld. Returning higher confidence model', - 'parameters':{'text':text, 'fasttext':fasttext, 'cld':cld,}, + 'parameters':{'text':text, 'fasttext':fasttext_result, 'cld':cld_result,}, })) - if fasttext['result']['confidence']>cld['result']['confidence']: - return fasttext + if fasttext['result']['confidence'] > cld_result['result']['confidence']: + return fasttext_result else: - return cld + return cld_result else: # Fallback to Google when models disagree and neither has a high-confidence result - google = GoogleLangidProvider.langid(text) + google_result = GoogleLangidProvider.langid(text) app.logger.debug(json.dumps({ 'service':'LangId', 'message': 'Called Google after inconclusive local results', - 'parameters':{'text':text, 'fasttext':fasttext, 'cld':cld, 'google':google}, + 'parameters':{'text':text, 'fasttext':fasttext_result, 'cld':cld_result, 'google':google_result}, })) - return google + return google_result