return nil if v.nil?
return v.to_i if /\A\d+\Z/ =~ v # number?
return $1 if /\A"(.+)"\Z/ =~ v # remove surrounding "
- v # sexp?
+ v # sexp? or the other?
end
end
def initialize
@location = CHISE::DataSource::DB_DIR.path
- @ds = DataSource.new(CHISE::DataSource::Berkeley_DB, @location.to_s, 0, 0755)
+ @ds = nil
+ setup_ds
@feature_db = {}
@ccs_db = {}
- @byids_db = {}
+ # @byids_db = {}
+ @ccsstr_db = {}
end
attr_reader :ds, :location
+ def setup_ds
+ return if @ds
+ @ds = DataSource.new(CHISE::DataSource::Berkeley_DB, @location.to_s, 0, 0755)
+ end
+
def close
# @ds.close if @ds # do not close for now
+ # @ds = nil
end
def each_feature_name()
ccsdb.decode(code_point)
end
- def get_by_ids_db(n)
+ def nuget_by_ids_db(n)
@byids_db[n] = ByIDS_DB.new(self, n) if @byids_db[n].nil?
@byids_db[n]
end
+ def get_ccs_str(n)
+ @ccsstr_db[n] = CCS_STR.new(self, n) if @ccsstr_db[n].nil?
+# @ccsstr_db[n] = CCS_STR_DB.new(self, n) if @ccsstr_db[n].nil?
+ @ccsstr_db[n]
+ end
+
private
include EachEntryModule
end
module TableManagementModule
def to_hash
+ sync # add.
h = {}
each_char {|k, v| h[k] = v }
h
}
end
def setup_db(w) @feature.setup_db(w); end
- def sync() @feature.sync(); end
+ def sync
+ #qp "sync"
+ @feature.sync
+ end
alias close sync
def set_value(cid, value)
- @feature.set_value(cid, value)
+ @feature.set_value(cid, value.to_s)
end
def get_value(cid)
end
end
- class ByIDS_DB
+ class CCS_STR_DB
include ParseValueModule
include ChiseValue
include TableAccessModule
}
end
- def decode(ids)
+ def get_by_str(str)
setup_db
return nil if @db.nil?
- parse_c_string(@db.get(ids))
+ parse_c_string(@db.get(str))
end
- def set_decoded_char(ids, cid)
+ def set_by_str(str, cid)
setup_db(true)
raise "@db is nil." if @db.nil?
- @db.put(ids, format_char_id(cid))
+ @db.put(str, format_char_id(cid))
end
def each_char
}
end
end
+
end