3 $LOAD_PATH << '../ruby/src'
9 require 'network' #漢字間接続のネットワークを計算する
11 class KageServer #======================================================================
13 TYPES = "skeleton mincho gothic".split
17 HOME_DIR = "d:/work/chise/"
18 CACHE_DIR = HOME_DIR + "cache_kage"
19 URL = "http://192.168.2.60:5100/"
20 def initialize(url=URL)
23 @use_cache = true #デフォルト: cacheに存在する場合はcacheから引き出す。
24 @offline = false #テスト用
25 #@offline = true #テスト用
26 Dir.mkdir(CACHE_DIR) unless FileTest.directory?(CACHE_DIR)
28 attr_accessor :url, :use_cache
29 def filename(num, type=SKELETON) sprintf("u%04x.%s", num, TYPES[type]) end
30 def cache_file(num, type=SKELETON) CACHE_DIR+"/"+filename(num, type)+".svg" end
35 Dir.glob("*.svg").each {|file|
36 if file =~ /^u([0-9a-fA-F]+).skeleton.svg$/
44 def get(num, type=SKELETON)
45 return open(cache_file(num, type)).read if FileTest.exist?(cache_file(num, type))
46 svg = get_http(num, type)
50 def get_http(num, type=SKELETON)
51 return nil if @offline
52 uri = URI.parse(URL + filename(num, type))
54 Net::HTTP.version_1_1 # declear to use 1.1 features.
55 Net::HTTP.start( uri.host, uri.port ) {|http|
56 response, body = http.get('/'+filename(num, type)+".svg")
59 # p ['error', uri.to_s]
62 store_cache(num, type, body)
69 def store_cache(num, type, svg)
71 open(cache_file(num, type), "w") {|f|
76 (svg =~ /<!-- error -->/)
80 open("kage-list.txt"){|f|
82 if line =~ /u([0-9a-f]+)\.skeleton/
86 error = true if line =~ /error/
96 @kn = KanjiNetwork.new
97 @kl = KanjiList.instance
101 list = open("../../jis.txt").read
102 @kn.make_network(list)
103 nodes, edges = @kn.nodes_and_edges
109 next if num == 0x3561
110 next if num == 0x4fdb
111 next if num == 0x58d1
112 next if num == 0x891d
113 next if num == 0x8902
120 ar.each {|num| #intの数列
121 char = Character.get(num)
124 #TYPES.each_with_index {|type, index|
125 #(0..2).each {|index|
127 result = get(num, index) #cacheに保存するべしと。
130 print "#{er} #{ch} #{err}\n"
135 char = "&CDP-8BA5;".de_er
137 #str = (char.to_s+"真")
138 str = (char.to_s+"直")
143 if $0 == __FILE__ #======================================================================
144 ks = KageServer.instance
145 #print ks.get(0x4e03)
149 #----------------------------------------------------------------------end.