=pod
=encoding utf8
=head1 Name
Text::Levenshtein::Damerau - Levenshtein and Damerau Levenshtein edit distances
=for HTML
=head1 Synopsis
use Text::Levenshtein::Damerau;
say dld('Neil','Niel'); # damerau levenstein distance
# prints 1
say ld('Neil','Niel'); # levenshtein distance
prints 2
=head1 Description
Returns the true Levenshtein or Damerau Levenshtein edit distance of strings with adjacent transpositions.
use Text::Levenshtein::Damerau;
my @names = 'John','Jonathan','Jose','Juan','Jimmy';
my $name_mispelling = 'Jonh';
my $dl = Text::Levenshtein::Damerau.new(
max => 0, # default
targets => @names, # required
sources => [$name_mispelling]
);
say "Lets search for a 'John' but mistyped...";
my %results = $dl.get_results;
# Display each source, target, and the distance
for %results.kv -> $source, $targets {
for $targets.kv -> $target, $dld {
say "source:$source\ttarget:$target\tdld:" ~ ($dld // "");
}
}
# More info
say "----------------------------";
say "\$dl.best_distance: {$dl.best_distance}";
say "-";
say "\$dl.targets: {~$dl.targets}";
say "\$dl.best_target: {$dl.best_target}";
say "-";
say "\@names: {~@names}";
=head2 Routines
=over 8
=item * C
Damerau Levenshtein Distance (Levenshtein Distance including transpositions)
Arguments: $source, $target, $max?
I<$max distance. 0 = unlimited. Default = 0>
Returns: int that represents the edit distance between the two argument. Stops calculations and returns Int if max distance is set and reached if possible.
use Text::Levenshtein::Damerau;
say dld('AABBCC','AABCBCD');
# prints 2
# Max edit distance of 1
say dld('AABBCC','AABCBCD',1); # distance is 2
# prints Int
=item * C
Levenshtein Distance (no transpositions)
Arguments: $source, $target, $max?
I<$max distance. 0 = unlimited. Default = 0>
Returns: Int that represents edit distance between the two argument. Stops calculations and returns Int if max distance is set and reached if possible.
use Text::Levenshtein::Damerau;
say ld('AABBCC','AABCBCD');
# prints 3
# Max edit distance of 1
# Uses regular Levenshtein distance (no transpositions)
say ld('AABBCC','AABCBCD',1); # distance is 3
# prints Int
=back
=head2 Methods
=over 8
=item * C
Damerau Levenshtein Distance (Levenshtein Distance including transpositions)
Arguments: \@sources, \@targets, $max?
I<$max distance. 0 = unlimited. Default = 0>
Create a new object. For now, this is so you may call C on it.
=item * C
Generates %results and sets the following attributes:
$.best_distance
$.best_target
$.best_source if @.sources.elems > 1
%.results
# %results{$source}{$target} = $distance_result
Returns: %.results
=back
=head2 Bugs
Please report bugs to:
L
=head2 Author
Nick Logan L
=cut