summaryrefslogtreecommitdiff
path: root/storage/mroonga/vendor/groonga/examples/dictionary/gene95/gene2grn.rb
blob: 0d10cfd1085729a33ad7b5e126e5591980ffce9f (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
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

$KCODE = 'u'

require 'kconv'

class String
  def to_json
    a = split(//).map {|char|
      case char
      when '"' then '\\"'
      when '\\' then '\\\\'
      when "\b" then '\b'
      when "\f" then '\f'
      when "\n" then '\n'
      when "\r" then ''
      when "\t" then '\t'
      else char
      end
    }
    "\"#{a.join('')}\""
  end
end

class Array
  def to_json
    '[' + map {|element|
      element.to_json
    }.join(',') + ']'
  end
end

puts <<END
column_create item_dictionary gene95_desc COLUMN_SCALAR ShortText
column_create bigram item_dictionary_gene95_desc COLUMN_INDEX|WITH_POSITION item_dictionary gene95_desc
load --table item_dictionary
[["_key","gene95_desc"],
END

while !STDIN.eof?
  key = Kconv.toutf8(gets.strip)
  body = Kconv.toutf8(gets.strip)
  puts [key, body].to_json
end
puts ']'