| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Text::EditTranscript; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
39714
|
use 5.008006; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
30
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
28
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
795
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
|
12
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
|
13
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# This allows declaration use Text::EditTranscript ':all'; |
|
16
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
|
17
|
|
|
|
|
|
|
# will save memory. |
|
18
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
) ] ); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
25
|
|
|
|
|
|
|
EditTranscript |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub EditTranscript { |
|
32
|
4
|
|
|
4
|
0
|
954
|
my $str = shift; |
|
33
|
4
|
|
|
|
|
5
|
my $str2 = shift; |
|
34
|
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
7
|
my $dist; |
|
36
|
|
|
|
|
|
|
my $transcript; |
|
37
|
4
|
|
|
|
|
11
|
for (my $i = 0; $i <= length($str); $i++) { |
|
38
|
260
|
|
|
|
|
527
|
$dist->[$i]->[0] = $i; |
|
39
|
260
|
|
|
|
|
618
|
$transcript->[$i]->[0] = "D"; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
4
|
|
|
|
|
10
|
for (my $i = 0; $i <= length($str2); $i++) { |
|
42
|
260
|
|
|
|
|
430
|
$dist->[0]->[$i] = $i; |
|
43
|
260
|
|
|
|
|
660
|
$transcript->[0]->[$i] = "I"; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
4
|
|
|
|
|
5
|
my $cost; |
|
48
|
|
|
|
|
|
|
|
|
49
|
4
|
|
|
|
|
8
|
for (my $i = 1; $i <= length($str); $i++) { |
|
50
|
256
|
|
|
|
|
512
|
for (my $j = 1; $j <= length($str2); $j++) { |
|
51
|
61036
|
100
|
|
|
|
124520
|
if (substr($str,$i-1,1) eq substr($str2,$j-1,1)) { |
|
52
|
5172
|
|
|
|
|
5620
|
$cost = 0; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
else { |
|
55
|
55864
|
|
|
|
|
62008
|
$cost = 1; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
61036
|
|
|
|
|
172589
|
$dist->[$i]->[$j] = Min($dist->[$i-1]->[$j] + 1, |
|
58
|
|
|
|
|
|
|
$dist->[$i]->[$j-1] + 1, |
|
59
|
|
|
|
|
|
|
$dist->[$i-1]->[$j-1] + $cost); |
|
60
|
61036
|
100
|
|
|
|
213154
|
if ($dist->[$i]->[$j] eq $dist->[$i]->[$j-1] + 1) { |
|
61
|
30391
|
|
|
|
|
59880
|
$transcript->[$i]->[$j] = "I"; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
61036
|
100
|
|
|
|
159526
|
if ($dist->[$i]->[$j] eq $dist->[$i-1]->[$j]+1) { |
|
64
|
30370
|
|
|
|
|
60771
|
$transcript->[$i]->[$j] = "D"; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
61036
|
100
|
|
|
|
202864
|
if ($dist->[$i]->[$j] eq $dist->[$i-1]->[$j-1] + $cost) { |
|
67
|
5646
|
100
|
|
|
|
9708
|
if ($cost eq 0) { |
|
68
|
5172
|
|
|
|
|
13712
|
$transcript->[$i]->[$j] = "-"; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
else { |
|
71
|
474
|
|
|
|
|
1264
|
$transcript->[$i]->[$j] = "S"; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
4
|
|
|
|
|
11
|
my $st = Traceback($transcript,length($str),length($str2)); |
|
78
|
4
|
|
|
|
|
10
|
$st = scalar reverse $st; |
|
79
|
4
|
|
|
|
|
9656
|
return $st; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub Traceback { |
|
84
|
4
|
|
|
4
|
0
|
7
|
my $transcript = shift; |
|
85
|
4
|
|
|
|
|
7
|
my $i = shift; |
|
86
|
4
|
|
|
|
|
5
|
my $j = shift; |
|
87
|
|
|
|
|
|
|
|
|
88
|
4
|
|
|
|
|
7
|
my $string; |
|
89
|
|
|
|
|
|
|
|
|
90
|
4
|
|
66
|
|
|
18
|
while ($i > 0 || $j > 0) { |
|
91
|
257
|
50
|
|
|
|
670
|
if (defined $transcript->[$i]->[$j]) { |
|
92
|
257
|
|
|
|
|
412
|
$string .= $transcript->[$i]->[$j]; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
257
|
50
|
|
|
|
482
|
last if (!defined $transcript->[$i]->[$j]); |
|
96
|
|
|
|
|
|
|
# to keep us from getting caught in loops |
|
97
|
257
|
100
|
100
|
|
|
1179
|
if ($transcript->[$i]->[$j] eq "S" || $transcript->[$i]->[$j] eq "-") { |
|
|
|
100
|
|
|
|
|
|
|
98
|
255
|
50
|
|
|
|
462
|
$i-- if ($i > 0); |
|
99
|
255
|
50
|
|
|
|
779
|
$j-- if ($j > 0); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
elsif ($transcript->[$i]->[$j] eq "I") { |
|
102
|
1
|
50
|
|
|
|
6
|
$j-- if ($j > 0); |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
else { |
|
105
|
1
|
50
|
|
|
|
4
|
$i-- if ($i > 0); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
4
|
|
|
|
|
11
|
return $string; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub Min { |
|
114
|
61036
|
|
|
61036
|
0
|
96320
|
my @list = @_; |
|
115
|
|
|
|
|
|
|
|
|
116
|
61036
|
|
|
|
|
107299
|
@list = sort {$a <=> $b} @list; |
|
|
182833
|
|
|
|
|
215085
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
61036
|
|
|
|
|
126848
|
return shift @list; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
|
123
|
|
|
|
|
|
|
__END__ |