1#!/usr/bin/env ruby
2
3ENV["TOMOE_ENV"] ||= "benchmark"
4
5base = File.expand_path(File.dirname(__FILE__))
6require File.join(base, "init")
7
8ActiveRecord::Base.logger.level = Logger::INFO
9
10def utf8_to_ucs4(utf8)
11  if utf8
12    TomoeTestUtils::Unicode.utf8_to_ucs4(utf8)
13  else
14    nil
15  end
16end
17
18$LOAD_PATH.unshift(File.join(base, "lib"))
19
20migrate = File.join(base, "migrate.rb")
21print "purging DB..."
22$stdout.flush
23`#{migrate} 0`
24`#{migrate}`
25puts "done."
26
27filename = TomoeTestUtils::Path.dictionary
28dict = Tomoe::DictXML.new("filename" => filename,
29                          "editable" => false)
30config = TomoeTestUtils::Config.db_config.merge("editable" => true)
31mysql_dict = Tomoe::DictMySQL.new(config)
32
33cands = dict.search(Tomoe::Query.new)
34puts "dict size: #{cands.size}"
35
36print "converting..."
37$stdout.flush
38$KCODE = "u"
39cands.each_with_index do |cand, i|
40  mysql_dict.register(cand.char)
41  if (i % 1000).zero? and !i.zero?
42    print "#{i}."
43    $stdout.flush
44  end
45end
46puts "done."
47
48puts "converted characters: #{Char.count}"
49