summaryrefslogtreecommitdiff
path: root/rr
blob: 30bf2d338cd741b87cab73e076c0e95d92ec874f (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
#!/usr/bin/env ruby

require 'zipf'

windows = []
cur = []
cur_sz = 0
while line = STDIN.gets
  if cur_sz >= 1000
    windows << cur
    cur = []
  else
    cur << line.strip
    cur_size += cur[-1].split.size
  end
end

windows.each { |w|
  h = {}
  h.default = 0
  w.each { |seg|
    ngrams(seg, 4) { |ng|
      h[ng] += 1
    }
  }
  puts h
}