The following may get you headed in a useful direction:
use strict; use warnings; use List::Compare; my @words = qw(dictate world mamal); my %dict; # Build a lookup for the dictionary words while (defined (my $word = <DATA>)) { chomp $word; next unless length $word; my @bigrams = grep length == 2, map {substr $word, $_, 2} 0 .. len +gth ($word) - 1; next unless @bigrams; $dict{$word} = \@bigrams; } # Process the given words for my $word (@words) { my @bigrams = grep length == 2, map {substr $word, $_, 2} 0 .. len +gth ($word) - 1; next unless @bigrams; for my $dictWord (keys %dict) { my $lc = List::Compare->new($dict{$dictWord}, \@bigrams); my @common = $lc->get_intersection (); my $diceCoef = 2 * @common / (@bigrams + @{$dict{$dictWord}}); next unless $diceCoef; print "Dice coefficient for '$word' and '$dictWord' is $diceCo +ef\n"; } } __DATA__ a small dictionary of words
Prints:
Dice coefficient for 'dictate' and 'dictionary' is 0.4 Dice coefficient for 'world' and 'words' is 0.5 Dice coefficient for 'mamal' and 'small' is 0.5
In reply to Re: dice's coefficient
by GrandFather
in thread dice's coefficient
by locked_user zanruka
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |