LCS-Similar
view release on metacpan or search on metacpan
return 1 if ($a eq $b);
return 1 if (!$a eq !$b); # avoid division by zero
# length of LCS
my $llcs = LCS->LLCS(
[split(//,$a)],
[split(//,$b)],
);
# the standard formula
my $similarity = (2 * $llcs) / (length($a) + length($b));
return $similarity if ($similarity >= $threshold);
return 0;
}
# aligned indices of elements similar more than $threshold 0.5
my $lcs = LCS::Similar->LCS( $lines1, $lines2, \&similarity, 0.5 );
# map indices and not so similar elements into AoA of lines
my $aligned = LCS->lcs2align( $lines1, $lines2, $lcs );
lib/LCS/Similar.pm view on Meta::CPAN
return 1 if ($a eq $b);
return 1 if (!$a eq !$b); # avoid division by zero
# length of LCS
my $llcs = LCS->LLCS(
[split(//,$a)],
[split(//,$b)],
);
# the standard formula
my $similarity = (2 * $llcs) / (length($a) + length($b));
return $similarity if ($similarity >= $threshold);
return 0;
}
# aligned indices of elements similar more than $threshold 0.5
my $lcs = LCS::Similar->LCS( $lines1, $lines2, \&similarity, 0.5 );
# map indices and not so similar elements into AoA of lines
my $aligned = LCS->lcs2align( $lines1, $lines2, $lcs );
( run in 0.787 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )