Text::...amerau(3pm)
okay so bestie, you clicked into the Text::Levenshtein::Damerau(3pm) manual page and honestly? taste. π
this is the Group Chatβ’ version, same facts, way better vibes.
π NAME π
Text::Levenshtein::Damerau β Damerau Levenshtein edit distance. that's it, that's the whole thing β¨
π¦ SYNOPSIS π¦
here's the entire vibe in one copy-pasteable block, no cap:
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
# or even more simply
use Text::Levenshtein::Damerau qw/edistance/;
use warnings;
use strict;
print edistance('Neil','Niel');
# prints 1
πΈ DESCRIPTION πΈ
Returns the true Damerau Levenshtein edit distance of strings with adjacent transpositions. lowkey a legend for fuzzy matching, DNA variation metrics, and fraud detection. π΅οΈββοΈ
Defaults to using Pure Perl Text::Levenshtein::Damerau::PP, but there's an XS addon Text::Levenshtein::Damerau::XS for massive speed improvements. ποΈβ¨ Works correctly with utf8 if the backend supports it; known to work with Text::Levenshtein::Damerau::PP and Text::Levenshtein::Damerau::XS.
oh and it absolutely eats with unicode, watch:
use utf8;
my $tld = Text::Levenshtein::Damerau->new('βββ€β‘');
print $tld->dld('ββ€ββ‘');
# prints 1
π«Ά CONSTRUCTOR π«Ά
β¨ new
Creates and returns a Text::Levenshtein::Damerau object. Takes a scalar with the text (source) you want to compare against. that's the main character, the one everything else gets measured 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$intdistance or less). - OPTIONAL
backend => 'Some::Module::its_function'β any module that will take 2 arguments and returns an int. If the module fails to load, the function doesn't exist, or the function doesn't return a number when passed 2 strings, thenbackendremains unchanged. π
so you can override the defaults like this:
# Override defaults and use Text::Levenshtein::Damerau::PP's pp_edistance()
$tld->dld({ list=> \@list, backend => 'Text::Levenshtein::Damerau::PP::pp_edistance');
# Override defaults and use Text::Levenshtein::Damerau::XS's xs_edistance()
use Text::Levenshtein::Damerau;
requires Text::Levenshtein::Damerau::XS;
...
$tld->dld({ list=> \@list, backend => 'Text::Levenshtein::Damerau::XS::xs_edistance');
Returns: a 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 = ('Niel','Jack');
my $tld = Text::Levenshtein::Damerau->new('Neil');
my $d_ref = $tld->dld({ list=> \@names_list }); # pass a list, returns a hash ref
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 the distance of the $tld source against every item in @targets, then returns the string of the best match. it's giving "who wore it best" but for spelling. π
my $tld = Text::Levenshtein::Damerau->new('Neil');
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 the distance of the $tld source against every item in the passed array, then returns the smallest edit distance.
my $tld = Text::Levenshtein::Damerau->new('Neil');
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.
- OPTIONAL 3rd argument int (max distance; only return results with
$intdistance or less).0= unlimited. Default =0.
Returns: int that represents the edit distance between the two arguments. -1 if max distance is set and reached.
Wrapper function to take the edit distance between a source and target string. It will attempt to use, in order:
Text::Levenshtein::Damerau::XSxs_edistanceText::Levenshtein::Damerau::PPpp_edistance
use Text::Levenshtein::Damerau qw/edistance/;
print edistance('Neil','Niel');
# prints 1
π SEE ALSO π
<https://github.com/ugexe/Text--Levenshtein--Damerau>β Repository<http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance>β Damerau levenshtein explanationText::Fuzzyβ Regular levenshtein distance
π BUGS π
Please report bugs to:
<https://rt.cpan.org/Public/Dist/Display.html?Name=Text-Levenshtein-Damerau>
not me begging you to file the bug report instead of just suffering in silence π do it for the plot.
π AUTHOR π
Nick Logan <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.
and that's the whole page bestie π«Ά this manual came bundled as perl v5.36.0, last touched 2022-10-13, and it ate, no crumbs left. slay, go compute some edit distances πβ¨
π¦ where this page comes from
- ubuntu noble: libtext-levenshtein-damerau-perl 0.41-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtext-levenshtein-damerau-perl 0.41-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtext-levenshtein-damerau-perl 0.41-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms