blob: f090da98c041092afd9a506407fb84816d709a91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#!/usr/bin/env ruby
require 'zipf'
require 'optimist'
require 'zlib'
conf = Optimist::options do
opt :weights_files, "a number of weights files: name value", :required => true
opt :filter, "Filter if key does not appear in every file.", :type => :bool, :default => false
end
h = {}
ARGV.each { |fn|
f = ReadFile.new fn
while line = f.gets
k, v = line.split
v = v.to_f
if h.has_key? k
h[k] << v
else
h[k] = [v]
end
end
f.close
}
n = ARGV.size.to_f
h.each_pair { |k,w|
next if conf[:filter] and w.size < n
puts "#{k} #{w.inject(:+)/n}"
}
|