1 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
5 require "chise/chisedb"
11 class CharacterFactory # generate Character object and cache them
14 MAX_CACHE_CHARACTER = 10000
18 @parser = CharacterParser.new
27 mcs = @parser.parse(s)
28 @chars[mcs] = Character.new(mcs) if @chars[mcs].nil?
33 clear if MAX_CACHE_CHARACTER < @chars.length # clear all cache
42 def initialize(char_id)
44 raise unless char_id.kind_of?(Integer) # make sure char_id is Integer.
45 raise if char_id < 0 # make sure char_id is positive.
48 # @utf8_mcs = CHISE.i_tou8(@char_id)
49 @utf8_mcs = itou8(@char_id)
52 # @check_all_done = nil
58 CharacterFactory.instance.get(s)
62 sprintf("Char:%x", @char_id)
65 def to_s() @utf8_mcs; end
68 f = normalize_feature_name(f)
81 v = get_feature("="+f)
91 f = normalize_feature_name(k)
93 ft = cd.get_feature(f)
94 ft.set_value(@char_id, v)
98 def method_missing(mid, *args) # ref. ostruct.rb
101 return self[mname] if args.empty? # get
103 if args.length == 1 && /=\Z/ =~ mname # put
104 self[mname.chop] = args.shift
112 en = EntityReferenceEncoder.new
117 cd = ChiseDB.instance
119 ft = cd.get_feature(f)
121 v = ft.get_value(@char_id)
141 cd = ChiseDB.instance
142 cd.load_feature(f, @char_id)
145 def normalize_feature_name(a)
146 a = a.gsub(/_/, "-") #underlineは-に置換
147 a = a.sub(/-at-/, "@")
148 a = a.sub(/-plus-/, "+")
149 a = a.sub(/\Amap-/, "=>")
150 a = a.sub(/\Ato-/, "->")
151 a = a.sub(/\Afrom-/, "<-")