2 # KageServer - access and fetch Kage glyph data files
3 # $Id: kageserver.rb,v 1.3 2003-11-30 13:16:38 eto Exp $
4 # Copyright (C) 2002-2003 Kouichirou Eto, All rights reserved.
5 # This is free software with ABSOLUTELY NO WARRANTY.
6 # You can redistribute it and/or modify it under the terms of the GNU GPL2.
11 $LOAD_PATH << '../../lib'
13 require 'chise/network' #漢字間接続のネットワークを計算する
14 #require 'chise/kanjilist'
17 class KageServer #======================================================================
19 TYPES = "skeleton mincho gothic".split
23 URL = "http://192.168.2.60:5100/"
24 def initialize(url=URL)
27 @use_cache = true #デフォルト: cacheに存在する場合はcacheから引き出す。
28 @offline = false #テスト用
31 @cache_dir = c.base_dir+"/cache_kage"
32 Dir.mkdir(@cache_dir) unless FileTest.directory?(@cache_dir)
34 attr_accessor :url, :use_cache, :offline
35 def filename(num, type=SKELETON) sprintf("u%04x.%s", num, TYPES[type]) end
36 def cache_file(num, type=SKELETON) @cache_dir+"/"+filename(num, type)+".svg" end
41 Dir.glob("*.svg").each {|file|
42 if file =~ /^u([0-9a-fA-F]+).skeleton.svg$/
50 def get(num, type=SKELETON)
51 return open(cache_file(num, type)).read if FileTest.exist?(cache_file(num, type))
52 svg = get_http(num, type)
56 def get_http(num, type=SKELETON)
57 return nil if @offline
58 uri = URI.parse(URL + filename(num, type))
60 Net::HTTP.version_1_1 # declear to use 1.1 features.
61 Net::HTTP.start( uri.host, uri.port ) {|http|
62 response, body = http.get('/'+filename(num, type)+".svg")
65 # p ['error', uri.to_s]
68 store_cache(num, type, body)
75 def store_cache(num, type, svg)
77 open(cache_file(num, type), "w") {|f|
82 (svg =~ /<!-- error -->/)
86 open("kage-list.txt"){|f|
88 if line =~ /u([0-9a-f]+)\.skeleton/
92 error = true if line =~ /error/
102 @kn = KanjiNetwork.new
103 @kl = KanjiList.instance
107 #list = open("../../jis.txt").read
108 list = @kl.jisx0208()
109 @kn.make_network(list)
110 nodes, edges = @kn.nodes_and_edges
116 next if num == 0x3561
117 next if num == 0x4fdb
118 next if num == 0x58d1
119 next if num == 0x891d
120 next if num == 0x8902
127 ar.each {|num| #intの数列
128 char = Character.get(num)
131 #TYPES.each_with_index {|type, index|
132 #(0..2).each {|index|
134 result = get(num, index) #cacheに保存するべしと。
137 print "#{er} #{ch} #{err}\n"
142 char = "&CDP-8BA5;".de_er
144 #str = (char.to_s+"真")
145 str = (char.to_s+"直")
150 if $0 == __FILE__ #======================================================================
151 ks = KageServer.instance
152 #print ks.get(0x4e03)
156 #----------------------------------------------------------------------end.