raise if char_id < 0 # make sure char_id is positive.
@char_id = char_id
@char_id.freeze
- # @utf8_mcs = CHISE.i_tou8(@char_id)
@utf8_mcs = itou8(@char_id)
@utf8_mcs.freeze
@feature = {}
- # @check_all_done = nil
end
attr_reader :char_id
attr_reader :utf8_mcs
def each_feature
cd = ChiseDB.instance
- #return
cd.each_feature_name {|f|
- #p f
feature = cd.get_feature(f)
begin
v = feature.get_value(@char_id)
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
end
def each_feature_name()
-# setup_ds
@ds.each_feature_name {|f|
next if f.to_s == "." || f.to_s == ".."
next if f.to_s =~ /\.txt\Z/
end
def each_ccs
-# setup_ds
each_entry("character/by_feature") {|f| yield(f) }
end
def get_feature(name)
-# setup_ds
@feature_db[name] = FeatureDB.new(self, name) if @feature_db[name].nil?
@feature_db[name]
end
def load_feature(cid, name)
-# setup_ds
feature = get_feature(name)
feature.get_value(cid)
end
def get_ccs(name)
-# setup_ds
@ccs_db[name] = CCS_DB.new(self, name) if @ccs_db[name].nil?
@ccs_db[name]
end
def decode_char(ccs, code_point)
-# setup_ds
ccsdb = get_ccs(ccs)
ccsdb.decode(code_point)
end
def get_by_ids_db(n)
-# setup_ds
@byids_db[n] = ByIDS_DB.new(self, n) if @byids_db[n].nil?
@byids_db[n]
end
IDC_SURROUND_FROM_LOWER_LEFT = IDC_A
IDC_OVERLAID = IDC_B
- class Nu_IDS
- def initialize(ids)
- @ids = ids
- @ids.freeze
- end
-
- def tree() IDS_Tree.new(@ids); end
-
- def compose(dbname="ids")
- ids = @ids.to_ids.aggregate
-
- cd = ChiseDB.instance
- byidsdb = cd.get_by_ids_db(dbname)
- cid = byidsdb.decode(ids)
- return "" if cid.nil? # TO CHECK: why "", not nil?
- composed = Character.get(cid).to_s
- return "" if composed.nil?
- return "" if composed.char_length == 0
- return composed if composed.char_length == 1
- composed.each_char {|ch|
- char = ch.char
- #return ch if char.has_attribute?
- return ch # TO CHECK: the first character?
- }
- return ""
- end
-
- def aggregate(dbname="ids")
- # In each sub part of IDS, search the corresponding char_id.
- # If you could search the corresponding char_id, substitute with it.
- tree = self.tree
- return @ids if tree.depth <= 1 # no sub_node
- tree.sub_nodes.each {|node|
- c = node.to_ids.compose(dbname)
- next if c.nil? || c == ""
- # print "#{@ids} #{node} #{c}\n"
- # p [@ids, node, c]
- n = @ids.gsub(node, c)
- return n.to_ids.aggregate(dbname)
- }
- @ids
- end
- end
-
module StringIDS
def decompose
map_char {|ch| ch.char.decompose }
def aggregate(dbname="ids")
# In each sub part of IDS, search the corresponding char_id.
# If you could search the corresponding char_id, substitute with it.
- tree = self.ids_tree
+ #tree = self.ids_tree
+ tree = IDS_Tree.new(self)
return self if tree.depth <= 1 # no sub_node
tree.sub_nodes.each {|node|
c = node.compose(dbname)
require "chise/libchise_r"
begin
require "libchise_c.so"
- #raise LoadError # uncomment, if you'd like to use libchise_r.
+ raise LoadError # uncomment, if you'd like to use libchise_r.
module CHISE
DataSource = DataSource_C
Feature = Feature_C
begin
@db.sync
@db.close
+ @db = nil
rescue => e
p e
end
char_id = 0x4ECF
feature = @ds.get_feature("ideographic-structure")
assert_instance_of(CHISE::Feature, feature)
- #assert_equal(true, feature.setup_db(0))
- #assert_equal(true, feature.sync)
+ assert_equal(true, feature.setup_db(0))
+ assert_equal(true, feature.sync)
value = feature.get_value(char_id)
assert_equal("(?\342\277\260 ?\344\272\273 ?\345\216\266)", value)
# get a character by Daikanwa number 364.
ccs = @ds.get_ccs("=daikanwa")
assert_instance_of(CHISE::CCS, ccs)
- #assert_equal(true, ccs.setup_db(0))
- #assert_equal(true, ccs.sync)
+ assert_equal(true, ccs.setup_db(0))
+ assert_equal(true, ccs.sync)
char_id = ccs.decode(364)
assert_equal(0x4ECF, char_id)