| 1 | package Lingua::AlSetLib; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | $VERSION=1.1; | |||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Dumpvalue; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # input: array of integers | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # output: array of contiguous integer arrays | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 0 | ▶ | sub getContiguousSequences { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getContiguousSequences: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 0 | my $array=shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | my $dumper = new Dumpvalue; | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | my @sortedArray = sort {$a <=> $b} @$array; | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | # print "sorted ARRay:\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # print $dumper->dumpValue(\@sortedArray); | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | my $sequences=[]; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my $numSeq=0; | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | if (@$array > 0){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my $former = $sortedArray[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | push @{$sequences->[$numSeq]},$former; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | for (my $i=1;$i<@sortedArray;$i++){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | if ($sortedArray[$i]== ($former+1)){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | push @{$sequences->[$numSeq]},$sortedArray[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | $numSeq++; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | push @{$sequences->[$numSeq]},$sortedArray[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | $former=$sortedArray[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # print "SEQUENCES (best $longuestSequence):\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # print $dumper->dumpValue($sequences); | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | return $sequences; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub getLonguestContiguousSequence { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getLonguestContiguousSequence: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $array=shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $dumper = new Dumpvalue; | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my @sortedArray = sort {$a <=> $b} @$array; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | # print "sorted ARRay:\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # print $dumper->dumpValue(\@sortedArray); | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $sequences=[]; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my ($currentLength,$greatestLength,$longuestSequence,$numSeq)=(0,0,0,0); | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if (@$array > 0){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $former = $sortedArray[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | push @{$sequences->[$numSeq]},$former; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $currentLength++; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $greatestLength=$currentLength; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $longuestSequence = $numSeq; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | for (my $i=1;$i<@sortedArray;$i++){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($sortedArray[$i]== ($former+1)){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | push @{$sequences->[$numSeq]},$sortedArray[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $currentLength++; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ($currentLength > $greatestLength){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $greatestLength=$currentLength; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $longuestSequence = $numSeq; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $numSeq++; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | push @{$sequences->[$numSeq]},$sortedArray[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $currentLength=1; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($currentLength > $greatestLength){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $greatestLength=$currentLength; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $longuestSequence = $numSeq; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $former=$sortedArray[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # print "SEQUENCES (best $longuestSequence):\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # print $dumper->dumpValue($sequences); | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | return $sequences->[$longuestSequence]; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub ibm1Prob { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ibm1Prob: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my ($src,$trg,$pt_s)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my @wsrc=split(/ /, $src); | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my @wtrg=split(/ /, $trg); | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $numWs = scalar(@wsrc); | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $numWt = scalar(@wtrg); | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # IBM1 SRC->TRG | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if (@wsrc>1){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | unshift @wtrg,"NULL"; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $numWt++; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $prod=1; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | for my $ws (@wsrc){ | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $sum=0; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | for my $wt (@wtrg){ | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $srctrg="$ws ||| $wt"; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $sum+=$pt_s->{$srctrg}; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | #print "\t$srctrg => $pt_s->{$srctrg} ( $sum )\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $prod*=$sum; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | #calcul de la probabilitat ibm1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # my $ibm1_st=$prod/($numWt**$numWs); | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $ibm1_st=$prod; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ($ibm1_st==0){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $ibm1_st=1.0e-40; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # print "$src | $trg ==> prod:$prod I:$numWt J:$numWs ibmst: $ibm1_st\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return $ibm1_st; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # INPUT: ref to array A, ref to array B | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # OUTPUT: list of positions of array A where array B begins in A | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # EX: A=(4,5,8,3,9,22,8,3) B=(8,3) output=(2,6) | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub findArrayInAnother { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
findArrayInAnother: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my ($refToSubArray,$refToArray)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my @startPosi; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $numSub = scalar(@$refToSubArray); | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $numArray=scalar(@$refToArray); | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if ($numArray >= $numSub){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | for (my $i=0;$i<$numArray;$i++){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $failed=0; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $subi=0; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | while (!$failed && $subi<$numSub){ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $failed and $subi < $numSub
MC/DC0%0/2
not $failed and $subi < $numSub
not $failed
$subi < $numSub
Truth table0%0/3
not(A) and B
A= not $failedB= $subi < $numSub
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($refToSubArray->[$subi] ne $refToArray->[$i+$subi]){$failed=1;} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $subi++; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if (!$failed){push @startPosi,$i;} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return @startPosi; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | ######################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ### SUBROUTINES COPIED FROM ALGORITHM::DIFF CPAN MODULE # | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ######################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | sub _withPositionsOfInInterval | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_withPositionsOfInInterval: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my $aCollection = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $start = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $end = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my $keyGen = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my %d; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | my $index; | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | for ( $index = $start ; $index <= $end ; $index++ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $element = $aCollection->[$index]; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $key = &$keyGen( $element, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if ( exists( $d{$key} ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | unshift ( @{ $d{$key} }, $index ); | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $d{$key} = [$index]; | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | return wantarray ? %d : \%d; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | sub _replaceNextLargerWith | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_replaceNextLargerWith: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my ( $array, $aValue, $high ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | $high ||= $#$array; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$high ||= $array->$#*
MC/DC0%0/2
$high ||= $array->$#*
$high
$array->$#*
Truth table0%0/3
A ||= B
A= $highB= $array->$#*
| |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # off the end? | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if ( $high == -1 || $aValue > $array->[-1] ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$high == -1 or $aValue > $array->[-1]
MC/DC0%0/2
$high == -1 or $aValue > $array->[-1]
$high == -1
$aValue > $array->[-1]
Truth table0%0/3
A or B
A= $high == -1B= $aValue > $array->[-1]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | push ( @$array, $aValue ); | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | return $high + 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # binary search for insertion point... | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | my $low = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my $index; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | my $found; | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | while ( $low <= $high ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $index = ( $high + $low ) / 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # $index = int(( $high + $low ) / 2); # without 'use integer' | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $found = $array->[$index]; | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if ( $aValue == $found ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | elsif ( $aValue > $found ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $low = $index + 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $high = $index - 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # now insertion point is in $low. | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $array->[$low] = $aValue; # overwrite next larger | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | return $low; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | sub _longestCommonSubsequence | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_longestCommonSubsequence: not called CC=25 SCAR=64.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my $a = shift; # array ref or hash ref | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my $b = shift; # array ref or hash ref | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $counting = shift; # scalar | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my $keyGen = shift; # code ref | |||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $compare; # code ref | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ( ref($a) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | { # prepared hash must be in $b | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my $tmp = $b; | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $b = $a; | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $a = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # Check for bogus (non-ref) argument values | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if ( !ref($a) || !ref($b) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $a and ref $b
MC/DC0%0/2
ref $a and ref $b
ref $a
ref $b
Truth table0%0/3
A and B
A= ref $aB= ref $b
| |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my @callerInfo = caller(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | die 'error: must pass array or hash references to ' . $callerInfo[3]; | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # set up code refs | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # Note that these are optimized. | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ( !defined($keyGen) ) # optimize for strings | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | $keyGen = sub { $_[0] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | $compare = sub { my ( $a, $b ) = @_; $a eq $b }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | $compare = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $a = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my $b = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | &$keyGen( $a, @_ ) eq &$keyGen( $b, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my ( $aStart, $aFinish, $matchVector ) = ( 0, $#$a, [] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my ( $prunedCount, $bMatches ) = ( 0, {} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | if ( ref($b) eq 'HASH' ) # was $bMatches prepared for us? | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $bMatches = $b; | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my ( $bStart, $bFinish ) = ( 0, $#$b ); | |||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # First we prune off any common elements at the beginning | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | while ( $aStart <= $aFinish | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$aStart <= $aFinish and $bStart <= $bFinish and &$compare($a->[$aStart], $b->[$bStart], @_)
$aStart <= $aFinish and $bStart <= $bFinish
MC/DC0%0/3
$aStart <= $aFinish and $bStart <= $bFinish and &$compare($a->[$aStart], $b->[$bStart], @_)
$aStart <= $aFinish
$bStart <= $bFinish
&$compare($a->[$aStart], $b->[$bStart], @_)
Truth table0%0/4
A and B and C
A= $aStart <= $aFinishB= $bStart <= $bFinishC= &$compare($a->[$aStart], $b->[$bStart], @_)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | and $bStart <= $bFinish | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | and &$compare( $a->[$aStart], $b->[$bStart], @_ ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $matchVector->[ $aStart++ ] = $bStart++; | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $prunedCount++; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # now the end | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | while ( $aStart <= $aFinish | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$aStart <= $aFinish and $bStart <= $bFinish and &$compare($a->[$aFinish], $b->[$bFinish], @_)
$aStart <= $aFinish and $bStart <= $bFinish
MC/DC0%0/3
$aStart <= $aFinish and $bStart <= $bFinish and &$compare($a->[$aFinish], $b->[$bFinish], @_)
$aStart <= $aFinish
$bStart <= $bFinish
&$compare($a->[$aFinish], $b->[$bFinish], @_)
Truth table0%0/4
A and B and C
A= $aStart <= $aFinishB= $bStart <= $bFinishC= &$compare($a->[$aFinish], $b->[$bFinish], @_)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | and $bStart <= $bFinish | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | and &$compare( $a->[$aFinish], $b->[$bFinish], @_ ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $matchVector->[ $aFinish-- ] = $bFinish--; | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $prunedCount++; | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # Now compute the equivalence classes of positions of elements | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | $bMatches = | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | _withPositionsOfInInterval( $b, $bStart, $bFinish, $keyGen, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my $thresh = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $links = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my ( $i, $ai, $j, $k ); | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | for ( $i = $aStart ; $i <= $aFinish ; $i++ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $ai = &$keyGen( $a->[$i], @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | if ( exists( $bMatches->{$ai} ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $k = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | for $j ( @{ $bMatches->{$ai} } ) | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # optimization: most of the time this will be true | ||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | if ( $k and $thresh->[$k] > $j and $thresh->[ $k - 1 ] < $j ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$k and $thresh->[$k] > $j and $$thresh[$k - 1] < $j
$k and $thresh->[$k] > $j
MC/DC0%0/3
$k and $thresh->[$k] > $j and $$thresh[$k - 1] < $j
$k
$thresh->[$k] > $j
$$thresh[$k - 1] < $j
Truth table0%0/4
A and B and C
A= $kB= $thresh->[$k] > $jC= $$thresh[$k - 1] < $j
| |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $thresh->[$k] = $j; | |||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $k = _replaceNextLargerWith( $thresh, $j, $k ); | |||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # oddly, it's faster to always test this (CPU cache?). | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | if ( defined($k) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | $links->[$k] = | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | [ ( $k ? $links->[ $k - 1 ] : undef ), $i, $j ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | if (@$thresh) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | return $prunedCount + @$thresh if $counting; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | for ( my $link = $links->[$#$thresh] ; $link ; $link = $link->[0] ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $matchVector->[ $link->[1] ] = $link->[2]; | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | elsif ($counting) | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | return $prunedCount; | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | return wantarray ? @$matchVector : $matchVector; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | sub LCS | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
LCS: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my $a = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my $b = shift; # array ref or hash ref | |||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | my $matchVector = _longestCommonSubsequence( $a, $b, 0, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | my @retval; | |||||||||||||||||||||||||||||||||||||||||||||
| 326 | my $i; | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | for ( $i = 0 ; $i <= $#$matchVector ; $i++ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | if ( defined( $matchVector->[$i] ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | push ( @retval, $a->[$i] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | return wantarray ? @retval : \@retval; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | sub LCS_ratio | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
LCS_ratio: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my $a = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | my $b = shift; # array ref or hash ref | |||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my $lon=_longestCommonSubsequence( $a, $b, 1, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 343 | # if ($lon>0){print "LCS:$lon\n";} | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | my $ratio; | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | #Aquà hago el ratio de la similitud cogiendo como valor total la longitud de la frase que sea más larga | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | my $m=scalar(@$a); | |||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my $n=scalar(@$b); | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if (($m >= $n) && ($m != 0) && ($n != 0)){$ratio=$lon/$m;} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$m >= $n and $m != 0 and $n != 0
$m >= $n and $m != 0
MC/DC0%0/3
$m >= $n and $m != 0 and $n != 0
$m >= $n
$m != 0
$n != 0
Truth table0%0/4
A and B and C
A= $m >= $nB= $m != 0C= $n != 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | elsif(($m < $n) && ($m != 0) && ($n != 0)){$ratio=$lon/$n;} | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$m < $n and $m != 0 and $n != 0
$m < $n and $m != 0
MC/DC0%0/3
$m < $n and $m != 0 and $n != 0
$m < $n
$m != 0
$n != 0
Truth table0%0/4
A and B and C
A= $m < $nB= $m != 0C= $n != 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | else{$ratio=0;} | |||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | return ($ratio); | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | sub traverse_sequences | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
traverse_sequences: not called CC=20 SCAR=60.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my $a = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my $b = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | my $callbacks = shift || {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my $keyGen = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | my $matchCallback = $callbacks->{'MATCH'} || sub { }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$callbacks->{'MATCH'} || sub {
}
MC/DC0%0/2
$callbacks->{'MATCH'} || sub {
}
$callbacks->{'MATCH'}
sub {
}
Truth table0%0/3
A || B
A= $callbacks->{'MATCH'}B= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | my $discardACallback = $callbacks->{'DISCARD_A'} || sub { }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$callbacks->{'DISCARD_A'} || sub {
}
MC/DC0%0/2
$callbacks->{'DISCARD_A'} || sub {
}
$callbacks->{'DISCARD_A'}
sub {
}
Truth table0%0/3
A || B
A= $callbacks->{'DISCARD_A'}B= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my $finishedACallback = $callbacks->{'A_FINISHED'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | my $discardBCallback = $callbacks->{'DISCARD_B'} || sub { }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$callbacks->{'DISCARD_B'} || sub {
}
MC/DC0%0/2
$callbacks->{'DISCARD_B'} || sub {
}
$callbacks->{'DISCARD_B'}
sub {
}
Truth table0%0/3
A || B
A= $callbacks->{'DISCARD_B'}B= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | my $finishedBCallback = $callbacks->{'B_FINISHED'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $matchVector = _longestCommonSubsequence( $a, $b, 0, $keyGen, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | # Process all the lines in @$matchVector | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | my $lastA = $#$a; | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | my $lastB = $#$b; | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | my $bi = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my $ai; | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | for ( $ai = 0 ; $ai <= $#$matchVector ; $ai++ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my $bLine = $matchVector->[$ai]; | |||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | if ( defined($bLine) ) # matched | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | &$discardBCallback( $ai, $bi++, @_ ) while $bi < $bLine; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | &$matchCallback( $ai, $bi++, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | &$discardACallback( $ai, $bi, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # The last entry (if any) processed was a match. | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # $ai and $bi point just past the last matching lines in their sequences. | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | while ( $ai <= $lastA or $bi <= $lastB ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ai <= $lastA or $bi <= $lastB
MC/DC0%0/2
$ai <= $lastA or $bi <= $lastB
$ai <= $lastA
$bi <= $lastB
Truth table0%0/3
A or B
A= $ai <= $lastAB= $bi <= $lastB
| |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # last A? | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | if ( $ai == $lastA + 1 and $bi <= $lastB ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ai == $lastA + 1 and $bi <= $lastB
MC/DC0%0/2
$ai == $lastA + 1 and $bi <= $lastB
$ai == $lastA + 1
$bi <= $lastB
Truth table0%0/3
A and B
A= $ai == $lastA + 1B= $bi <= $lastB
| |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | if ( defined($finishedACallback) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | &$finishedACallback( $lastA, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $finishedACallback = undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | &$discardBCallback( $ai, $bi++, @_ ) while $bi <= $lastB; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # last B? | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | if ( $bi == $lastB + 1 and $ai <= $lastA ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$bi == $lastB + 1 and $ai <= $lastA
MC/DC0%0/2
$bi == $lastB + 1 and $ai <= $lastA
$bi == $lastB + 1
$ai <= $lastA
Truth table0%0/3
A and B
A= $bi == $lastB + 1B= $ai <= $lastA
| |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | if ( defined($finishedBCallback) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | &$finishedBCallback( $lastB, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $finishedBCallback = undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 416 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 417 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | &$discardACallback( $ai++, $bi, @_ ) while $ai <= $lastA; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | &$discardACallback( $ai++, $bi, @_ ) if $ai <= $lastA; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | &$discardBCallback( $ai, $bi++, @_ ) if $bi <= $lastB; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||
| 429 | #diff computes the smallest set of additions and deletions necessary to turn the first sequence into the second, and returns a description of these changes. The description is a list of hunks; each hunk represents a contiguous section of items which should be added, deleted, or replaced. (Hunks containing unchanged items are not included.) | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # EXAMPLES: | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # @diffs = diff( \@seq1, \@seq2 ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # $diffs_ref = diff( \@seq1, \@seq2 ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 433 | sub diff | ||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
diff: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | my $a = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | my $b = shift; # array ref | |||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | my $retval = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $hunk = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | my $discard = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | push @$hunk, [ '-', $_[0], $a->[ $_[0] ] ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | my $add = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | push @$hunk, [ '+', $_[1], $b->[ $_[1] ] ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | my $match = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | push @$retval, $hunk | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 447 | if 0 < @$hunk; | ||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | $hunk = [] | |||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | traverse_sequences( $a, $b, | |||||||||||||||||||||||||||||||||||||||||||||
| 451 | { MATCH => $match, DISCARD_A => $discard, DISCARD_B => $add }, @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | &$match(); | |||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | return wantarray ? @$retval : $retval; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||
| 456 | ###### END ALGORITHM::DIFF FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | sub max { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | my ($a,$b)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | if ($a > $b) {return $a;} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | else {return $b}; | |||||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | sub min { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
min: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | my ($a,$b)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | ▶ | if ($a < $b) {return $a;} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | else {return $b}; | |||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||
| 471 | ### copy-paste of Algorithm::MinMax module (to avoid having dependencies) | ||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | sub minmax { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
minmax: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | my @array = @{ $_[ 1 ] }; | |||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | my @result; | |||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | if( scalar( @array ) == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | return @result; | |||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | if( scalar( @array ) == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | $result[ 0 ] = $array[ 0 ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | $result[ 1 ] = $array[ 0 ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | return @result; | |||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | my @min_cand; | |||||||||||||||||||||||||||||||||||||||||||||
| 484 | my @max_cand; | ||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | my $r = scalar( @array ) - 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | my $k = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | for( my $i = 0; $i <= $r ; $i = $i + 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | if( $array[ $i ] < $array[ $i + 1 ] ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | $min_cand[ $k ] = $array[ $i ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | $max_cand[ $k ] = $array[ $i + 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 491 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | $min_cand[ $k ] = $array[ $i + 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | $max_cand[ $k ] = $array[ $i ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ++$k; | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | if( scalar( @array ) % 2 != 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | if( $min_cand[ 0 ] < $array[ $r + 1 ] ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | $max_cand[ $k ] = $array[ $r + 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 500 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | $min_cand[ $k ] = $array[ $r + 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | my $m = $min_cand[ 0 ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | for( my $i = 1; $i < scalar( @min_cand ); ++$i ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | ▶ | if( $min_cand[ $i ] < $m ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | $m = $min_cand[ $i ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | $result[ 0 ] = $m; | |||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | $m = $max_cand[ 0 ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | for( my $i = 1; $i < scalar( @max_cand ); ++$i ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | if( $max_cand[ $i ] > $m ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | $m = $max_cand[ $i ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | $result[ 1 ] = $m; | |||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | @result; | |||||||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||
| 521 | ### END Algorithm::MinMax function | ||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | sub escapeRegExp { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
escapeRegExp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | my $line = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 527 | # regExp characters to escape: \ | ( ) [ { ^ $ * + ? . | ||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | $line =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | $line =~ s/\|/\\\|/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | $line =~ s/\(/\\\(/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | $line =~ s/\)/\\\)/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | $line =~ s/\[/\\\[/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | $line =~ s/\{/\\\}/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | $line =~ s/\^/\\\^/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | $line =~ s/\$/\\\$/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $line =~ s/\*/\\\*/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | $line =~ s/\+/\\\+/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | $line =~ s/\?/\\\?/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | $line =~ s/\./\\\./g; | |||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||