#!/usr/bin/env ruby
# ctow-analyzer: Analyze error logs of ctow command.
# $Id: ctow-analyzer,v 1.1 2003/12/29 21:59:26 komatsu Exp $
#
# Copyright (C) 2003 Hiroyuki Komatsu <komatsu@taiyaki.org>
#     All rights reserved.
#     This is free software with ABSOLUTELY NO WARRANTY.
#
# You can redistribute it and/or modify it under the terms of 
# the GNU General Public License version 2.

def analyze (io)
  @data = {}

  io.each {|line|
    if line !~ /^reading/ then
      next
    end
    data = line.chomp.split(/ /)
    if data[1] == "a" then
      next
    end

    pron    = data[0].split(/:/)[1]
    literal = data[1].split(/:/)[1]
    pos     = data[5].split(/:/)[1]

    if @data[pos].nil? then
      @data[pos] = [[pron, literal]]
    else
      @data[pos] << [pron, literal]
    end
  }

  @data.keys.each {|pos|
    puts format("%s:\t(%s, %s)", pos, *(@data[pos].first)) 
  }
  puts "=" * 60
  @data.keys.each {|pos|
    puts pos
    @data[pos].each {|(pron, literal)|
      puts format("  %20s %20s", pron, literal)
    }
  }
end

analyze($stdin)


# --- Text properties for Emacs. ---
# Local variables:
# mode: ruby
# End:
