Wikipedia の XML データからリダイレクトの項目以外のものを出力する

月曜日, 5月 12th, 2008 | Author: いなば

作業めもめも。

#!/usr/bin/ruby

target = ARGV[0]

redirectFlag = false
buffer = String.new

fh = open(target)
fh.each { |line|
buffer += line

if /<comment>redirect<\/comment>/ =~ line
redirectFlag = true
end

if /<\/page>/ =~ line
print "#{buffer}\n" if redirectFlag == false
buffer = ""
redirectFlag = false
end
}

実行

./delredirect.rb jawiki-20070903-pages-articles.xml

全件対象にして、8分ほどで出力終了。

grep '<page>' noredirect.xml | wc -l

で調べてみると、774490件。おかしいな。動作確認用にWikipediaの小さなサンプルを作ってみるで確認したデータと見比べても件数が減っていなさすぎる。
むむぅ。要再検討だな。

Category: めも, 研究
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>