summaryrefslogtreecommitdiff
path: root/add_seg
blob: e4fe22d046c276b0ed0b6be71386727b1d08f201 (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
34
35
36
#!/usr/bin/env ruby

require 'trollop'
require 'zipf'

cfg = Trollop::options do
  opt :grammar, "(Absolute) path of folder containing grammars.", :type => :string, :short => '-g', :required => true
  opt :loo, "leave one out", :type => :bool, :default => false
  opt :start_id, "start with this id", :type => :int, :default => 0, :short => '-i'
  opt :nogz, "grammar files not gzipped", :type => :bool, :default => false
  opt :index, "number according to index", :type => :string, :default => nil
end

index = []
if cfg[:index]
  index = ReadFile.readlines_strip(cfg[:index]).map{ |i| i.to_i }
end

i = cfg[:start_id]
j = 0
while line = STDIN.gets
  ext = '.gz'
  ext = '' if cfg[:nogz]
  s = "<seg"
  if cfg[:loo] then s += " exclude=\"#{i}\"" end
  if index.size > 0
    puts s + " id=\"#{index[j]}\"> #{line.strip} </seg>"
    if cfg[:grammar] then s += " grammar=\"#{cfg[:grammar]}/grammar.#{index[j]}#{ext}\"" end
  else
    if cfg[:grammar] then s += " grammar=\"#{cfg[:grammar]}/grammar.#{i}#{ext}\"" end
    puts s + " id=\"#{i}\"> #{line.strip} </seg>"
  end
  i += 1
  j += 1
end