.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" 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 "Text::Brew 3pm" .TH Text::Brew 3pm "2022-10-13" "perl v5.34.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::Brew \- An implementation of the Brew edit distance .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Text::Brew qw(distance); \& \& my ($distance,$arrayref_edits)=distance("four","foo"); \& my $sequence=join",",@$arrayref_edits; \& print "The Brew distance for (four,foo) is $distance\en"; \& print "obtained with the edits: $sequence\en\en"; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module implements the Brew edit distance that is very close to the dynamic programming technique used for the Wagner-Fischer (and so for the Levenshtein) edit distance. Please look at the module references below. For more information about the Brew edit distance see: .PP The difference here is that you have separated costs for the DELetion and INSertion operations (but with the default to 1 for both, you obtain the Levenshtein edit distance). But the most interesting feature is that you can obtain the description of the edits needed to transform the first string into the second one (not vice versa: here DELetions are separated from INSertions). The difference from the original algorithm by Chris Brew is that I have added the \s-1SUBST\s0 operation, making it different from \s-1MATCH\s0 operation. .PP The symbols used here are: .PP .Vb 5 \& INITIAL that is the INITIAL operation (i.e. NO operation) \& MATCH that is the MATCH operation (0 is the default cost) \& SUBST that is the SUBSTitution operation (1 is the default cost) \& DEL that is the DELetion operation (1 is the default cost) \& INS that is the INSertion operation (1 is the default cost) .Ve .PP and you can change the default costs (see below). .PP You can make \s-1INS\s0 and \s-1DEL\s0 the same operation in a simple way: .PP .Vb 3 \& 1) give both the same cost \& 2) change the output string DEL to INS/DEL (o whatever) \& 3) change the output string INS to INS/DEL (o whatever) .Ve .SS "\s-1USAGE\s0" .IX Subsection "USAGE" .Vb 2 \& use strict; \& use Text::Brew qw(distance); \& \& my ($distance,$arrayref_edits)=distance("four","foo"); \& my $sequence=join",",@$arrayref_edits; \& print "The Brew distance for (four,foo) is $distance\en"; \& print "obtained with the edits: $sequence\en\en"; \& \& my $string1="foo"; \& my @strings=("four","foo","bar"); \& my (@dist,@edits); \& foreach my $string2 (@strings) { \& my ($dist,$edits)=distance($string1,$string2); \& push @dist,$dist; \& push @edits,(join ",",@$edits); \& } \& foreach my $i (0 .. $#strings) { \& \& print "The Brew distance for ($string1,$strings[$i]) is $dist[$i]\en"; \& print "obtained with the edits: $edits[$i]\en\en"; \& } .Ve .SS "\s-1OPTIONAL PARAMETERS\s0" .IX Subsection "OPTIONAL PARAMETERS" .Vb 1 \& distance($string1,$string2,{\-cost=>[0,2,1,1],\-output=>\*(Aqedits\*(Aq}); \& \& \-output \& accepted values are: \& distance means that the distance returns \& only the numeric distance \& \& both the distance returns both the \& numeric distance and the array of the edits \& \& edits means that the distance returns only the \& array of the edits \& \& Default output is \*(Aqboth\*(Aq. \& \& \-cost \& accepted value is an array with 4 elements: \& 1st is the cost for the MATCH \& 2nd is the cost for the INS (INSertion) \& 3rd is the cost for the DEL (DELetion) \& 4th is the cost for the SUBST (SUBSTitution) \& \& Default array is [0,1,1,1] . \& \& Examples are: \& \& my $distance=distance("four","foo",{\-output=>\*(Aqdistance\*(Aq}); \& print "The Brew distance for (four,foo) is $distance\en\en"; \& \& \& my $arrayref_edits=distance("four","foo",{\-output=>\*(Aqedits\*(Aq}); \& my $sequence=join",",@$arrayref_edits; \& print "The Brew sequence for (four,foo) is $sequence\en\en"; \& \& \& my ($distance,$arrayref_edits)=distance("four","foo",{\-cost=>[0,2,1,1]}); \& my $sequence=join",",@$arrayref_edits; \& print "The Brew distance for (four,foo) is $distance\en"; \& print "obtained with the edits: $sequence\en\en"; \& \& ($distance,$arrayref_edits)=distance("foo","four",{\-cost=>[0,2,1,1]}); \& $sequence=join",",@$arrayref_edits; \& print "The Brew distance for (foo,four) is $distance\en"; \& print "obtained with the edits: $sequence\en\en"; .Ve .SH "CREDITS" .IX Header "CREDITS" All the credits goes to Chris Brew the author of the algorithm. .SH "THANKS" .IX Header "THANKS" Many thanks to Stefano L. Rodighiero <\fIlarsen at perlmonk.org\fR> for the suggestions. .SH "AUTHOR" .IX Header "AUTHOR" Copyright 2003 Dree Mistrut <\fIdree@friuli.to\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::WagnerFischer\*(C'\fR