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
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
392
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
7
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#======================================================================= |
10
|
|
|
|
|
|
|
#======================================================================= |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
3
|
use parent 'Graph::Writer'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
13
|
|
|
|
|
|
|
our $VERSION = '2.07'; |
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
|
|
2
|
my $self = shift; |
45
|
1
|
|
|
|
|
2
|
my $graph = shift; |
46
|
1
|
|
|
|
|
1
|
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
|
|
|
|
|
4
|
print $FILE "VERSION=1.0\n"; |
59
|
1
|
|
|
|
|
3
|
print $FILE "N=",int($graph->vertices)," L=",int($graph->edges),"\n"; |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
76
|
$node_num = 0; |
62
|
1
|
|
|
|
|
4
|
foreach $v (sort $graph->vertices) |
63
|
|
|
|
|
|
|
{ |
64
|
5
|
|
|
|
|
39
|
$v2n{$v} = $node_num; |
65
|
5
|
|
|
|
|
7
|
print $FILE "I=$node_num"; |
66
|
5
|
|
|
|
|
10
|
foreach my $field (keys %node_attributes) |
67
|
|
|
|
|
|
|
{ |
68
|
20
|
|
|
|
|
771
|
foreach my $attr (@{ $node_attributes{$field} }) |
|
20
|
|
|
|
|
27
|
|
69
|
|
|
|
|
|
|
{ |
70
|
25
|
50
|
|
|
|
287
|
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
|
|
|
|
|
286
|
print $FILE "\n"; |
79
|
5
|
|
|
|
|
6
|
++$node_num; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
3
|
$edge_num = 0; |
83
|
1
|
|
|
|
|
4
|
foreach my $edge (sort _by_vertex $graph->edges) |
84
|
|
|
|
|
|
|
{ |
85
|
7
|
|
|
|
|
11
|
($from, $to) = @$edge; |
86
|
7
|
|
|
|
|
20
|
print $FILE "J=$edge_num S=", $v2n{$from}, " E=", $v2n{$to}; |
87
|
7
|
|
|
|
|
16
|
foreach my $field (keys %edge_attributes) |
88
|
|
|
|
|
|
|
{ |
89
|
42
|
|
|
|
|
6760
|
foreach my $attr (@{ $edge_attributes{$field} }) |
|
42
|
|
|
|
|
59
|
|
90
|
|
|
|
|
|
|
{ |
91
|
56
|
50
|
|
|
|
2849
|
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
|
|
|
|
|
1434
|
print $FILE "\n"; |
100
|
7
|
|
|
|
|
9
|
++$edge_num; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
1
|
|
|
|
|
6
|
return 1; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _by_vertex |
108
|
|
|
|
|
|
|
{ |
109
|
13
|
|
|
13
|
|
107
|
return $a->[0].$a->[1] cmp $b->[0].$b->[1]; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |