-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcombination_mta.py
131 lines (114 loc) · 4.39 KB
/
combination_mta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import translators as ts
from translate import Translator
print("Please input an English question:")
english_qns = input()
def google_block(eng_qns):
# translate the English question to Chinese using Google
eng_chi_google = ts.google(eng_qns, 'en', 'zh-CN')
# the list of questions translated from Chinese to English
the_list = []
# Google
chi_eng_google = ts.google(eng_chi_google, 'zh', 'en')
the_list.append(chi_eng_google)
# Bing
translator = Translator(from_lang="zh", to_lang="en")
chi_eng_bing = translator.translate(eng_chi_google)
the_list.append(chi_eng_bing)
# Youdao
chi_eng_youdao = ts.youdao(eng_chi_google, 'zh', 'en')
the_list.append(chi_eng_youdao)
# Tencent
chi_eng_tencent = ts.tencent(eng_chi_google, 'zh', 'en')
the_list.append(chi_eng_tencent)
return the_list
def bing_block(eng_qns):
# translate the English question to Chinese using Bing
translator = Translator(from_lang="en", to_lang="zh")
eng_chi_bing = translator.translate(eng_qns)
# the list of questions translated from Chinese to English
the_list = []
# Google
chi_eng_google = ts.google(eng_chi_bing, 'zh', 'en')
the_list.append(chi_eng_google)
# Bing
translator = Translator(from_lang="zh", to_lang="en")
chi_eng_bing = translator.translate(eng_chi_bing)
the_list.append(chi_eng_bing)
# Youdao
chi_eng_youdao = ts.youdao(eng_chi_bing, 'zh', 'en')
the_list.append(chi_eng_youdao)
# Tencent
chi_eng_tencent = ts.tencent(eng_chi_bing, 'zh', 'en')
the_list.append(chi_eng_tencent)
return the_list
def youdao_block(eng_qns):
# translate the English question to Chinese using Youdao
eng_chi_youdao = ts.youdao(eng_qns, 'en', 'zh-CN')
# the list of questions translated from Chinese to English
the_list = []
# Google
chi_eng_google = ts.google(eng_chi_youdao, 'zh', 'en')
the_list.append(chi_eng_google)
# Bing
translator = Translator(from_lang="zh", to_lang="en")
chi_eng_bing = translator.translate(eng_chi_youdao)
the_list.append(chi_eng_bing)
# Youdao
chi_eng_youdao = ts.youdao(eng_chi_youdao, 'zh', 'en')
the_list.append(chi_eng_youdao)
# Tencent
chi_eng_tencent = ts.tencent(eng_chi_youdao, 'zh', 'en')
the_list.append(chi_eng_tencent)
return the_list
def tencent_block(eng_qns):
# translate the English question to Chinese using Youdao
eng_chi_tencent = ts.tencent(eng_qns, 'en', 'zh-CN')
# the list of questions translated from Chinese to English
the_list = []
# Google
chi_eng_google = ts.google(eng_chi_tencent, 'zh', 'en')
the_list.append(chi_eng_google)
# Bing
translator = Translator(from_lang="zh", to_lang="en")
chi_eng_bing = translator.translate(eng_chi_tencent)
the_list.append(chi_eng_bing)
# Youdao
chi_eng_youdao = ts.youdao(eng_chi_tencent, 'zh', 'en')
the_list.append(chi_eng_youdao)
# Tencent
chi_eng_tencent = ts.tencent(eng_chi_tencent, 'zh', 'en')
the_list.append(chi_eng_tencent)
return the_list
# Return whole list of generated questions from the combination of machine translation applications
def combination_mta(eng_qns):
# Combine all 4 blocks
whole_list = google_block(eng_qns) + bing_block(eng_qns) + youdao_block(eng_qns) + tencent_block(eng_qns)
# return whole_list
print(*whole_list, sep="\n")
combination_mta(english_qns)
def remove_punctuation(string):
# punctuation marks
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
# traverse the given string and if any punctuation
# marks occur replace it with null
for x in string.lower():
if x in punctuations:
string = string.replace(x, "")
# Print string without punctuation
return string
# Returns a unique list of generated questions
def uni_combination_mta(eng_qns):
# Combine all 4 blocks
whole_list = google_block(eng_qns) + bing_block(eng_qns) + youdao_block(eng_qns) + tencent_block(eng_qns)
# Remove punctuations in all strings
no_punc_list = []
for i in range(len(whole_list)):
no_punc_list.append(remove_punctuation(whole_list[i]))
# Generate the unique list of generated questions
new_list = []
for j in range(len(no_punc_list)):
new_list.append(no_punc_list[j].lower())
uni_list = list(set(new_list))
# return uni_list
print(*uni_list, sep="\n")
# uni_combination_mta(english_qns)