line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Graph::Writer::HTK - perl module for writing a Graph as an HTK lattice |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
package Graph::Writer::HTK; |
5
|
|
|
|
|
|
|
$Graph::Writer::HTK::VERSION = '2.09'; |
6
|
1
|
|
|
1
|
|
456
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
7
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
8
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#======================================================================= |
11
|
|
|
|
|
|
|
#======================================================================= |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
3
|
use parent 'Graph::Writer'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my @graph_attributes = qw(base lmname lmscale wdpenalty); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %node_attributes = |
18
|
|
|
|
|
|
|
( |
19
|
|
|
|
|
|
|
'W' => [ 'WORD', 'label' ], |
20
|
|
|
|
|
|
|
't' => [ 'time' ], |
21
|
|
|
|
|
|
|
'v' => [ 'var' ], |
22
|
|
|
|
|
|
|
'L' => [ 'L' ], |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my %edge_attributes = |
26
|
|
|
|
|
|
|
( |
27
|
|
|
|
|
|
|
'W' => [ 'WORD', 'label' ], |
28
|
|
|
|
|
|
|
'v' => [ 'var' ], |
29
|
|
|
|
|
|
|
'd' => [ 'div' ], |
30
|
|
|
|
|
|
|
'a' => [ 'acoustic' ], |
31
|
|
|
|
|
|
|
'n' => [ 'ngram' ], |
32
|
|
|
|
|
|
|
'l' => [ 'language', 'weight' ], |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#======================================================================= |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# _write_graph |
38
|
|
|
|
|
|
|
# |
39
|
|
|
|
|
|
|
# dump the graph out as an HTK lattice to the given filehandle. |
40
|
|
|
|
|
|
|
# |
41
|
|
|
|
|
|
|
#======================================================================= |
42
|
|
|
|
|
|
|
sub _write_graph |
43
|
|
|
|
|
|
|
{ |
44
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
45
|
1
|
|
|
|
|
1
|
my $graph = shift; |
46
|
1
|
|
|
|
|
2
|
my $FILE = shift; |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
1
|
my $nvertices; |
49
|
|
|
|
|
|
|
my $nedges; |
50
|
0
|
|
|
|
|
0
|
my $v; |
51
|
0
|
|
|
|
|
0
|
my $from; |
52
|
0
|
|
|
|
|
0
|
my $to; |
53
|
0
|
|
|
|
|
0
|
my %v2n; |
54
|
0
|
|
|
|
|
0
|
my $node_num; |
55
|
0
|
|
|
|
|
0
|
my $edge_num; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
1
|
|
|
|
|
3
|
print $FILE "VERSION=1.0\n"; |
59
|
1
|
|
|
|
|
3
|
print $FILE "N=",int($graph->vertices)," L=",int($graph->edges),"\n"; |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
68
|
$node_num = 0; |
62
|
1
|
|
|
|
|
3
|
foreach $v (sort $graph->vertices) |
63
|
|
|
|
|
|
|
{ |
64
|
5
|
|
|
|
|
33
|
$v2n{$v} = $node_num; |
65
|
5
|
|
|
|
|
6
|
print $FILE "I=$node_num"; |
66
|
5
|
|
|
|
|
10
|
foreach my $field (keys %node_attributes) |
67
|
|
|
|
|
|
|
{ |
68
|
20
|
|
|
|
|
614
|
foreach my $attr (@{ $node_attributes{$field} }) |
|
20
|
|
|
|
|
22
|
|
69
|
|
|
|
|
|
|
{ |
70
|
25
|
50
|
|
|
|
224
|
if ($graph->has_vertex_attribute($v, $attr)) |
71
|
|
|
|
|
|
|
{ |
72
|
0
|
|
|
|
|
0
|
print $FILE " $field=", |
73
|
|
|
|
|
|
|
$graph->get_vertex_attribute($v, $attr); |
74
|
0
|
|
|
|
|
0
|
last; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
5
|
|
|
|
|
196
|
print $FILE "\n"; |
79
|
5
|
|
|
|
|
6
|
++$node_num; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
2
|
$edge_num = 0; |
83
|
1
|
|
|
|
|
3
|
foreach my $edge (sort _by_vertex $graph->edges) |
84
|
|
|
|
|
|
|
{ |
85
|
7
|
|
|
|
|
9
|
($from, $to) = @$edge; |
86
|
7
|
|
|
|
|
16
|
print $FILE "J=$edge_num S=", $v2n{$from}, " E=", $v2n{$to}; |
87
|
7
|
|
|
|
|
13
|
foreach my $field (keys %edge_attributes) |
88
|
|
|
|
|
|
|
{ |
89
|
42
|
|
|
|
|
5610
|
foreach my $attr (@{ $edge_attributes{$field} }) |
|
42
|
|
|
|
|
50
|
|
90
|
|
|
|
|
|
|
{ |
91
|
56
|
50
|
|
|
|
2558
|
if ($graph->has_edge_attribute($from, $to, $attr)) |
92
|
|
|
|
|
|
|
{ |
93
|
0
|
|
|
|
|
0
|
print $FILE " $field=", |
94
|
|
|
|
|
|
|
$graph->get_vertex_attribute($from, $to, $attr); |
95
|
0
|
|
|
|
|
0
|
last; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
7
|
|
|
|
|
1079
|
print $FILE "\n"; |
100
|
7
|
|
|
|
|
8
|
++$edge_num; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
1
|
|
|
|
|
7
|
return 1; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _by_vertex |
108
|
|
|
|
|
|
|
{ |
109
|
13
|
|
|
13
|
|
89
|
return $a->[0].$a->[1] cmp $b->[0].$b->[1]; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |