Created
January 25, 2017 11:10
-
-
Save wannaphong/5b3aca85f64aca3e28a3199fb24f935d to your computer and use it in GitHub Desktop.
fork https://github.com/wbap/Hackathon2015/blob/master/Tsuzuki/kusokora/process_wiki.py . It can run in Python 3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import os.path | |
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) | |
logger.info("running %s" % ' '.join(sys.argv)) | |
# check and process input arguments | |
if len(sys.argv) < 3: | |
print((globals()['__doc__'] % locals())) | |
sys.exit(1) | |
inp, outp = sys.argv[1:3] | |
space = b' ' | |
i = 0 | |
output = open(outp, 'w', encoding='utf-8') | |
wiki = WikiCorpus(inp, lemmatize=False, dictionary={}) | |
for text in wiki.get_texts(): | |
list1=space.join(text) | |
output.write((list1.decode('utf-8')) + "\n") | |
i+=1 | |
if (i % 10000 == 0): | |
logger.info("Saved " + str(i) + " articles") | |
output.close() | |
logger.info("Finished Saved " + str(i) + " articles") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment