| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Graph::GML; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
37850
|
use 5.012003; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
53
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
41
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
19
|
|
|
|
1
|
|
|
|
|
42
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1633
|
use Graph; |
|
|
1
|
|
|
|
|
176850
|
|
|
|
1
|
|
|
|
|
1454
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
|
14
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
|
15
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# This allows declaration use Graph::GML ':all'; |
|
18
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
|
19
|
|
|
|
|
|
|
# will save memory. |
|
20
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
) ] ); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Preloaded methods go here. |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub new { |
|
36
|
1
|
|
|
1
|
0
|
13
|
my $class = shift; |
|
37
|
1
|
|
|
|
|
3
|
my %args = @_; |
|
38
|
1
|
|
|
|
|
2
|
my $self = {}; |
|
39
|
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
2
|
bless $self, $class; |
|
41
|
|
|
|
|
|
|
|
|
42
|
1
|
50
|
|
|
|
4
|
if (defined $args{'file'}) { |
|
43
|
0
|
|
|
|
|
0
|
return _handle_file($args{'file'}); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
10
|
return undef; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _handle_file { |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
0
|
|
|
my $file = shift; |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $string = _read_file($file); |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if ($string =~ /^Creator/) { |
|
56
|
0
|
|
|
|
|
|
my $creator; |
|
57
|
0
|
|
|
|
|
|
($creator,$string) = _get_string($string,"Creator"); |
|
58
|
0
|
|
|
|
|
|
print $creator,"\n"; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $wd; |
|
62
|
0
|
|
|
|
|
|
($wd,$string) = _get_next($string); |
|
63
|
0
|
|
|
|
|
|
$wd =~ s/\s+//g; |
|
64
|
0
|
|
|
|
|
|
my $graph; |
|
65
|
|
|
|
|
|
|
my $nodes; |
|
66
|
0
|
|
|
|
|
|
my $populated; |
|
67
|
0
|
|
|
|
|
|
while (length($wd)) { |
|
68
|
|
|
|
|
|
|
# print $wd,"\n"; |
|
69
|
0
|
0
|
|
|
|
|
if ($string =~ /directed/) { |
|
70
|
|
|
|
|
|
|
#according to the spec, directed isn't really a tag |
|
71
|
|
|
|
|
|
|
#but's used, so we deal |
|
72
|
0
|
|
|
|
|
|
my $val; |
|
73
|
0
|
|
|
|
|
|
($val,$string) = _get_word($string); |
|
74
|
0
|
|
|
|
|
|
($val,$string) = _get_word($string); |
|
75
|
|
|
|
|
|
|
# print "Directed: ",$val,"\n"; |
|
76
|
0
|
0
|
|
|
|
|
if ($val) { |
|
77
|
0
|
|
|
|
|
|
print "Made directed graph\n"; |
|
78
|
0
|
|
|
|
|
|
$graph = Graph->new(directed=>1); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
0
|
|
|
|
|
|
($wd,$string) = _get_next($string); |
|
81
|
0
|
|
|
|
|
|
next; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
0
|
0
|
|
|
|
|
if ($wd eq "graph") { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
($wd,$string) = _get_next($string); |
|
85
|
0
|
|
|
|
|
|
next; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
elsif ($wd eq "node") { |
|
88
|
0
|
0
|
|
|
|
|
if (!defined $graph) { |
|
89
|
|
|
|
|
|
|
#if not already created, assume undirected |
|
90
|
0
|
|
|
|
|
|
$graph = Graph::Undirected->new; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
0
|
|
|
|
|
|
($nodes,$string) = _handle_node($nodes,$string); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
elsif ($wd eq "edge") { |
|
95
|
0
|
0
|
|
|
|
|
if (!$populated) { |
|
96
|
0
|
|
|
|
|
|
$graph = _populate_graph($graph,$nodes); |
|
97
|
0
|
|
|
|
|
|
$populated = 1; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
0
|
|
|
|
|
|
($graph,$string) = _handle_edge($graph,$nodes,$string); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
0
|
|
|
|
|
|
($wd,$string) = _get_next($string); |
|
102
|
0
|
|
|
|
|
|
$wd =~ s/\s+//g; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
return $graph; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub _populate_graph { |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
|
|
0
|
|
|
my $graph = shift; |
|
111
|
0
|
|
|
|
|
|
my $nodes = shift; |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my $vert; |
|
114
|
0
|
|
|
|
|
|
foreach my $el (keys %{$nodes}) { |
|
|
0
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
0
|
0
|
|
|
|
if (ref($nodes->{$el}) eq "HASH" && defined $nodes->{$el}->{label}) { |
|
117
|
0
|
|
|
|
|
|
$vert = $nodes->{$el}->{label}; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
else { |
|
120
|
0
|
|
|
|
|
|
$vert = $el; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
0
|
|
|
|
|
|
$graph->add_vertex($vert); |
|
123
|
0
|
0
|
0
|
|
|
|
if (ref($nodes->{$el}) eq "HASH" && defined $nodes->{$el}->{value}) { |
|
124
|
0
|
|
|
|
|
|
$graph->set_vertex_weight($vert,$nodes->{$el}->{value}); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return $graph; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub _handle_node { |
|
132
|
0
|
|
|
0
|
|
|
my $nodehash = shift; |
|
133
|
0
|
|
|
|
|
|
my $string = shift; |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my $node; |
|
136
|
0
|
|
|
|
|
|
($node,$string) = _get_next($string); |
|
137
|
0
|
|
|
|
|
|
$node =~ s/^\s+//; |
|
138
|
0
|
|
|
|
|
|
my $tmphash; |
|
139
|
0
|
|
|
|
|
|
my ($key,$id,$val); |
|
140
|
0
|
|
|
|
|
|
while (length($node)) { |
|
141
|
0
|
|
|
|
|
|
($key,$node) = _get_word($node); |
|
142
|
0
|
0
|
|
|
|
|
if ($key eq "id") { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
($id,$node) = _get_word($node); |
|
144
|
|
|
|
|
|
|
# $tmphash->{id} = $id; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
elsif ($key eq "name") { |
|
147
|
0
|
|
|
|
|
|
($tmphash->{name},$node) = _get_word($node); |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
elsif ($key eq "label") { |
|
150
|
0
|
|
|
|
|
|
($tmphash->{label},$node) = _get_string($node); |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
elsif ($key eq "comment") { |
|
153
|
0
|
|
|
|
|
|
($tmphash->{comment},$node) = _get_string($node); |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
elsif ($key eq "value") { |
|
156
|
0
|
|
|
|
|
|
($tmphash->{value},$node) = _get_string($node); |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# print $id,"\n"; |
|
161
|
0
|
0
|
|
|
|
|
if (!defined $id) { return ($nodehash,$string); } |
|
|
0
|
|
|
|
|
|
|
|
162
|
0
|
0
|
|
|
|
|
if (!defined $tmphash) { |
|
163
|
0
|
|
|
|
|
|
$nodehash->{$id} = 1; |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
else { |
|
167
|
0
|
|
|
|
|
|
$nodehash->{$id} = $tmphash; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
0
|
|
|
|
|
|
return ($nodehash,$string); |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub _handle_edge { |
|
173
|
0
|
|
|
0
|
|
|
my $graph = shift; |
|
174
|
0
|
|
|
|
|
|
my $nodes = shift; |
|
175
|
0
|
|
|
|
|
|
my $string = shift; |
|
176
|
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
my $edge; |
|
178
|
0
|
|
|
|
|
|
($edge,$string) = _get_next($string); |
|
179
|
0
|
|
|
|
|
|
$edge =~ s/^\s+//; |
|
180
|
0
|
|
|
|
|
|
my ($key,$source,$target,$label,$comment,$value); |
|
181
|
0
|
|
|
|
|
|
while (length($edge)) { |
|
182
|
0
|
|
|
|
|
|
($key,$edge) = _get_word($edge); |
|
183
|
0
|
0
|
|
|
|
|
if ($key eq "source") { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
($source,$edge) = _get_word($edge); |
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
elsif ($key eq "target") { |
|
187
|
0
|
|
|
|
|
|
($target,$edge) = _get_word($edge); |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
elsif ($key eq "label") { |
|
190
|
0
|
|
|
|
|
|
($label,$edge) = _get_string($edge); |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
elsif ($key eq "comment") { |
|
193
|
0
|
|
|
|
|
|
($comment,$edge) = _get_string($edge); |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
elsif ($key eq "value") { |
|
196
|
0
|
|
|
|
|
|
($value,$edge) = _get_string($edge); |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
} |
|
199
|
|
|
|
|
|
|
|
|
200
|
0
|
0
|
0
|
|
|
|
if (ref($nodes->{$source}) eq "HASH" && defined $nodes->{$source}->{label}) { |
|
201
|
0
|
|
|
|
|
|
$source = $nodes->{$source}->{label}; |
|
202
|
|
|
|
|
|
|
} |
|
203
|
0
|
0
|
0
|
|
|
|
if (ref($nodes->{$target}) eq "HASH" && defined $nodes->{$target}->{label}) { |
|
204
|
0
|
|
|
|
|
|
$target = $nodes->{$target}->{label}; |
|
205
|
|
|
|
|
|
|
} |
|
206
|
0
|
0
|
|
|
|
|
if (defined $value) { |
|
207
|
0
|
|
|
|
|
|
$graph->add_weighted_edge($source,$target,$value); |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
else { |
|
210
|
0
|
|
|
|
|
|
$graph->add_edge($source,$target); |
|
211
|
|
|
|
|
|
|
} |
|
212
|
|
|
|
|
|
|
# print "Edge -- Source: ",$source," Target: ",$target," Label",$label,"\n"; |
|
213
|
0
|
|
|
|
|
|
return ($graph,$string); |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub _get_next { |
|
217
|
0
|
|
|
0
|
|
|
my $string = shift; |
|
218
|
0
|
|
|
|
|
|
my $split= '['; |
|
219
|
0
|
|
|
|
|
|
my $split2 = ']'; |
|
220
|
0
|
|
|
|
|
|
my $wd; |
|
221
|
0
|
|
|
|
|
|
($wd,$string) = split(/[\Q$split$split2\E]/,$string,2); |
|
222
|
0
|
|
|
|
|
|
return ($wd,$string); |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub _read_file { |
|
226
|
0
|
|
|
0
|
|
|
my $file = shift; |
|
227
|
|
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
|
my $data; |
|
229
|
0
|
0
|
|
|
|
|
open(IF,$file) || die $file," ",$!; |
|
230
|
0
|
|
|
|
|
|
while () { |
|
231
|
0
|
|
|
|
|
|
chop; |
|
232
|
0
|
|
|
|
|
|
$data .= $_; |
|
233
|
|
|
|
|
|
|
} |
|
234
|
0
|
|
|
|
|
|
close(IF); |
|
235
|
0
|
|
|
|
|
|
$data =~ s/^\s+//; # remove any strings at the beginning |
|
236
|
0
|
|
|
|
|
|
return $data; |
|
237
|
|
|
|
|
|
|
} |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub _get_string { |
|
240
|
0
|
|
|
0
|
|
|
my $string = shift; |
|
241
|
0
|
|
|
|
|
|
my $id = shift; |
|
242
|
|
|
|
|
|
|
|
|
243
|
0
|
0
|
|
|
|
|
if (defined $id) { |
|
244
|
0
|
|
|
|
|
|
$string =~ s/$id\s+//; #remove that pesky id string |
|
245
|
|
|
|
|
|
|
} |
|
246
|
0
|
|
|
|
|
|
my $split= '"'; |
|
247
|
0
|
|
|
|
|
|
my ($bar,$creator,$str) = split(/\"/,$string,3); |
|
248
|
0
|
|
|
|
|
|
return ($creator,$str); |
|
249
|
|
|
|
|
|
|
} |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
sub _get_word { |
|
252
|
0
|
|
|
0
|
|
|
my $string = shift; |
|
253
|
|
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
|
$string =~ s/^\s+//; |
|
255
|
0
|
|
|
|
|
|
my ($wd,$str) = split(/\s+/,$string,2); |
|
256
|
|
|
|
|
|
|
|
|
257
|
0
|
|
|
|
|
|
return ($wd,$str); |
|
258
|
|
|
|
|
|
|
} |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
1; |
|
261
|
|
|
|
|
|
|
__END__ |