Jaro similarity: Difference between revisions

m
→‎{{header|Raku}}: Raku style prefers identifiers with - instead of _
mNo edit summary
m (→‎{{header|Raku}}: Raku style prefers identifiers with - instead of _)
Line 2,832:
return 1 if $s eq $t;
 
my $s_lens-len = + my @s = $s.comb;
my $t_lent-len = + my @t = $t.comb;
my $match_distancematch-distance = ($s_lens-len max $t_lent-len) div 2 - 1;
 
my ($matches, @s_matchess-matches, @t_matchest-matches);
for ^@s -> $i {
my $start = 0 max $i - $match_distancematch-distance;
my $end = $i + $match_distancematch-distance min ($t_lent-len - 1);
 
for $start .. $end -> $j {
next if @t_matchest-matches[$j] or @s[$i] ne @t[$j];
(@s_matchess-matches[$i], @t_matchest-matches[$j]) = (1, 1);
$matches++ and last;
}
Line 2,851:
my ($k, $transpositions) = (0, 0);
for ^@s -> $i {
next unless @s_matchess-matches[$i];
$k++ until @t_matchest-matches[$k];
$transpositions++ if @s[$i] ne @t[$k];
$k++;
}
 
( $matches/$s_lens-len + $matches/$t_lent-len + (($matches - $transpositions/2) / $matches) ) / 3
}
 
say jaro(.key, .value).fmt: '%.3f' for
'MARTHA' => 'MARHTA', 'DIXON' => 'DICKSONX', 'JELLYFISH' => 'SMELLYFISH',
'I repeat myself' => 'I repeat myself', '' => '';</syntaxhighlight>
</syntaxhighlight>
{{out}}
<pre>0.944
1,480

edits