1 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
6 $LOAD_PATH << "../../lib"
8 require "chise/network" #漢字間接続のネットワークを計算する
9 #require "chise/kanjilist"
14 TYPES = "skeleton mincho gothic".split
18 URL = "http://192.168.2.60:5100/"
19 def initialize(url=URL)
22 @use_cache = true #デフォルト: cacheに存在する場合はcacheから引き出す。
23 @offline = false #テスト用
26 @cache_dir = c.base_dir+"/cache_kage"
27 Dir.mkdir(@cache_dir) unless FileTest.directory?(@cache_dir)
29 attr_accessor :url, :use_cache, :offline
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")
60 # p ["error", uri.to_s]
63 store_cache(num, type, body)
70 def store_cache(num, type, svg)
72 open(cache_file(num, type), "w") {|f|
77 (svg =~ /<!-- error -->/)
81 open("kage-list.txt"){|f|
83 if line =~ /u([0-9a-f]+)\.skeleton/
87 error = true if line =~ /error/
97 @kn = KanjiNetwork.new
98 @kl = KanjiList.instance
102 #list = open("../../jis.txt").read
103 list = @kl.jisx0208()
104 @kn.make_network(list)
105 nodes, edges = @kn.nodes_and_edges
111 next if num == 0x3561
112 next if num == 0x4fdb
113 next if num == 0x58d1
114 next if num == 0x891d
115 next if num == 0x8902
122 ar.each {|num| #intの数列
123 char = Character.get(num)
126 #TYPES.each_with_index {|type, index|
127 #(0..2).each {|index|
129 result = get(num, index) #cacheに保存するべしと。
132 print "#{er} #{ch} #{err}\n"
137 char = "&CDP-8BA5;".de_er
139 #str = (char.to_s+"真")
140 str = (char.to_s+"直")
146 ks = KageServer.instance
147 #print ks.get(0x4e03)