blob: dbc59ebaceb2b48aada4e8772192f685fbb4e1f3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#!/usr/bin/env ruby
require 'nlp_ruby'
require 'trollop'
cfg = Trollop::options do
banner "ng < <input>"
opt :n, "n for Ngrams", :type => :int, :default => 4
opt :fix, "Don't output lower order Ngrams.", :type => :bool, :default => false
opt :separator, "separte ngrams of a line by this string", :type => :string, :default => "\n"
end
while line = STDIN.gets
a = []
ngrams(line, cfg[:n], cfg[:fix]) { |ng| a << ng.join(' ') }
a.reject! { |i| i.strip.size==0 }
puts a.join cfg[:separator] if a.size>0
end
|