1 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
3 require "chise/idstree"
10 IDC_4 = "\342\277\264"
11 IDC_5 = "\342\277\265"
12 IDC_6 = "\342\277\266"
13 IDC_7 = "\342\277\267"
14 IDC_8 = "\342\277\270"
15 IDC_9 = "\342\277\271"
16 IDC_A = "\342\277\272"
17 IDC_B = "\342\277\273"
19 IDC_LEFT_TO_RIGHT = IDC_0
20 IDC_ABOVE_TO_BELOW = IDC_1
21 IDC_LEFT_TO_MIDDLE_AND_RIGHT = IDC_2
22 IDC_ABOVE_TO_MIDDLE_AND_BELOW = IDC_3
23 IDC_FULL_SURROUND = IDC_4
24 IDC_SURROUND_FROM_ABOVE = IDC_5
25 IDC_SURROUND_FROM_BELOW = IDC_6
26 IDC_SURROUND_FROM_LEFT = IDC_7
27 IDC_SURROUND_FROM_UPPER_LEFT = IDC_8
28 IDC_SURROUND_FROM_UPPER_RIGHT = IDC_9
29 IDC_SURROUND_FROM_LOWER_LEFT = IDC_A
34 map_char {|ch| ch.char.decompose }
38 map_char {|ch| ch.char.decompose_all }
41 def ids_tree() IDS_Tree.new(self); end
43 def compose(dbname="ids")
46 byidsdb = cd.get_by_ids_db(dbname)
47 cid = byidsdb.decode(ids)
48 return "" if cid.nil? # TO CHECK: why "", not nil?
49 composed = Character.get(cid).to_s
50 return "" if composed.nil?
51 return "" if composed.char_length == 0
52 return composed if composed.char_length == 1
53 composed.each_char {|ch|
55 return ch # TO CHECK: the first character?
57 "" # TO CHECK: why "", not nil?
60 def aggregate(dbname="ids")
61 # In each sub part of IDS, search the corresponding char_id.
62 # If you could search the corresponding char_id, substitute with it.
64 tree = IDS_Tree.new(self)
65 return self if tree.depth <= 1 # no sub_node
66 tree.sub_nodes.each {|node|
67 c = node.compose(dbname)
68 next if c.nil? || c == ""
69 n = self.gsub(node, c)
70 return n.aggregate(dbname)
75 def find() # "日雲"→"曇"とかいう感じの操作
77 length = char_length()
80 ar << char.ids_contained #その文字を含んでいる漢字のリスト
93 if length == v #全部に顔を出していたら
104 0x2ff0 <= @char_id && @char_id <= 0x2fff
107 def idc_argument_number
108 return 0 unless is_idc?
109 return 3 if @char_id == 0x2ff2 || @char_id == 0x2ff3
115 def decompose_by_meaning
117 ids = self.ids_represent
118 return ids if ids && !ids.empty? && k != ids
119 ids = self.ids_element
120 return ids if ids && !ids.empty? && k != ids
121 ids = self.ids_meaning
122 return ids if ids && !ids.empty? && k != ids
126 def decompose # by glyph
129 return ids if ids && !ids.empty? && k != ids
131 return ids if ids && !ids.empty? && k != ids
137 de = self.decompose # the start point.
141 de = pde.decompose # decompose it again.
142 break if pde == de # previous is same.
143 exit if 10 < level # p ["too many recursive", self]