1
#!/usr/local/bin/ruby -Ke
2
## Copyright (C) 2005 MITA Yuusuke <clefs@mail.goo.ne.jp>
4
## Author: MITA Yuusuke <clefs@mail.goo.ne.jp>
5
## Maintainer: SKK Development Team <skk@ring.gr.jp>
6
## Version: $Id: ipadic2skk.rb,v 1.3 2006/01/04 10:35:06 skk-cvs Exp $
7
## Keywords: japanese, dictionary
8
## Last Modified: $Date: 2006/01/04 10:35:06 $
10
## This program is free software; you can redistribute it and/or modify
11
## it under the terms of the GNU General Public License as published by
12
## the Free Software Foundation; either version 2, or (at your option)
15
## This program is distributed in the hope that it will be useful,
16
## but WITHOUT ANY WARRANTY; without even the implied warranty of
17
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
## General Public License for more details.
20
## You should have received a copy of the GNU General Public License
21
## along with this program, see the file COPYING. If not, write to the
22
## Free Software Foundation Inc., 51 Franklin St, Fifth Floor, Boston,
23
## MA 02110-1301, USA.
27
## This script tries to convert IPADIC dictionary files into skk ones.
29
## % ipadic2skk.rb ipadic-2.7.0/Noun.name.dic | skkdic-expr2 > SKK-JISYO.ipadic.jinmei
31
## would yield a lot of nifty jinmei additions.
33
## % ipadic2skk.rb -Ag ipadic-2.7.0/Verb.dic | conjugation.rb -opUC | skkdic-expr2 > SKK-JISYO.ipadic.verb
35
## With -g and -A options, this script can append grammatical annotations
36
## useful in combination with conjugation.rb.
38
## NOTE: skkdictools.rb should be in the ruby loadpaths to have this work.
44
opt = OptionParser.new
50
opt.on('-a', "convert Asayake into AsayaKe") { asayake_mode = "convert" }
51
opt.on('-A', "both Asayake and AsayaKe are output") { asayake_mode = "both" }
52
opt.on('-g', "append grammatical annotations") { grammar = true }
53
opt.on('-k', "generate hiragana-to-katakana pairs (�֤ͤ� /�ͥ�/��)") { skip_hira2kana = false }
54
opt.on('-K', "generate identical pairs (�֤ͤ� /�ͤ�/��)") { skip_identical = false }
58
rescue OptionParser::InvalidOption => e
59
print "'#{$0} -h' for help.\n"
65
next if $_ !~ /^\(�ʻ� \(([^)]*)\)\) \(\(���Ф��� \(([^ ]*) [0-9]*\)\) \(�ɤ� ([^ ]*)\)/
66
# (�ʻ� (̾�� ����)) ((���Ф��� (�ز� 3999)) (�ɤ� ���å�) (ȯ�� ���å�) )
67
next if skip_hira2kana && $2 == $3
70
key = $3.tr('��-��', '��-��').gsub(/��/, '����')
71
next if skip_identical && key == candidate
74
if grammar && $_ =~ /\(���ѷ� ([^)]*)\) \)$/
75
# (���ѷ� ���ʡ����¥����) )
76
conjugation = $1.sub(/^(..)��([��-��]��)/, '\2\1 ')
82
comment += " " + conjugation if !conjugation.nil?
85
# generate "#0"; complete-numerative.rb should do the rest
101
if key =~ /^\{(.*)\}([��-��]*)$/
103
# (�ɤ� {���ͥ�/���ͥ�})
109
keys.each do |midasi|
110
midasi += tail if !tail.nil?
111
next if skip_identical && midasi == candidate
114
if asayake_mode != "none"
115
new_midasi, new_candidate, postfix = okuri_nasi_to_ari(midasi, candidate)
119
comment_extra += "[iks(gm)]" if postfix == "��" && hinsi =~ /���ƻ�/
121
comment_extra += "[wiueot(c)]" if postfix == "��" && conjugation =~ /��Ը���/
122
comment_extra += "[gi]" if postfix == "��" && conjugation =~ /���Ը���/
123
comment_extra += "[mn]" if postfix == "��" && conjugation =~ /�Ը���/
124
comment_extra += "[*]" if postfix == "��" && conjugation =~ /����/
125
comment_extra += "[rt(cn)]" if postfix == "��" && conjugation =~ /��Ը���/
126
# this can be of problem
127
comment_extra += "[a-z]" if postfix == "��" && conjugation =~ /����/
129
#comment_extra += "[ki]" if postfix == "��" && conjugation =~ /���Ը���/
130
if postfix == "��" && conjugation =~ /���Ը���/
131
#if new_candidate =~ /��$/
132
if new_midasi =~ /��k$/
133
comment_extra += "[ktc]"
134
elsif new_midasi =~ /��k$/
135
comment_extra += "[k]"
137
comment_extra += "[ki]"
141
comment_extra += "(-#{postfix})"
142
#print_orig = false if !comment_extra.empty?
143
print_orig = false if hinsi =~ /ư��|���ƻ�/
145
print_pair(new_midasi, new_candidate, nil,
146
comment.delete("��") + comment_extra)
147
print_orig = false if asayake_mode != "both"
149
comment += "[��dn(s)]" if hinsi =~ /����ư��촴/
150
comment += "[��s]" if hinsi =~ /������³/
153
print_pair(midasi, candidate, nil, grammar ? comment : nil) if print_orig