翻译机

来源:互联网 发布:biz cc 域名 哪个好 编辑:程序博客网 时间:2024/06/07 03:22
Dict = {    'i':u'我','my':u'我的','is':u'是', 'name':u'名字','that':u'这','hello':u'大家好', 'guys':u'伙伴们',    'like':u'喜欢', 'computer':u'计算机', 'graphic':u'图形图像','especially':u'尤其是',    'vfx':u'视觉特效','loli':u'萝莉', 'life':u'生活','lambert':u'兰伯特'}Text = '''Hello guysMy name is LambertI like computer graphic especially VFXI like LOLIThat is my life'''def translateMachine(word):    convert = word.lower()    if convert not in Dict:        return word    return Dict[convert]def translateSentence(sentence):    wordsInSentence = sentence.split(' ')    chineseSentence = ''    for i in wordsInSentence:        chineseSentence +=translateMachine(i)    return chineseSentencedef translateText(text):    sentencesInText =text.split('\n')    chineseText = ''    for j in sentencesInText:        chineseText += translateSentence(j)        chineseText += '\n'    return chineseTextprint(translateText(Text))
0 0
原创粉丝点击