我该如何使用Graph::Easy为图形的边分配权重或频率得分?
我有一个双弧和它们的频率列表。 我可以使用Graph::Easy轻松创建只包含双弧的(数学)图表。 输出恰好符合我的要求。 但是当我尝试“set_attribute”时,会出现错误,提示“'frequency'不是有效的属性名称”。我做错了什么? 使用Graph::Easy,我如何使频率成为一个有效的属性?
#!/usr/bin/perl
# graph.pl - given a list of bigrams and their frequencies, output graphml
# require
use Graph::Easy;
use strict;
# initialize
my $graph = Graph::Easy->new;
# process the data
while ( <DATA> ) {
# parse
chop;
my ( $nodes, $frequency ) = split( "\t", $_ );
my ( $source, $target ) = split( ' ', $nodes );
# update the graph
my $edge = $graph->add_edge( $source, $target );
# error happen here
$edge->set_attribute( 'frequency', $frequency );
}
# output & done
print $graph->as_graphml();
exit;
# a set of bigrams and their frequencies
__DATA__
cds classroom 4
maximum registration 4
may want 3
anomalies within 2
resulting analysis 2
participants may 2
corpus without 2
journal articles 2
quickly learn 2
active reading 2
text mining 2
literally count 2
find patterns 2
14 million 2
digital humanities 2
humanities research 2