我将 4GB 维基词典 XML 数据转储分解为更小的文件,没有重叠,用 Python 处理它并保存不同的页面 (...)。
相同的信息,在不同的文件中拆分,正在膨胀到 18+ GB。
为什么会这样?有没有办法避免这种情况?
import os
import re
import subprocess
subprocess.call(['mkdir', 'WIKTIONARY_WORDS_DUMP'])
# English Wiktionary (which noneless contains many foreign words!)
f = open('enwiktionary-20151020-pages-articles.xml', 'r')
page = False
number = 1
for i, l in enumerate(f):
if '<page>' in l:
word_file = open(os.path.join('WIKTIONARY_WORDS_DUMP', str(number)+'.xml'), 'a')
word_file.write(l)
page = True
number += 1
elif '</page>' in l:
word_file.write(l)
word_file.close()
page = False
elif page:
word_file.write(l)
word_file.close()
f.close()