Created
October 4, 2017 16:41
-
-
Save theo-m/868b5e311422b27c2d81166a33da5098 to your computer and use it in GitHub Desktop.
unwrap wiki
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
#-- this script is not my own, I modified it from a Gensim tutorial --# | |
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)) | |
inp, outp = sys.argv[1:3] | |
space = " " | |
i = 0 | |
output = open(outp, 'w') | |
wiki = WikiCorpus(inp, lemmatize=False, dictionary={}) | |
for text in wiki.get_texts(): | |
output.write(' '.join(map(lambda t: t.decode('utf-8'), text)) + "\n") | |
i = 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