Text completion: Difference between revisions

m
→‎Sorenson-Dice: fewer intermediates
m (→‎Sorenson-Dice: better DRY)
m (→‎Sorenson-Dice: fewer intermediates)
Line 551:
<lang perl6>sub sorenson ($phrase, %hash) {
my $match = bigram $phrase;
%hash.race.map: { [(2 * +($match ∩ .value) / (+$match + .value)).round(.001), .key] }
my $this = .value;
[(2 * +($match ∩ $this) / (+$match + $this)).round(.001), .key]
}
}
 
sub bigram (\these) {
Bag.new( flat these.fc.words.map: { .comb.rotor(2 => -1)».join } )
}
 
sub bigram (\these) { Bag.new( flat these.fc.words.map: { .comb.rotor(2 => -1)».join } ) }
 
# Load the dictionary
10,327

edits