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']}"
43 @idsdb.each_ccs {|ccs|
45 @idsdb.get_ccs(ccs).each_character {|char, ids|
46 next if ids == char.to_s
47 next if ids.char_length == 1
48 char.ids_text = ids # just set it.
51 @cd.get_feature("ids-text").dump
55 @cd.get_feature("ids-text").each_char {|cid, idser|
56 char = Character.get(cid)
58 ids = idser.de_er # parse Entity Reference
63 char.ids_de_er = ids # set it.
65 @cd.get_feature("ids-de-er").dump
68 def check_integrity_of_ids_tree
69 @cd.get_feature("ids-de-er").each {|cid, ids|
70 char = Character.get(cid)
71 idstree = IDS_Tree.new(ids)
73 raise "contains self" if ids.include?(char.to_s)
74 idstree.check_integrity
76 #puts "#{cid}\t#{e.message}\t#{ids}"
77 char.ids_error = e.message
80 char.ids = ids # set it.
82 @cd.get_feature("ids").dump
83 @cd.get_feature("ids-error").dump
87 ct = @cd.get_by_ids_db("ids")
88 @cd.get_feature("ids").each {|cid, ids|
89 char = Character.get(cid)
90 ct.set_decoded_char(ids, cid)
95 def store_ids_aggregated
96 @cd.get_feature("ids").each {|cid, ids|
97 char = Character.get(cid)
100 ag = ids.to_ids.aggregate
101 #puts "#{char.to_s}\t#{ids}\t#{ag}"
102 char.ids_aggregated = ag
104 @cd.get_feature("ids-aggregated").dump
107 def store_ids_subparts
108 @cd.get_feature("ids").each {|cid, v|
109 char = Character.get(cid)
110 pids = char.to_s # previous_ids
115 break if ids == pids #これ以上分割できないようだったら終了〜。
118 qp [char.to_s, pids, ids, ar] if 10 < i #これは何かおかしいぞと
121 str = ar.sort.uniq.join("") # can contain IDC.
122 char.ids_subparts = str
124 @cd.get_feature("ids-subparts").dump
127 def store_ids_contained
129 @cd.get_feature("ids-subparts").each {|cid, v|
130 char = Character.get(cid)
131 parts = char.ids_subparts
132 parts.each_char {|ch|
133 h[ch] = [] if h[ch].nil?
138 #char = Character.get(cid)
141 char.ids_contained = v.join
143 @cd.get_feature("ids-contained").dump
152 @config = Config.instance
153 @path = @config.ids_dir.path
159 @dbs[ccs] = IDS_CCS_DB.new(self, ccs) if @dbs[ccs].nil?
164 @path.each_entry {|f|
165 next unless /\AIDS-(.+)\.txt\Z/ =~ f
172 def initialize(idsdb, ccs)
173 @idsdb, @ccs = idsdb, ccs
174 @path = @idsdb.path+("IDS-"+ccs+".txt")
180 next if /\A;/ =~ line # skip comment
182 code, picture, ids = line.split
191 each_line {|code, ids|
193 next if ids == "" # If there is no IDS, ignore it.
197 char = Character.get(er)