feature: format detection outputs (#207)
* feature: format detection output * feature: format detection outputs * feature: format detection outputs
This commit is contained in:
parent
e5c9505559
commit
0e1c9d1d52
@ -259,8 +259,12 @@ class Translator:
|
|||||||
src = ''
|
src = ''
|
||||||
confidence = 0.0
|
confidence = 0.0
|
||||||
try:
|
try:
|
||||||
src = ''.join(data[8][0])
|
if len(data[8][0]) > 1:
|
||||||
confidence = data[8][-2][0]
|
src = data[8][0]
|
||||||
|
confidence = data[8][-2]
|
||||||
|
else:
|
||||||
|
src = ''.join(data[8][0])
|
||||||
|
confidence = data[8][-2][0]
|
||||||
except Exception: # pragma: nocover
|
except Exception: # pragma: nocover
|
||||||
pass
|
pass
|
||||||
result = Detected(lang=src, confidence=confidence)
|
result = Detected(lang=src, confidence=confidence)
|
||||||
|
@ -84,18 +84,21 @@ def test_translate_list(translator):
|
|||||||
def test_detect_language(translator):
|
def test_detect_language(translator):
|
||||||
ko = translator.detect(u'한국어')
|
ko = translator.detect(u'한국어')
|
||||||
en = translator.detect('English')
|
en = translator.detect('English')
|
||||||
|
rubg = translator.detect('тест')
|
||||||
|
|
||||||
assert ko.lang == 'ko'
|
assert ko.lang == 'ko'
|
||||||
assert en.lang == 'en'
|
assert en.lang == 'en'
|
||||||
|
assert rubg.lang == ['ru', 'bg']
|
||||||
|
|
||||||
|
|
||||||
def test_detect_list(translator):
|
def test_detect_list(translator):
|
||||||
items = [u'한국어', ' English']
|
items = [u'한국어', ' English', 'тест']
|
||||||
|
|
||||||
result = translator.detect(items)
|
result = translator.detect(items)
|
||||||
|
|
||||||
assert result[0].lang == 'ko'
|
assert result[0].lang == 'ko'
|
||||||
assert result[1].lang == 'en'
|
assert result[1].lang == 'en'
|
||||||
|
assert result[2].lang == ['ru', 'bg']
|
||||||
|
|
||||||
|
|
||||||
def test_src_in_special_cases(translator):
|
def test_src_in_special_cases(translator):
|
||||||
|
Loading…
Reference in New Issue
Block a user