1 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
5 require "chise/chisedb"
9 class CharacterFactory # generate Character object and cache them
12 MAX_CACHE_CHARACTER = 10000
16 @parser = CharacterParser.new
25 mcs = @parser.parse(s)
26 @chars[mcs] = Character.new(mcs) if @chars[mcs].nil?
31 clear if MAX_CACHE_CHARACTER < @chars.length # clear all cache
36 def initialize(char_id)
38 raise unless char_id.is_a?(Fixnum) # char_id sure is a Fixnum.
39 raise if char_id < 0 # char_id sure is a positive value.
42 @utf8_mcs = CHISE.i_tou8(@char_id)
51 CharacterFactory.instance.get(s)
55 sprintf("Char:%x", @char_id)
58 def to_s() @utf8_mcs; end
61 f = normalize_feature_name(f)
74 v = get_feature("="+f)
84 f = normalize_feature_name(k)
86 ft = cd.get_feature(f)
87 ft.set_value(@char_id, v)
91 def method_missing(mid, *args) # ref. ostruct.rb
94 return self[mname] if args.empty? # get
96 if args.length == 1 && /=\Z/ =~ mname # put
97 self[mname.chop] = args.shift
105 en = EntityReferenceEncoder.new
112 cd = ChiseDB.instance
113 cd.load_feature(f, @char_id)
116 def normalize_feature_name(a)
117 a = a.gsub(/_/, "-") #underlineは-に置換
118 a = a.sub(/-at-/, "@")
119 a = a.sub(/-plus-/, "+")
120 a = a.sub(/\Amap-/, "=>")
121 a = a.sub(/\Ato-/, "->")
122 a = a.sub(/\Afrom-/, "<-")