Conversion_Kitchen_Code/kitchen_counter/conversion/translation/translation_comparison.py

53 lines
2.0 KiB
Python
Raw Normal View History

2024-04-27 09:33:09 +00:00
from translation_resources import ibm_watson, google, aws, azure, lingvanex, yandex
from final_translation1.py import compare_outputs
def dial_comparison_ph1a(text, source_lang, target_lang):
print(source_lang)
print(target_lang)
translated_text=[]
sources_name = {'0':'Google', '1':'AWS', '2':'Azure', '3':'Lingvanex', '4':'Yandex'}
sentences=sentence_tokenize.sentence_split(text, lang=source_lang)
for sentence in sentences:
print(sentence)
if sentence == "":
continue
t0 = google(sentence, source_lang, target_lang)
#print(t0)
t1 = aws(sentence, source_lang, target_lang)
#print(t1)
t2 = azure(sentence, target_lang)
#print(t2)
t3 = lingvanex(sentence, source_lang, target_lang)
#print(t3)
t4 = yandex(sentence, source_lang, target_lang)
#print(t4)
trans = {'0':t0, '1':t1, '2':t2, '3':t3, '4':t4}
trans_text = compare_outputs(sentence, t0, trans, sources_name)
translated_text.append(trans_text)
return " ".join(translated_text)
def dial_comparison_ph1b(text, source_lang, target_lang):
translated_text=[]
sources_name = {'0':'Google', '1':'IBM_Watson', '2':'AWS', '3':'Azure', '4':'Lingvanex', '5':'Yandex'}
sentences=sentence_tokenize.sentence_split(text, lang=source_lang)
for sentence in sentences:
print(sentence)
if sentence == "":
continue
t0 = google(sentence, source_lang, target_lang)
#print(t0)
t1 = ibm_watson(sentence, source_lang, target_lang)
#print(t1)
t2 = aws(sentence, source_lang, target_lang)
#print(t2)
t3 = azure(sentence, target_lang)
#print(t3)
t4 = lingvanex(sentence, source_lang, target_lang)
#print(t4)
t5 = yandex(sentence, source_lang, target_lang)
#print(t5)
trans = {'0':t0, '1':t1, '2':t2, '3':t3, '4':t4, '5':t5}
trans_text = compare_outputs(sentence, t0, trans, sources_name)
translated_text.append(trans_text)
return " ".join(translated_text)