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.
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
2 Arguments dld($string): takes a scalar (string to compare against)
Returns: a scalar (the edit distance)
3 Arguments dld(8,$string): takes an int (maximum edit distance to record; default is 8, 0 = unlimited), and an array (of strings to compare against).
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(8, @names_list); # pass a list, returns a hash
print $distance_hash{'Niel'}; #prints 1
print $distance_hash{'Jack'}; #prints 4
$tld->dld_best_match
Arguments: an array 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( @name_spellings );
# prints Niel
$tld->dld_best_distance
Arguments: an array of strings.
Returns: the smallest edit distance between the source and the array 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( @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
https://github.com/ugexe/Text--Levenshtein--Damerau =item * http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_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.