Skip to content

Instantly share code, notes, and snippets.

@nakagami
Last active April 6, 2018 00:31
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 nakagami/c1536669147f51a0d0cd92af3e199bf4 to your computer and use it in GitHub Desktop.
Save nakagami/c1536669147f51a0d0cd92af3e199bf4 to your computer and use it in GitHub Desktop.
ウィキペディア日本語版で多く参照されているページ
"""ウィキペディア日本語版のアーカイブファイルから多く参照されているページをリスト
https://dumps.wikimedia.org/jawiki/latest/ に最新のアーカイブファイルが存在する
以下のコマンドで記事が1ファイルになった jawiki-latest-pages-articles.xml をカレントディレクトリにおいてからスクリプトを実行
::
curl https://dumps.wikimedia.org/jawiki/latest/jawiki-latest-pages-articles.xml.bz2 |bzcat > jawiki-latest-pages-articles.xml
"""
import collections
import re
LINK_RE = re.compile("\\[\\[(.+?)\\]\\]")
def find_link(f):
for s in f:
for word in LINK_RE.findall(s):
if not re.search('[:0-9]', word):
yield word
wordcount = collections.Counter(find_link(open('jawiki-latest-pages-articles.xml', 'r', encoding='utf-8')))
for e in wordcount.most_common(1000):
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment