Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: improved levenshtein

by Bill.Costa (Acolyte)
on Oct 16, 2013 at 01:21 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-03-19 03:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found