首页 > 其他 > 详细

中文维基数据处理 - 1. 下载与清洗

时间:2017-11-25 12:10:49      阅读:296      评论:0      收藏:0      [点我收藏+]

1. 数据下载

一些重要的链接:

  1. 最新转储
    需要 zhwiki-latest-pages-articles.xml.bz2 这个文件
  2. 中文维基的页面统计信息
    目前内容页面数大约是 978K

2. 数据处理

选择了 Gensim 这个主题工具包进行数据预处理。

2.1 xml 转 json

scripts.segment_wiki

python -m gensim.scripts.segment_wiki -f zhwiki-latest-pages-articles.xml.bz2 | gzip > zhwiki-latest.json.gz

然后就转换成了可被 Python 直接读取的 json 文档。

2.2 测试数据

from smart_open import smart_open
import json
x = 0

for line in smart_open(‘zhwiki-latest.json.gz‘):
     article = json.loads(line)

     print("Article title: %s" % article[‘title‘])
     for section_title, section_text in zip(article[‘section_titles‘], article[‘section_texts‘]):
         print("Section title: %s" % section_title)
         print("Section text: %s" % section_text)

     x += 1
     if x == 5:
         break

运行如上代码可以输出中文维基中的前 5 篇文档。

2.3 分词 / 命名实体识别 / 关系抽取

没写。

中文维基数据处理 - 1. 下载与清洗

原文:http://www.cnblogs.com/nlp-in-shell/p/7894719.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!