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

« back to all changes in this revision

Viewing changes to convert2skk/ctdicconv.rb

  • Committer: Bazaar Package Importer
  • Author(s): Takao KAWAMURA
  • Date: 2003-09-18 15:31:09 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20030918153109-9ubs3wtb5pxtv8us
Tags: 1.1-1
* New upstream release.
* Fixed the extended description. (Closes: Bug#209892)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/ruby -Ke
 
2
require 'jcode'
 
3
 
 
4
# ctdicconv.rb -- convert china_taiwan.csv to SKK-JISYO dictionary format.
 
5
#
 
6
# Copyright (C) 2002 NAKAJIMA Mikio <minakaji@osaka.email.ne.jp>
 
7
#
 
8
# Author: NAKAJIMA Mikio <minakaji@osaka.email.ne.jp>
 
9
# Created: Aug 2, 2002
 
10
# Last Modified: $Date: 2002/08/01 21:39:37 $
 
11
# Version: $Id: ctdicconv.rb,v 1.1 2002/08/01 21:39:37 minakaji Exp $
 
12
 
 
13
# This file is part of Daredevil SKK.
 
14
 
 
15
# Daredevil SKK is free software; you can redistribute it and/or modify
 
16
# it under the terms of the GNU General Public License as published by
 
17
# the Free Software Foundation; either versions 2, or (at your option)
 
18
# any later version.
 
19
#
 
20
# Daredevil SKK is distributed in the hope that it will be useful
 
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
23
# GNU General Public License for more details.
 
24
#
 
25
# You should have received a copy of the GNU General Public License
 
26
# along with Daredevil SKK, see the file COPYING.  If not, write to the
 
27
# Free Software Foundation Inc., 59 Temple Place - Suite 330, Boston,
 
28
# MA 02111-1307, USA.
 
29
#
 
30
# Commentary:
 
31
 
 
32
$ANNOTATION = true
 
33
##$ANNOTATION = false
 
34
 
 
35
# from �֥��֥������Ȼظ�������ץȸ���ruby��p121
 
36
def csv_split(source, delimiter = ',')
 
37
  csv = []
 
38
  data = ""
 
39
  source.split(delimiter).each do |d|
 
40
    if data.empty?
 
41
      data = d
 
42
    else
 
43
      data += delimiter + d
 
44
    end
 
45
    if /^"/ =~ data
 
46
      if /[^"]"$/ =~ data or '""' == data
 
47
        csv << data.sub(/^"(.*)"$/, '\1').gsub(/""/, '"')
 
48
        data = ''
 
49
      end
 
50
    else
 
51
      csv << d
 
52
      data = ''
 
53
    end
 
54
  end
 
55
  raise "cannot decode CSV\n" unless data.empty?
 
56
  csv
 
57
end
 
58
 
 
59
file = ARGV.shift
 
60
 
 
61
if not file
 
62
  print "�ե��������ꤷ�Ʋ�����\n"
 
63
else
 
64
  first = true
 
65
  File.foreach(file) do |line|
 
66
    if first
 
67
      first = false
 
68
      next
 
69
    end
 
70
    #�������,����,�Ѹ츫�Ф�,����,���ܸ��ɤ�,�����ɤߡʥ������ʡ�,�Ѹ�ɸ��2,������̾,������̾�ɤ�,����,�����ɤ�,annotation
 
71
    c_t,d,e_key,kanji,j_key,c_key,english,kanji_alias,kanji_alias_key,capital,capital_key,annotation= csv_split(line.chomp)
 
72
    if (e_key && !e_key.empty? && kanji && !kanji.empty?)
 
73
      e_key.strip!
 
74
      kanji.strip!
 
75
      # �Ѹ츫�Ф� /����/
 
76
      if ($ANNOTATION && annotation && !annotation.empty?)
 
77
        annotation.strip!
 
78
        print e_key, " /", kanji, ";", annotation, "/\n"
 
79
      else
 
80
        print e_key, " /", kanji, "/\n"
 
81
      end
 
82
 
 
83
      # ���ܸ츫�Ф� /Capitalized �Ѹ�/
 
84
      if (j_key && !j_key.empty?)
 
85
        j_key.strip!
 
86
        if ($ANNOTATION && annotation && !annotation.empty?)
 
87
          annotation.strip!
 
88
          print j_key, " /", e_key.capitalize, ";", annotation, "/\n"
 
89
        else
 
90
          print j_key, " /", e_key.capitalize, "/\n"
 
91
        end
 
92
      end
 
93
    end
 
94
 
 
95
    if (j_key && !j_key.empty? && kanji && !kanji.empty?)
 
96
      # ���ܸ츫�Ф� /����/
 
97
      if ($ANNOTATION && annotation && !annotation.empty?)
 
98
        annotation.strip!
 
99
        print j_key, " /", kanji, ";", annotation, "/\n"
 
100
      else
 
101
        print j_key, " /", kanji, "/\n"
 
102
      end
 
103
    end
 
104
 
 
105
    if (c_key && !c_key.empty? && kanji && !kanji.empty?)
 
106
      c_key.strip!
 
107
      c_key.tr!("��-��", "��-��")
 
108
      # ���츫�Ф� /����/
 
109
      if ($ANNOTATION && annotation && !annotation.empty?)
 
110
        print c_key, " /", kanji, ";", annotation, "/\n"
 
111
      else
 
112
        print c_key, " /", kanji, "/\n"
 
113
      end
 
114
    end
 
115
    # ������̾���Ф� /������̾/
 
116
    if (kanji_alias && kanji_alias_key &&
 
117
        !kanji_alias.empty? && !kanji_alias_key.empty?)
 
118
      if ($ANNOTATION && annotation && !annotation.empty?)
 
119
        print kanji_alias_key, " /", kanji_alias, ";", annotation, "/\n"
 
120
      else
 
121
        print kanji_alias_key, " /", kanji_alias, "/\n"
 
122
      end
 
123
    end
 
124
    # ���Ը��Ф� /����/
 
125
    #if (capital && capital_key &&
 
126
    #    !capital.empty? && !capital_key.empty?)
 
127
    #  print capital_key, " /", capital, "/\n"
 
128
    #end
 
129
  end
 
130
end
 
131
 
 
132
# end of ctdicconv.rb