Text completion: Difference between revisions

Content added Content deleted
m (→‎Sorenson-Dice: better DRY)
m (→‎Sorenson-Dice: fewer intermediates)
Line 551: Line 551:
<lang perl6>sub sorenson ($phrase, %hash) {
<lang perl6>sub sorenson ($phrase, %hash) {
my $match = bigram $phrase;
my $match = bigram $phrase;
%hash.race.map: {
%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
# Load the dictionary