Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: improved levenshtein

by Bill.Costa (Acolyte)
on Oct 16, 2013 at 01:21 UTC ( #1058380=note: print w/replies, xml ) Need Help??

in reply to improved levenshtein

I copied this module and put the following test code in the body. I didn't get expected results when I made simple changes within the string. For example, why isn't "set" => "sit" a distance of 1 (this code returns 2). I created a larger test set that also generates substr outside of string warnings as well. But these warnings went away and all the tests work as expected, when I commented out the early exits (return) in the first two for loops.

my @tSet = ( [ qw(a a 0) ], [ qw(batman batman 0) ], [ qw(a b 1) ], [ qw(here there 1) ], [ qw(cat cats 1) ], [ qw(set sit 1) ], # returns 2 [ qw(robin Robin 1) ], [ qw(robin Bobin 1) ], [ qw(robin roBin 1) ], # returns 2 [ qw(set tes 2) ], [ qw(postal postage 2) ], [ qw(kitten sitting 3) ], [ qw(aaaaaaaaaaaaaaa bbbbbbbbbbbbbbb 15) ], ); use Test::More; foreach my $set (@tSet) { my($s, $t, $d) = @{$set}; my $got = distance($s, $t); if ($got != $d) { ok(0, "$s x $t => $d but got $got") } else { ok(1, "$s x $t => $d") } } done_testing(scalar(@tSet));

Replies are listed 'Best First'.
Re^2: improved levenshtein
by boftx (Deacon) on Oct 16, 2013 at 01:46 UTC

    What is the code for distance()?

    Update: Nevermind, the OP was changed while I was posting this.

    The answer to the question "Can we do this?" is always an emphatic "Yes!" Just give me enough time and money.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2018-11-21 05:42 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (237 votes). Check out past polls.