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 #テスト用
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")
62 store_cache(num, type, body)
69 def store_cache(num, type, svg)
70 open(cache_file(num, type), "w") {|f|
75 (svg =~ /<!-- error -->/)
79 open("kage-list.txt"){|f|
81 if line =~ /u([0-9a-f]+)\.skeleton/
85 error = true if line =~ /error/
95 @kn = KanjiNetwork.new
96 @kl = KanjiList.instance
100 @kn.make_network(list)
101 nodes, edges = @kn.nodes_and_edges
106 #next if 0xffff < num
112 ar.each {|num| #intの数列
113 char = Character.get(num)
116 #TYPES.each_with_index {|type, index|
117 #(0..2).each {|index|
119 result = get(num, index) #cacheに保存するべしと。
122 print "#{er} #{ch} #{err}\n"
127 char = "&CDP-8BA5;".de_er
129 #str = (char.to_s+"真")
130 str = (char.to_s+"直")
135 if $0 == __FILE__ #======================================================================
136 ks = KageServer.instance
137 #print ks.get(0x4e03)
141 #----------------------------------------------------------------------end.