Last active
August 29, 2015 14:16
-
-
Save nkpoid/684dca14cc2b8ce77f1f to your computer and use it in GitHub Desktop.
dic2db.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ねくろいどのしりとりに使われている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