| 1 | package Text::EditTranscript; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008006; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 1 | require Exporter; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 1 | 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 | 1 | our %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | ) ] ); | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 1 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||
| 25 | EditTranscript | ||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 1 | our $VERSION = '0.07'; | |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | sub EditTranscript { | ||||||||||||||||||||||||||||||
|
Subroutine
EditTranscript: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 32 | 4 | my $str = shift; | |||||||||||||||||||||||||||||||
| 33 | 4 | my $str2 = shift; | |||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 4 | my $dist; | |||||||||||||||||||||||||||||||
| 36 | my $transcript; | ||||||||||||||||||||||||||||||||
| 37 | 4 | ▶ | for (my $i = 0; $i <= length($str); $i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | 260 | $dist->[$i]->[0] = $i; | |||||||||||||||||||||||||||||||
| 39 | 260 | $transcript->[$i]->[0] = "D"; | |||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | for (my $i = 0; $i <= length($str2); $i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | 260 | $dist->[0]->[$i] = $i; | |||||||||||||||||||||||||||||||
| 43 | 260 | $transcript->[0]->[$i] = "I"; | |||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 4 | my $cost; | |||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 4 | ▶ | for (my $i = 1; $i <= length($str); $i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 50 | 256 | ▶ | for (my $j = 1; $j <= length($str2); $j++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 51 | 61036 | ▶ | if (substr($str,$i-1,1) eq substr($str2,$j-1,1)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 52 | 5172 | $cost = 0; | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | else { | ||||||||||||||||||||||||||||||||
| 55 | 55864 | $cost = 1; | |||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | 61036 | $dist->[$i]->[$j] = Min($dist->[$i-1]->[$j] + 1, | |||||||||||||||||||||||||||||||
| 58 | $dist->[$i]->[$j-1] + 1, | ||||||||||||||||||||||||||||||||
| 59 | $dist->[$i-1]->[$j-1] + $cost); | ||||||||||||||||||||||||||||||||
| 60 | 61036 | ▶ | if ($dist->[$i]->[$j] eq $dist->[$i]->[$j-1] + 1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 61 | 30391 | $transcript->[$i]->[$j] = "I"; | |||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | 61036 | ▶ | if ($dist->[$i]->[$j] eq $dist->[$i-1]->[$j]+1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | 30370 | $transcript->[$i]->[$j] = "D"; | |||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | 61036 | ▶ | if ($dist->[$i]->[$j] eq $dist->[$i-1]->[$j-1] + $cost) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | 5646 | ▶ | if ($cost eq 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | 5172 | $transcript->[$i]->[$j] = "-"; | |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | else { | ||||||||||||||||||||||||||||||||
| 71 | 474 | $transcript->[$i]->[$j] = "S"; | |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 4 | my $st = Traceback($transcript,length($str),length($str2)); | |||||||||||||||||||||||||||||||
| 78 | 4 | $st = scalar reverse $st; | |||||||||||||||||||||||||||||||
| 79 | 4 | return $st; | |||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 4 | ▶ | sub Traceback { | ||||||||||||||||||||||||||||||
|
Subroutine
Traceback: called CC=12 SCAR=25.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 84 | 4 | my $transcript = shift; | |||||||||||||||||||||||||||||||
| 85 | 4 | my $i = shift; | |||||||||||||||||||||||||||||||
| 86 | 4 | my $j = shift; | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 4 | my $string; | |||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 4 | ▶ | while ($i > 0 || $j > 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$i > 0 or $j > 0
MC/DC50%1/2
$i > 0 or $j > 0
$i > 0
$j > 0
Truth table66%2/3
A or B
A= $i > 0B= $j > 0
| |||||||||||||||||||||||||||||||||
| 91 | 257 | ▶ | if (defined $transcript->[$i]->[$j]) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 92 | 257 | $string .= $transcript->[$i]->[$j]; | |||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 257 | ▶ | last if (!defined $transcript->[$i]->[$j]); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 96 | # to keep us from getting caught in loops | ||||||||||||||||||||||||||||||||
| 97 | 257 | ▶ | if ($transcript->[$i]->[$j] eq "S" || $transcript->[$i]->[$j] eq "-") { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$transcript->[$i][$j] eq "S" or $transcript->[$i][$j] eq "-"
MC/DC100%2/2
$transcript->[$i][$j] eq "S" or $transcript->[$i][$j] eq "-"
$transcript->[$i][$j] eq "S"
$transcript->[$i][$j] eq "-"
Truth table100%3/3
A or B
A= $transcript->[$i][$j] eq "S"B= $transcript->[$i][$j] eq "-"
| |||||||||||||||||||||||||||||||||
| 98 | 255 | ▶ | $i-- if ($i > 0); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 99 | 255 | ▶ | $j-- if ($j > 0); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||
| 101 | elsif ($transcript->[$i]->[$j] eq "I") { | ||||||||||||||||||||||||||||||||
| 102 | 1 | ▶ | $j-- if ($j > 0); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | else { | ||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | $i-- if ($i > 0); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | 4 | return $string; | |||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | 61036 | ▶ | sub Min { | ||||||||||||||||||||||||||||||
|
Subroutine
Min: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 114 | 61036 | my @list = @_; | |||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 61036 | @list = sort {$a <=> $b} @list; | |||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 61036 | return shift @list; | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | 1 | 1; | |||||||||||||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||||||||||||||