I like this approach! To extend the idea even further, if the phrases are short and there is a small number of mismatch types, each item could be reduced to several canonical forms, and those could be used as keys to the hash. For example,
cat could be reduced to
ca?,
c?t, and
?at, to cover single-letter substitutions. So
cat is found in that hash as a value in three different buckets. Faced with the word
hat, one of its canonical forms,
?at also keys into a bucket containing
cat and gets added there.
Other canonical forms might be obtained from Text::Soundex or Text::Metaphone where "similar" means "sound alike".
How to then transform this hash of word affinities into a single list with no repeats is left as an exercize for the reader. :-)
Update:
To flesh out the soundex idea a little, here's a short example:
use strict;
use Text::Soundex;
my @inwords = qw(holly perl monks yahoo monk holey google eperl holy g
+oxgle kugel april);
my (%hash, @outwords);
push @{$hash{soundex($_)}}, $_ foreach @inwords;
push @outwords, @{$hash{$_}} foreach keys %hash;
print join(' ', @outwords);
It prints:
google goxgle kugel perl holly holey holy yahoo april monks monk eperl
Since each word in this example has but one canonical form, it appears in the hash exactly once. So there are no repeats to untangle as with the
cat/hat illustration.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.