-
Notifications
You must be signed in to change notification settings - Fork 6
/
process_wiki.py
36 lines (32 loc) · 1.04 KB
/
process_wiki.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
# -*- coding: utf-8 -*-
"""
@time: 1/3/2018 7:46 PM
@desc:
pre-processing of wiki corpus.
select the text from the original web files.
@author: guomianzhuang
"""
import os
import logging
import sys
from gensim.corpora import WikiCorpus
if __name__ == '__main__':
program = os.path.basename(sys.argv[0])
logger = logging.getLogger(program)
logging.basicConfig(format='%(asctime)s: %(levelname)s: %(message)s')
logging.root.setLevel(level=logging.INFO)
if len(sys.argv) < 3:
print(globals()['__doc__'] %locals())
sys.exit(1)
inp, outp = sys.argv[1:3]
space = ' '
i = 0
with open(outp, mode='w') as f:
wiki = WikiCorpus(inp, lemmatize=False, dictionary={})
for text in wiki.get_texts():
data = space.join(text)
f.write(str(data) + '\n')
i += 1
if i % 10000 == 0:
logger.info('Saved ' + str(i) + ' articles')
logger.info('Finished ' + str(i) + ' articles')