diff options
author | Patrick Simianer <p@simianer.de> | 2016-04-08 23:19:28 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2016-04-08 23:19:28 +0200 |
commit | 34d621606e58adeb35aa33f8503e105189a7c0d5 (patch) | |
tree | 18931029e5ceed1e2c2d77bfdf2b87a216633366 /rerank_output_lists.rb | |
parent | 81f6b20d1c41d8906900c57ab71ec08a007ea02c (diff) |
Diffstat (limited to 'rerank_output_lists.rb')
-rwxr-xr-x | rerank_output_lists.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/rerank_output_lists.rb b/rerank_output_lists.rb new file mode 100755 index 0000000..22bd9ca --- /dev/null +++ b/rerank_output_lists.rb @@ -0,0 +1,48 @@ +#!/usr/bin/env ruby + +require 'zipf' + +class KbestItem + attr_accessor :rank, :model, :rr, :gold, :f + def initialize s + a = s.split "\t" + @rank = a[0].to_i + @gold = a[1].to_f + @model = a[2].to_f + @rr = -1.0 + @f = SparseVector.from_kv a[3], "=", " " + end + + def to_s + return "#{@model}\t#{@gold}\t#{@rank}\t#{@rr}" + end +end + +w = SparseVector.from_kv ReadFile.new(ARGV[0]).read, "\t", "\n" + +def o kl, j + f = WriteFile.new "lists/#{j}.model" + g = WriteFile.new "lists/#{j}.rr" + kl.each { |i| + f.write "#{i.gold}\t#{i.model}\n" + g.write "#{i.gold}\t#{i.rr}\n" + } +end + +`mkdir -p lists` +STDERR.write "reranking..\n" +cur = [] +k_sum = 0 +j = 0 +while line = STDIN.gets + item = KbestItem.new line.strip + item.rr = w.dot(item.f) + if item.rank == 0 && cur.size > 0 + o cur, j + cur = [] + j += 1 + end + cur << item +end +o cur, j + |