Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Tuning an approximate match to prefer closer lengths

by bageler (Hermit)
on Nov 09, 2005 at 16:16 UTC ( [id://507121]=note: print w/replies, xml ) Need Help??


in reply to Tuning an approximate match to prefer closer lengths

using Text::Levenshtein's distance function, I get source1 as the best match.
use Text::Levenshtein qw(distance); $target = 'source'; $best=undef; for (qw(donor_dedupe_source indicted_video_source source1)) { $dist = distance($target,$_); if ($best == undef || $dist < $best) { $best = $dist; $bestword = $_; } } print "Best word was $bestword with an edit distance of $best\n";
output: Best word was source1 with an edit distance of 1

update: changed default value of $best to prevent perfect matches from being lost

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://507121]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-24 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found