in reply to dice's coefficient
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: dice's coefficient
by Anonymous Monk on Apr 14, 2008 at 07:51 UTC | |
by GrandFather (Saint) on Apr 14, 2008 at 09:57 UTC | |
by Anonymous Monk on Jan 14, 2012 at 10:49 UTC | |
by AnomalousMonk (Archbishop) on Jan 14, 2012 at 12:00 UTC | |
by Anonymous Monk on Jan 15, 2012 at 02:27 UTC |