2 # calc KanjiNetwork by eto 2003-0305
10 class KanjiNetwork #======================================================================漢字間のネットワークを計算する。
13 @formatter = GraphvizFormatter.new(self)
14 # @formatter = XSpringiesFormatter.new(self)
22 def make_network(list) #@h, @listに結果を入れていく。
28 def make_network_one(ch) #実質的にこれが本体。再帰で呼ばれる。
32 @list << ch #登場文字リストに追加
36 if ids.char_length == 1 #分割できない文字は、リンクを探す。
37 link = char.ids_represent if char.ids_represent
38 link = char.ids_link if char.ids_link
40 @h[ch] << link #親字に追加する。
45 ids.each_char {|idsch|
47 next if idschar.is_ids?
48 @h[ch] << idsch #親字に追加する。
50 make_network_one(idsch) #再帰する。
55 def nodes_and_edges() #これを二つのarrayで返す
58 @list.sort.uniq.each_with_index {|ch, index|
65 edgear << [nodeh[ch], nodeh[idsch]]
72 open(filename, "w"){|out| out.print to_s }
74 def to_s() @formatter.to_s; end
77 class GraphvizFormatter #====================================================================== Graphviz関係
78 def initialize(network)
81 def to_s() #Graphvizのフォーマット、dotフォーマットに変換する。
83 page.size = "5.5, 5.5"
92 @network.list.sort.uniq.each {|ch|
94 node = DotNode.new(char.to_i)
95 node.label = char.map_ucs_er #node.label = char.to_utf8
96 node.fontsize = (node.label =~ /^&#/) ? 12 : 6
97 #node.fontsize = (node.label =~ /^&#/) ? 24 : 6
98 node.shape = "plaintext"
99 node.fontname = "MS-Mincho" #呪われてるがしかたがない
100 #node.fontname = "Arial-Unicode-MS" #ダメ
104 @network.h.each {|ch, ar|
108 edge = DotEdge.new(char.to_i, idschar.to_i)
112 edge.color = "lightgray"
120 class XSpringiesFormatter #======================================================================
121 def initialize(network)
124 def to_s # #1.0 *** XSpringies data file
126 @network.list.sort.uniq.each {|ch|
129 label = char.map_ucs_er
130 str << "mass #{num}\n"
132 @network.h.each {|ch, ar|
138 str << "spng #{from} #{to}\n"
146 #----------------------------------------------------------------------end.