NAME
Text::Levenshtein::Damerau - Damerau Levenshtein edit distance
SYNOPSIS
use Text::Levenshtein::Damerau;
use warnings;
use strict;
my @targets = ('fuor','xr','fourrrr','fo');
# Initialize Text::Levenshtein::Damerau object with text to compare against
my $tld = Text::Levenshtein::Damerau->new('four');
print $tld->dld($targets[0]);
# prints 1
my %tld_hash = $tld->dld(@targets);
print $tld_hash{'fuor'};
# prints 1
print $tld->dld_best_match(@targets);
# prints fuor
print $tld->dld_best_distance(@targets);
# prints 1
DESCRIPTION
Returns the true Damerau Levenshtein edit distance of strings with adjacent transpositions.
Methods
- new
-
Constructor. Takes a scalar with the text (source) you want to compare against. my $tld = Text::Levenshtein::Damerau->new('Neil');
- dld
-
2 argument: takes a scalar (string to compare against) and returns a scalar (the edit distance) 3 argument: takes an int (maximum distance to record; default is 8, 0 = unlimited), an array (of strings to compare against), and returns a hash such that $hash{$string_from_list} = $edit_distance
my $tld = Text::Levenshtein::Damerau->new('Neil'); print $tld->dld('Niel'); # prints 1 #or if you want to check the distance of various items in a list my @names_list = ('Neil','Jack'); my $tld = Text::Levenshtein::Damerau->new('Neil'); my %distance_hash = $tld->dld(@names_list); # pass a list, returns a hash print $distance_hash{'Niel'}; #prints 1 print $distance_hash{'Jack'}; #prints 4
- dld_best_match
-
Takes an array of strings as an argument, and returns the string with the smallest edit distance between the source and the array of strings passed.
my @name_spellings = ('Niel','Neell','KNiel'); print $tld->dld_best_match( @name_spellings ); # Takes distance of $tld source against every item in @targets, then returns the string of the best match
- dld_best_distance
-
Takes an array of strings as an argument, and returns the smallest edit distance between the source and the array of strings passed.
my @name_spellings = ('Niel','Neell','KNiel'); my $best_matching_string_distance = $tld->dld_best_distance( @name_spellings ); # Takes distance of $tld source against every item in @name_spellings, then returns the smallest edit distance
- edistance
-
Exportable function to take the edit distance between a source and target string. Contains the actual algorithm implementation
use Text::Levenshtein::Damerau qw/edistance/; my $edit_distance = edistance('Neil','Niel'); # Takes distance of $tld source against every item in @targets, then returns the smallest edit distance
AUTHOR
ugexe <ug@skunkds.com>
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.