.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "WagnerFischer 3pm" .TH WagnerFischer 3pm "2021-01-01" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Text::WagnerFischer \- An implementation of the Wagner\-Fischer edit distance .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Text::WagnerFischer qw(distance); \& \& print distance("foo","four");# prints "2" \& \& print distance([0,1,2],"foo","four");# prints "3" \& \& \& my @words=("four","foo","bar"); \& \& my @distances=distance("foo",@words); \& print "@distances"; # prints "2 0 3" \& \& @distances=distance([0,2,1],"foo",@words); \& print "@distances"; # prints "3 0 3" .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module implements the Wagner-Fischer dynamic programming technique, used here to calculate the edit distance of two strings. The edit distance is a measure of the degree of proximity between two strings, based on \*(L"edits\*(R": the operations of substitutions, deletions or insertions needed to transform the string into the other one (and vice versa). A cost (weight) is needed for every of the operation defined above: .PP .Vb 3 \& / a if x=y (cost for letter match) \& w(x,y) = | b if x=\- or y=\- (cost for insertion/deletion operation) \& \e c if x!=y (cost for letter mismatch) .Ve .PP These costs are given through an array reference as first argument of the distance subroutine: [a,b,c]. If the costs are not given, a default array cost is used: [0,1,1] that is the case of the Levenshtein edit distance: .PP .Vb 3 \& / 0 if x=y (cost for letter match) \& w(x,y) = | 1 if x=\- or y=\- (cost for insertion/deletion operation) \& \e 1 if x!=y (cost for letter mismatch) .Ve .PP This particular distance is the exact number of edit needed to transform the string into the other one (and vice versa). When two strings have distance 0, they are the same. Note that the distance is calculated to reach the _minimum_ cost, i.e. choosing the most economic operation for each edit. .SH "EXTENDING (by Daniel Yacob)" .IX Header "EXTENDING (by Daniel Yacob)" New modules may build upon Text::WagnerFischer as a base class. This is practical when you would like to apply the algorithm to non-Roman character sets or would like to change some part of the algorithm but not another. .PP The following example demonstrates how to use the WagnerFisher distance algorithm but apply your own weight function in a new package: .PP .Vb 2 \& package Text::WagnerFischer::MyModule; \& use base qw( Text::WagnerFischer ); \& \& # \& # Link to the WagnerFisher "distance" function so that the \& # new module may also export it: \& # \& use vars qw(@EXPORT_OK); \& \& @EXPORT_OK = qw(&distance); \& \& *distance = \e&Text::WagnerFischer::distance; \& \& # \& # "override" the _weight function with the a one: \& # \& *Text::WagnerFischer::_weight = \e&_my_weight; \& \& # \& # "override" the default WagnerFischer "costs" table: \& # \& $Text::WagnerFischer::REFC = [0,2,3,1,1]; \& \& sub _my_weight { \& : \& : \& : \& } .Ve .SH "AUTHOR" .IX Header "AUTHOR" Copyright 2002,2003 Dree Mistrut <\fIdree@friul.it\fR> .PP This package is free software and is provided \*(L"as is\*(R" without express or implied warranty. You can redistribute it and/or modify it under the same terms as Perl itself. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\f(CW\*(C`Text::Levenshtein\*(C'\fR, \f(CW\*(C`Text::PhraseDistance\*(C'\fR