Last active
April 6, 2018 00:31
-
-
Save nakagami/c1536669147f51a0d0cd92af3e199bf4 to your computer and use it in GitHub Desktop.
ウィキペディア日本語版で多く参照されているページ
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
"""ウィキペディア日本語版のアーカイブファイルから多く参照されているページをリスト | |
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