1 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
4 require "chise/kanjilist"
5 require "chise/defkanji"
6 require "chise/graphviz"
9 class KanjiNetwork # 漢字間のネットワークを計算する
12 @formatter = GraphvizFormatter.new(self)
13 # @formatter = XSpringiesFormatter.new(self)
23 def make_network(list) #@h, @listに結果を入れていく。
29 def make_network_one(ch) #実質的にこれが本体。再帰で呼ばれる。
33 @list << ch #登場文字リストに追加
37 if ids.char_length == 1 #分割できない文字は、リンクを探す。
38 link = char.ids_represent if char.ids_represent
39 link = char.ids_link if char.ids_link
41 @h[ch] << link #親字に追加する。
46 ids.each_char {|idsch|
48 next if idschar.is_ids?
49 @h[ch] << idsch #親字に追加する。
51 make_network_one(idsch) #再帰する。
56 def nodes_and_edges() #これを二つのarrayで返す
59 @list.sort.uniq.each_with_index {|ch, index|
66 edgear << [nodeh[ch], nodeh[idsch]]
73 open(filename, "w"){|out| out.print to_s }
76 def to_s() @formatter.to_s; end
79 class GraphvizFormatter # Graphviz関係
80 def initialize(network)
84 def to_s() #Graphvizのフォーマット、dotフォーマットに変換する。
86 page.size = "5.5, 5.5"
95 @network.list.sort.uniq.each {|ch|
97 node = DotNode.new(char.to_i)
98 node.label = char.map_ucs_er #node.label = char.to_utf8
99 node.fontsize = (node.label =~ /^&#/) ? 12 : 6
100 #node.fontsize = (node.label =~ /^&#/) ? 24 : 6
101 node.shape = "plaintext"
102 node.fontname = "MS-Mincho" #呪われてるがしかたがない
103 #node.fontname = "Arial-Unicode-MS" #ダメ
107 @network.h.each {|ch, ar|
111 edge = DotEdge.new(char.to_i, idschar.to_i)
115 edge.color = "lightgray"
123 class XSpringiesFormatter
124 def initialize(network)
128 def to_s # #1.0 *** XSpringies data file
130 @network.list.sort.uniq.each {|ch|
133 label = char.map_ucs_er
134 str << "mass #{num}\n"
136 @network.h.each {|ch, ar|
142 str << "spng #{from} #{to}\n"