python conver_zn2en

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python conver_zn2en相关的知识,希望对你有一定的参考价值。

from bs4 import BeautifulSoup
punctuation = '.,!:;?\"\(\)'# 待匹配符号    
source_path = '/Users/allen/Desktop/xiyu_TASK/8998574100415488_wordplus.xml'# 正确xml路径
target_path = '/Users/allen/Desktop/xiyu_TASK/8998574100415488_word.xml'# 待修改xml路径
revise_path = '8998574100415488_word_revised2.xml'

with open(source_path, 'r') as source,\
open(target_path, 'r') as target, open(revise_path, 'w') as new:
    temp = ''''''
    
    soup_word = BeautifulSoup(target, 'xml')
    soup_wordplus = BeautifulSoup(source, 'xml')
    soup_new = BeautifulSoup(temp, 'xml')
    
    soup_new.append(soup_word)
    
    entries_word = soup_new.find_all('Word')
    entries_word2 = soup_wordplus.find_all('Word')

    for word, word2 in zip(entries_word, entries_word2):
        content = word.find('Text').string
        for char in content:
            if char in punctuation:
                glyphs = word2.find_all('Glyph')
                s = ""
                for glyph in glyphs:
                    s += glyph.string
                word.find('Text').string.replace_with(s)
    new.write(str(soup_new))

以上是关于python conver_zn2en的主要内容,如果未能解决你的问题,请参考以下文章

今天发现一个好玩的翻译接口

正则化和归一化

Apache不服务H2

升级到Apache 2.4.6后出错

使用JDK获取安卓秘钥散列

使用JDK获取安卓秘钥散列