blob: 1199453c2220cce30c5ab90d3a5fc46ae389fac6 (
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
|
#!/usr/bin/env ruby
CHUNK = ARGV[1].to_i
stats = {"__SETTINGS__" => {"__CHUNK__" => CHUNK}}
words = File.readlines(ARGV[0])
.map(&:split)
.flatten
(0 .. (words.length - CHUNK - CHUNK)).each do |i|
k = words[i...(i+CHUNK)]
v = words[(i+CHUNK)]
if stats.include?(k) then
t = stats[k]
if t.include?(v) then
t[v] += 1
else
t[v] = 1
end
else
stats[k] = Hash.new
stats[k][v] = 1
end
end
File.new(ARGV[2], "w").print(Marshal::dump(stats))
|