Jaro similarity: Difference between revisions
m
→{{header|Perl}}: add strict & warnings, sundry simplifications, 2 more tests
m (→Python :: Composition of pure functions: Tidied, updated primitives.) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: add strict & warnings, sundry simplifications, 2 more tests) |
||
Line 1,892:
=={{header|Perl}}==
<lang perl>use
use warnings;
use List::Util qw(min max);
sub jaro {
my
my(@s_matches, @t_matches, $matches);▼
my $match_distance = int(max($s_len, $t_len) / 2) - 1;▼
▲ my @t_matches;
▲ my @t = split(//, $t);
my $matches = 0;▼
foreach my $i (0 .. $#s) {▼
▲ my $match_distance = int (max($s_len, $t_len) / 2) - 1;
my $start = max(0, $i - $match_distance);
my $end = min($i + $match_distance + 1, $t_len);
for my $j ($start .. $end - 1) {
($s_matches[$i], $t_matches[$j]) =
$
$s_matches[$i] = 1;▼
}
}
for my $i (0 .. $#s) {
}
▲ (($matches - $transpositions / 2) / $matches)) / 3;
}
printf
['MARTHA', 'MARHTA'], ['DIXON', 'DICKSONX'], ['JELLYFISH', 'SMELLYFISH'],
['I repeat myself', 'I repeat myself'], ['', ''];</lang>
{{out}}
<pre>0.944
0.
0.
1.000
1.000</pre>
=={{header|Phix}}==
|