3 # calc KanjiNetwork by eto 2003-0305
4 # Copyright (C) 2002-2003 Kouichirou Eto
6 # This is free software with ABSOLUTELY NO WARRANTY.
8 # You can redistribute it and/or modify it under the terms of
9 # the GNU General Public License version 2.
18 class KanjiNetwork #======================================================================漢字間のネットワークを計算する。
21 @formatter = GraphvizFormatter.new(self)
22 # @formatter = XSpringiesFormatter.new(self)
30 def make_network(list) #@h, @listに結果を入れていく。
36 def make_network_one(ch) #実質的にこれが本体。再帰で呼ばれる。
40 @list << ch #登場文字リストに追加
44 if ids.char_length == 1 #分割できない文字は、リンクを探す。
45 link = char.ids_represent if char.ids_represent
46 link = char.ids_link if char.ids_link
48 @h[ch] << link #親字に追加する。
53 ids.each_char {|idsch|
55 next if idschar.is_ids?
56 @h[ch] << idsch #親字に追加する。
58 make_network_one(idsch) #再帰する。
63 def nodes_and_edges() #これを二つのarrayで返す
66 @list.sort.uniq.each_with_index {|ch, index|
73 edgear << [nodeh[ch], nodeh[idsch]]
80 open(filename, "w"){|out| out.print to_s }
82 def to_s() @formatter.to_s; end
85 class GraphvizFormatter #====================================================================== Graphviz関係
86 def initialize(network)
89 def to_s() #Graphvizのフォーマット、dotフォーマットに変換する。
91 page.size = "5.5, 5.5"
100 @network.list.sort.uniq.each {|ch|
102 node = DotNode.new(char.to_i)
103 node.label = char.map_ucs_er #node.label = char.to_utf8
104 node.fontsize = (node.label =~ /^&#/) ? 12 : 6
105 #node.fontsize = (node.label =~ /^&#/) ? 24 : 6
106 node.shape = "plaintext"
107 node.fontname = "MS-Mincho" #呪われてるがしかたがない
108 #node.fontname = "Arial-Unicode-MS" #ダメ
112 @network.h.each {|ch, ar|
116 edge = DotEdge.new(char.to_i, idschar.to_i)
120 edge.color = "lightgray"
128 class XSpringiesFormatter #======================================================================
129 def initialize(network)
132 def to_s # #1.0 *** XSpringies data file
134 @network.list.sort.uniq.each {|ch|
137 label = char.map_ucs_er
138 str << "mass #{num}\n"
140 @network.h.each {|ch, ar|
146 str << "spng #{from} #{to}\n"
154 #----------------------------------------------------------------------end.