文本预处理之中英文翻译

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from translate import Translator

translator = Translator(to_lang="Chinese")

text1 = 'Virtual Group Coaching: How to Improve Group Relationships in Remote Work Settings'
translation1 = translator.translate(text1)
print(translation1)

text2 = '虚拟小组辅导:How to Improve Group Relationships in Remote Work Settings'
translation2 = translator.translate(text2)
print(translation2)

def get_text(path):
f = open(path)
data = f.read()
f.close()
return data

text3 = get_text(r'D:\\1111.txt')
translation3 = translator.translate(text3)
print(translation3)