棋譜の選別

こんな感じのスクリプトで 2chkifu.csa からトッププロ同士だけの棋譜を選別する。
棋士名の配列に名前足していけば、それらの全ての組み合わせに該当する棋譜を取得出来る。

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

if ARGV.size != 2
  puts "USAGE: " + __FILE__ + " <input 2chkifu (utf8)>  <output 2chkifu (utf8)>"
  exit
end

Specialist = [
              "羽生善治",
              "谷川浩司",
              "森内俊之",
             ]

def include?(line)
  Specialist.combination(2).each do |i|
    if line.include?(i[0]) && line.include?(i[1]) && !line.include?("")
      return true
    end
  end
  return false
end

f = open(ARGV[0], "rb")
o = open(ARGV[1], "wb")
while line = f.gets
  if include?(line)
    o.print line
    o.print f.gets
  end
end

f.close
o.close