1 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
3 $LOAD_PATH << "../../lib" if $0 == __FILE__
6 require "chise/kanjilist"
7 require "chise/defkanji"
8 require "chise/graphviz"
11 class KanjiNetwork #=========================漢字間のネットワークを計算する。
14 @formatter = GraphvizFormatter.new(self)
15 # @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 }
75 def to_s() @formatter.to_s; end
78 class GraphvizFormatter #======================================== Graphviz関係
79 def initialize(network)
82 def to_s() #Graphvizのフォーマット、dotフォーマットに変換する。
84 page.size = "5.5, 5.5"
93 @network.list.sort.uniq.each {|ch|
95 node = DotNode.new(char.to_i)
96 node.label = char.map_ucs_er #node.label = char.to_utf8
97 node.fontsize = (node.label =~ /^&#/) ? 12 : 6
98 #node.fontsize = (node.label =~ /^&#/) ? 24 : 6
99 node.shape = "plaintext"
100 node.fontname = "MS-Mincho" #呪われてるがしかたがない
101 #node.fontname = "Arial-Unicode-MS" #ダメ
105 @network.h.each {|ch, ar|
109 edge = DotEdge.new(char.to_i, idschar.to_i)
113 edge.color = "lightgray"
121 class XSpringiesFormatter #=================================================
122 def initialize(network)
126 def to_s # #1.0 *** XSpringies data file
128 @network.list.sort.uniq.each {|ch|
131 label = char.map_ucs_er
132 str << "mass #{num}\n"
134 @network.h.each {|ch, ar|
140 str << "spng #{from} #{to}\n"