Skip to content

Instantly share code, notes, and snippets.

@nkpoid
Last active August 29, 2015 14:16
Show Gist options
  • Save nkpoid/684dca14cc2b8ce77f1f to your computer and use it in GitHub Desktop.
Save nkpoid/684dca14cc2b8ce77f1f to your computer and use it in GitHub Desktop.
dic2db.rb
#ねくろいどのしりとりに使われているdic.dbをipadicのdicファイルから自動生成するスクリプト
#変換したい.dicファイルを同ディレクトリ内にあるdicフォルダに入れて実行してください
require "kconv"
require "sqlite3"
@db = SQLite3::Database.open(File.expand_path("../dic.db", __FILE__))
@db.execute <<-SQL
CREATE TABLE IF NOT EXISTS dic
(word TEXT, reading TEXT)
SQL
files = Dir.glob(File.expand_path("../*.dic", __FILE__))
files.each do |file|
open(file) do |io|
io.each do |l|
l.toutf8 =~ /\(見出し語\s\((.+)\s.*\)\)\s\(読み\s(.+)\)\s\(/
word,yomi = $1,$2
next if !(word or yomi)
@db.execute"INSERT INTO dic VALUES (?,?)", [word, yomi]
$stderr.puts "Add -> #{word}(#{yomi})"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment