~ubuntu-branches/ubuntu/trusty/skktools/trusty

« back to all changes in this revision

Viewing changes to convert2skk/ipadic2skk.rb

  • Committer: Bazaar Package Importer
  • Author(s): Tatsuya Kinoshita
  • Date: 2006-10-05 20:44:11 UTC
  • mfrom: (1.2.1 upstream) (3.1.1 edgy)
  • Revision ID: james.westby@ubuntu.com-20061005204411-25mr105z6mhhvrtv
Tags: 1.2+0.20061004-1
* New upstream release. (CVS trunk on 2006-10-04)
* debian/rules: Use "nkf -e" instead of "qkc" for `doc2skk.sh'.
* debian/skkdic-sort.1: Typo fix.
* debian/skk2cdb: Put $OUTFILE in double quotes.
* debian/control (Suggests): Add required packages for `doc2skk.sh',
  `chasen, mecab, kakasi, nkf, w3m'.
* debian/control (Description): Revised.
* debian/copyright: Updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/local/bin/ruby -Ke
 
2
## Copyright (C) 2005 MITA Yuusuke <clefs@mail.goo.ne.jp>
 
3
##
 
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 $
 
9
##
 
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)
 
13
## any later version.
 
14
 
 
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.
 
19
 
 
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.
 
24
##
 
25
### Instruction:
 
26
##
 
27
## This script tries to convert IPADIC dictionary files into skk ones.
 
28
##
 
29
##     % ipadic2skk.rb ipadic-2.7.0/Noun.name.dic | skkdic-expr2 > SKK-JISYO.ipadic.jinmei
 
30
##
 
31
## would yield a lot of nifty jinmei additions.
 
32
##
 
33
##     % ipadic2skk.rb -Ag ipadic-2.7.0/Verb.dic | conjugation.rb -opUC | skkdic-expr2 > SKK-JISYO.ipadic.verb
 
34
##
 
35
## With -g and -A options, this script can append grammatical annotations
 
36
## useful in combination with conjugation.rb.
 
37
##
 
38
## NOTE: skkdictools.rb should be in the ruby loadpaths to have this work.
 
39
##
 
40
require 'jcode'
 
41
#require 'kconv'
 
42
require 'skkdictools'
 
43
require 'optparse'
 
44
opt = OptionParser.new
 
45
skip_identical = true
 
46
skip_hira2kana = true
 
47
grammar = false
 
48
asayake_mode = "none"
 
49
 
 
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 }
 
55
 
 
56
begin
 
57
  opt.parse!(ARGV)
 
58
rescue OptionParser::InvalidOption => e
 
59
  print "'#{$0} -h' for help.\n"
 
60
  exit 1
 
61
end
 
62
 
 
63
while gets
 
64
  #line = $_.toeuc
 
65
  next if $_ !~ /^\(�ʻ� \(([^)]*)\)\) \(\(���Ф��� \(([^ ]*) [0-9]*\)\) \(�ɤ� ([^ ]*)\)/
 
66
  # (�ʻ� (̾�� ����)) ((���Ф��� (�ز� 3999)) (�ɤ� ���å�) (ȯ�� ���å�) )
 
67
  next if skip_hira2kana && $2 == $3
 
68
  hinsi = $1
 
69
  candidate = $2
 
70
  key = $3.tr('��-��', '��-��').gsub(/��/, '����')
 
71
  next if skip_identical && key == candidate
 
72
 
 
73
  conjugation = nil
 
74
  if grammar && $_ =~ /\(���ѷ� ([^)]*)\) \)$/
 
75
    # (���ѷ� ���ʡ����¥����) )
 
76
    conjugation = $1.sub(/^(..)��([��-��]��)/, '\2\1 ')
 
77
  end
 
78
 
 
79
  comment = nil
 
80
  if grammar
 
81
    comment = hinsi
 
82
    comment += " " + conjugation if !conjugation.nil?
 
83
    if hinsi =~ /��Ƭ��/
 
84
      if hinsi =~ /����³/
 
85
        # generate "#0"; complete-numerative.rb should do the rest
 
86
        candidate += "#0"
 
87
        key += "#"
 
88
      else
 
89
        comment += "[��>]"
 
90
      end
 
91
    elsif hinsi =~ /����/
 
92
      if hinsi =~ /������/
 
93
        comment += "[��#]"
 
94
      else
 
95
        comment += "[��<]"
 
96
      end
 
97
    end
 
98
  end
 
99
 
 
100
  tail = ""
 
101
  if key =~ /^\{(.*)\}([��-��]*)$/
 
102
    tail = $2
 
103
    # (�ɤ� {���ͥ�/���ͥ�})
 
104
    keys = $1.split("/")
 
105
  else
 
106
    keys = key
 
107
  end
 
108
 
 
109
  keys.each do |midasi|
 
110
    midasi += tail if !tail.nil?
 
111
    next if skip_identical && midasi == candidate
 
112
    print_orig = true
 
113
 
 
114
    if asayake_mode != "none"
 
115
      new_midasi, new_candidate, postfix = okuri_nasi_to_ari(midasi, candidate)
 
116
      if !new_midasi.nil?
 
117
        comment_extra = ""
 
118
        if grammar
 
119
          comment_extra += "[iks(gm)]" if postfix == "��" && hinsi =~ /���ƻ�/
 
120
 
 
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 =~ /����/
 
128
 
 
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]"
 
136
            else
 
137
              comment_extra += "[ki]"
 
138
            end
 
139
          end
 
140
 
 
141
          comment_extra += "(-#{postfix})"
 
142
          #print_orig = false if !comment_extra.empty?
 
143
          print_orig = false if hinsi =~ /ư��|���ƻ�/
 
144
        end
 
145
        print_pair(new_midasi, new_candidate, nil,
 
146
                    comment.delete("��") + comment_extra)
 
147
        print_orig = false if asayake_mode != "both"
 
148
      else
 
149
        comment += "[��dn(s)]" if hinsi =~ /����ư��촴/
 
150
        comment += "[��s]" if hinsi =~ /������³/
 
151
      end
 
152
    end
 
153
    print_pair(midasi, candidate, nil, grammar ? comment : nil) if print_orig
 
154
  end
 
155
end