Debian Codegraph @

examples/dictionary/edict/edict2grn.rb

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/bin/env ruby
2
3 require "English"
4 require "nkf"
5 require "json"
6
7 print(<<HEADER.chomp)
8 column_create item_dictionary edict_desc COLUMN_SCALAR ShortText
9 column_create bigram item_dictionary_edict_desc COLUMN_INDEX|WITH_POSITION item_dictionary edict_desc
10 load --table item_dictionary
11 [
12 ["_key","edict_desc","kana"]
13 HEADER
14
15 loop do
16 raw_line = gets
17 break if raw_line.nil?
18
19 line = raw_line.encode("UTF-8", "EUC-JP")
20 keys, body = line.strip.split("/", 2)
21 keys = keys.strip
22 if /\s*\[(.+)\]\z/ =~ keys
23 keys = $PREMATCH
24 readings = $1
25 body = "[#{readings}] #{body}"
26 kana = readings.split(";").collect do |reading|
27 NKF.nkf("-Ww --katakana", reading)
28 end
29 keys.split(";").each do |key|
30 puts(",")
31 print([key, body, [key, *kana].uniq].to_json)
32 end
33 else
34 keys.split(";").each do |key|
35 puts(",")
36 kana = NKF.nkf("-Ww --katakana", key)
37 print([key, body, [key, kana].uniq].to_json)
38 end
39 end
40 end
41 puts
42 puts("]")