squirrel2300

导航

wikipedia 维基百科 语料 获取 与 提取 处理 by python3.5

英文维基百科

https://dumps.wikimedia.org/enwiki/

中文维基百科

https://dumps.wikimedia.org/zhwiki/

全部语言的列表

https://dumps.wikimedia.org/backup-index.html

 

提取处理可以使用 wikiextractor提取正文(由于网页数量太多,结构又很纷乱,提取出来的会有少许瑕疵,再处理即可)

https://github.com/attardi/wikiextractor

运行命令:  python WikiExtractor.py -b 500M -o output_file_name  input_file_name.xml

 

Notice:

1. 建议处理解压后的文件

2. 如果在windows 下面跑,需要设置  fileinput.FileInput() 参数使用 utf-8 编码,如下:

input = fileinput.FileInput(input_file, openhook=fileinput.hook_encoded("utf-8"))

会冲掉原来的设置(跟压缩文件类型相关?):fileinput.FileInput(openhook=fileinput.hook_compressed)

参考:https://docs.python.org/3.5/library/fileinput.html

 

posted on 2017-10-27 20:33  squirrel2300  阅读(3539)  评论(0编辑  收藏  举报