Skip to content

Instantly share code, notes, and snippets.

@koko-u
Created May 10, 2011 02:22
Show Gist options
  • Save koko-u/963817 to your computer and use it in GitHub Desktop.
Save koko-u/963817 to your computer and use it in GitHub Desktop.
英辞郎のTXTファイルをStardictの扱えるTAB形式に変換
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# 英辞郎が提供する txt ファイルを Stardict が読める .tab 形式に変換する
# iconv の Shift_jis -> Utf-8 変換はうまくないみたいなので、nkf を使いましょう。
# cat EIJI-129.TXT | nkf -w8Lu | ./mkstardicttab > eijirou.tab
# 最終的には stardict-tools の tabfile を使って
# /usr/lib/stardict-tools/tabfile eijirou.tab
# としてできたファイルを /usr/share/stardict/dic に置く
ARGF.each do |line|
attr = line[/ \{(.+?)\}/, 1]
key, content = line.gsub('■・', '\n・').gsub(/■/, '').sub(/ \{(.+?)\}/, '').split(' : ')
puts "#{key}\t#{"【#{attr}】" if attr}#{content}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment