Skip to content

Commit

Permalink
make codeclimate happy
Browse files Browse the repository at this point in the history
  • Loading branch information
computermacgyver committed Sep 26, 2024
1 parent 8ee11aa commit 464dde2
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions app/main/lib/langid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 464dde2

Please sign in to comment.