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 #URL = "http://218.219.209.16:5100/"
21 def initialize(url=URL)
24 @use_cache = true #デフォルト: cacheに存在する場合はcacheから引き出す。
25 @offline = false #テスト用
27 Dir.mkdir(CACHE_DIR) unless FileTest.directory?(CACHE_DIR)
29 attr_accessor :url, :use_cache
30 def filename(num, type=SKELETON) sprintf("u%04x.%s", num, TYPES[type]) end
31 def cache_file(num, type=SKELETON) CACHE_DIR+"/"+filename(num, type)+".svg" end
36 Dir.glob("*.svg").each {|file|
37 if file =~ /^u([0-9a-fA-F]+).skeleton.svg$/
45 def get(num, type=SKELETON)
46 return open(cache_file(num, type)).read if FileTest.exist?(cache_file(num, type))
47 svg = get_http(num, type)
51 def get_http(num, type=SKELETON)
52 return nil if @offline
53 uri = URI.parse(URL + filename(num, type))
55 Net::HTTP.version_1_1 # declear to use 1.1 features.
56 Net::HTTP.start( uri.host, uri.port ) {|http|
57 response, body = http.get('/'+filename(num, type)+".svg")
63 store_cache(num, type, body)
70 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 @kn.make_network(list)
102 nodes, edges = @kn.nodes_and_edges
107 #next if 0xffff < num
113 ar.each {|num| #intの数列
114 char = Character.get(num)
117 #TYPES.each_with_index {|type, index|
118 #(0..2).each {|index|
120 result = get(num, index) #cacheに保存するべしと。
123 print "#{er} #{ch} #{err}\n"
128 char = "&CDP-8BA5;".de_er
130 #str = (char.to_s+"真")
131 str = (char.to_s+"直")
136 if $0 == __FILE__ #======================================================================
137 ks = KageServer.instance
138 #print ks.get(0x4e03)
142 #----------------------------------------------------------------------end.