1 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
6 require "chise/management"
9 class IDS_DB_Management
11 @cd = ChiseDB.instance
12 @idsdb = IDS_DB.instance
15 def check_conflict_of_ids_text
16 @idsdb.each_ccs {|ccs|
20 @idsdb.get_ccs(ccs).each_character {|char, ids|
22 next if ids == char.to_s
23 next if ids.char_length == 1
24 char_id = char.char_id
26 if cids.nil? # There is no ids yet.
27 h[char_id] = ids # just set it.
29 else # but, if there is already a ids?
30 if cids == ids # the two are same.
31 c["same"] += 1 # and just ignore
32 else # but, if the two are not same?
34 puts "conflict\t#{char.to_s}\t#{ids}\t#{cids}"
38 puts "#{ccs}\t#{c['char']}\t#{c['same']}\t#{c['conflict']}\t#{c['good']}"
45 @idsdb.each_ccs {|ccs|
47 @idsdb.get_ccs(ccs).each_character {|char, ids|
48 next if ids == char.to_s
49 next if ids.char_length == 1
50 char.ids_text = ids # just set it.
52 # break if max <= h.length
54 # break if max <= h.length
56 qp "%08X" % h.keys.max
57 qp "sync", @cd.get_feature("ids-text").sync
58 @cd.get_feature("ids-text").dump
60 qp @cd.get_feature("ids-text").to_hash.length
65 @cd.get_feature("ids-text").each_char {|cid, ids_text|
66 char = Character.get(cid)
68 ids = ids_text.de_er # parse Entity Reference
73 next if ids == char.to_s
74 next if ids.char_length == 1
75 char.ids_de_er = ids # set it.
78 qp "%08X" % h.keys.max
79 @cd.get_feature("ids-de-er").dump
81 qp @cd.get_feature("ids-de-er").to_hash.length
84 def check_integrity_of_ids_tree
86 @cd.get_feature("ids-de-er").each_char {|cid, ids|
87 char = Character.get(cid)
88 idstree = IDS_Tree.new(ids)
90 raise "contains self" if ids.include?(char.to_s)
91 idstree.check_integrity
93 #puts "#{cid}\t#{e.message}\t#{ids}"
94 char.ids_error = e.message
97 char.ids_org = ids # set it.
100 @cd.get_feature("ids-org").dump
102 qp @cd.get_feature("ids-org").to_hash.length
103 @cd.get_feature("ids-error").dump
106 def make_by_ids_db_org
108 byids = @cd.get_ccs_str("ids-org")
109 @cd.get_feature("ids-org").each_char {|cid, ids|
110 char = Character.get(cid)
111 byids.set_by_str(ids, cid)
116 qp byids.to_hash.length
119 def store_ids_aggregated
121 @cd.get_feature("ids-org").each_char {|cid, ids|
122 char = Character.get(cid)
123 #ids = char.decompose
125 ag = ids.to_ids.aggregate("ids-org")
126 #puts "#{char.to_s}\t#{ids}\t#{ag}"
127 char.ids = ag # ids-aggregated
128 h[char.char_id] = ids
130 @cd.get_feature("ids").dump
132 qp @cd.get_feature("ids").to_hash.length
135 def store_ids_subparts
137 @cd.get_feature("ids").each_char {|cid, v|
138 char = Character.get(cid)
139 pids = char.to_s # previous_ids
141 i = 0 # only for infinite loop check
144 break if ids == pids # break if there is no possibilities.
147 qp [char.to_s, pids, ids, ar] if 10 < i # something wrong.
150 str = ar.sort.uniq.join("") # can contain IDC.
151 char.ids_subparts = str
152 h[char.char_id] = str
154 @cd.get_feature("ids-subparts").dump
156 qp @cd.get_feature("ids-subparts").to_hash.length
159 def store_ids_contained
161 @cd.get_feature("ids-subparts").each_char {|cid, v|
162 char = Character.get(cid)
163 parts = char.ids_subparts
164 parts.each_char {|ch|
165 h[ch] = [] if h[ch].nil?
170 str = ar.sort.map {|cid| Character.get(cid).to_s }.join
171 char.ids_contained = str
173 @cd.get_feature("ids-contained").dump
177 byids = @cd.get_ccs("ids")
178 @cd.get_feature("ids").each_char {|cid, ids|
179 char = Character.get(cid)
180 byids.set_by_str(ids, cid)
190 @config = Config.instance
191 @path = @config.ids_dir.path
197 @dbs[ccs] = IDS_CCS_DB.new(self, ccs) if @dbs[ccs].nil?
202 @path.each_entry {|f|
203 next unless /\AIDS-(.+)\.txt\Z/ =~ f
210 def initialize(idsdb, ccs)
211 @idsdb, @ccs = idsdb, ccs
212 @path = @idsdb.path+("IDS-"+ccs+".txt")
218 next if /\A;/ =~ line # skip comment
220 code, picture, ids = line.split
229 each_line {|code, ids|
231 next if ids == "" # If there is no IDS, ignore it.
235 char = Character.get(er)