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 = $tld->dld({ list => \@targets });
print $tld->{'fuor'};
# prints 1
print $tld->dld_best_match({ list => \@targets });
# prints fuor
print $tld->dld_best_distance({ list => \@targets });
# prints 1
DESCRIPTION
Returns the true Damerau Levenshtein edit distance of strings with adjacent transpositions.
CONSTRUCTOR
new
Creates and returns a Text::Levenshtein::Damerau
object. Takes a scalar with the text (source) you want to compare against.
my $tld = Text::Levenshtein::Damerau->new('Neil');
# Creates a new Text::Levenshtein::Damerau object $tld
METHODS
$tld->dld
Scalar Argument: Takes a string to compare with.
Returns: an integer representing the edit distance between the source and the passed argument.
Hashref Argument: Takes a hashref containing:
list => \@array (array ref of strings to compare with)
OPTIONAL max_distance => $int (only return results with a $int distance or less)
Returns: hashref with each word from the passed list as keys, and their edit distance (if less than max_distance, which is unlimited by default).
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 $d_ref = $tld->dld({ list=> \@names_list }); # pass a list, returns a hash
print $d_ref->{'Niel'}; #prints 1
print $d_ref->{'Jack'}; #prints 4
$tld->dld_best_match
Argument: an array reference of strings.
Returns: the string with the smallest edit distance between the source and the array of strings passed.
Takes distance of $tld source against every item in @targets, then returns the string of the best match.
my @name_spellings = ('Niel','Neell','KNiel');
print $tld->dld_best_match({ list=> \@name_spellings });
# prints Niel
$tld->dld_best_distance
Arguments: an array reference of strings.
Returns: the smallest edit distance between the source and the array reference of strings passed.
Takes distance of $tld source against every item in the passed array, then returns the smallest edit distance.
my @name_spellings = ('Niel','Neell','KNiel');
print $tld->dld_best_distance({ list => \@name_spellings });
# prints 1
EXPORTABLE METHODS
edistance
Arguments: source string and target string.
Returns: scalar containing int that represents the edit distance between the two argument.
Function to take the edit distance between a source and target string. Contains the actual algorithm implementation
use Text::Levenshtein::Damerau qw/edistance/;
print edistance('Neil','Niel');
# prints 1
SEE ALSO
BUGS
Please report bugs to:
https://rt.cpan.org/Public/Dist/Display.html?Name=Text-Levenshtein-Damerau
AUTHOR
ugexe <ug@skunkds.com>
LICENSE AND COPYRIGHT
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.