Skip to content

Instantly share code, notes, and snippets.

@theo-m
Created October 4, 2017 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theo-m/868b5e311422b27c2d81166a33da5098 to your computer and use it in GitHub Desktop.
Save theo-m/868b5e311422b27c2d81166a33da5098 to your computer and use it in GitHub Desktop.
unwrap wiki
#-- 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