1 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
4 require "chise/libchise"
7 module ParseValueModule
10 return v.to_i if /\A\d+\Z/ =~ v # number?
11 return $1 if /\A"(.+)"\Z/ =~ v # remove surrounding "
12 v # sexp? or the other?
20 @location = CHISE::DataSource::DB_DIR.path
27 attr_reader :ds, :location
31 @ds = DataSource.new(CHISE::DataSource::Berkeley_DB, @location.to_s, 0, 0755)
35 # @ds.close if @ds # do not close for now
39 def each_feature_name()
40 @ds.each_feature_name {|f|
41 next if f.to_s == "." || f.to_s == ".."
42 next if f.to_s =~ /\.txt\Z/
43 yield(f.path.unescape_win_filename.unescape.to_s)
48 each_entry("character/by_feature") {|f| yield(f) }
52 @feature_db[name] = FeatureDB.new(self, name) if @feature_db[name].nil?
56 def load_feature(cid, name)
57 feature = get_feature(name)
58 feature.get_value(cid)
62 @ccs_db[name] = CCS_DB.new(self, name) if @ccs_db[name].nil?
66 def decode_char(ccs, code_point)
68 ccsdb.decode(code_point)
72 @byids_db[n] = ByIDS_DB.new(self, n) if @byids_db[n].nil?
77 include EachEntryModule
80 module TableManagementModule
84 each_char {|k, v| h[k] = v }
89 txt = @name.path.escape.escape_win_filename.to_s+".txt"
90 t = @cd.location+@category+@keyvalue+txt
92 to_hash.sort.each {|k, v|
93 out.printf("%s\t%s\n", k, v)
100 include ParseValueModule
101 include TableManagementModule
103 def initialize(cd, name)
104 @cd, @name = cd, name
106 @feature = @ds.get_feature(@name.path.escape.escape_win_filename.to_s)
107 @category, @keyvalue = "character", "feature"
112 def setup_db(w) @feature.setup_db(w); end
119 def set_value(cid, value)
120 @feature.set_value(cid, value)
124 parse_value(@feature.get_value(cid))
128 @feature.each_char {|cid, value|
130 yield(cid, parse_value(value))
136 include TableManagementModule
138 def initialize(cd, name)
139 @cd, @name = cd, name
141 @ccs = @ds.get_ccs(@name)
143 @category, @keyvalue = "character", "by_feature"
148 def setup_db(w) @ccs.setup_db(w); end
149 def sync() @ccs.sync(); end
151 def set(code_point, cid) @ccs.set(code_point, cid); end
152 def decode(code_point) @ccs.decode(code_point); end
155 db_dir = CHISE::DataSource::DB_DIR
156 @dsr = DataSource_R.new(CHISE::DataSource::Berkeley_DB, db_dir, 0, 0755) if @dsr.nil?
158 @ccsr = CCS_R.new(@dsr, @name) if @ccsr.nil?
161 def each_char # call CCS_R here.
163 @ccsr.each_char {|code_point, cid|
164 yield(code_point, cid)
170 include ParseValueModule
172 include TableAccessModule
173 include TableManagementModule
175 def initialize(cd, name)
176 @cd, @name = cd, name
178 @category, @keyvalue = "character", "by_ids"
187 return nil if @db.nil?
188 parse_c_string(@db.get(ids))
191 def set_decoded_char(ids, cid)
193 raise "@db is nil." if @db.nil?
194 @db.put(ids, format_char_id(cid))
199 raise "@db is nil." if @db.nil?
201 yield(parse_value(k), parse_c_string(v))