.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" 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 .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . 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 "Similarity 3pm" .TH Similarity 3pm 2024-03-07 "perl v5.38.2" "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 String::Similarity \- calculate the similarity of two strings .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use String::Similarity; \& \& $similarity = similarity $string1, $string2; \& $similarity = similarity $string1, $string2, $limit; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" .ie n .IP "$factor = similarity $string1, $string2, [$limit]" 4 .el .IP "\f(CW$factor\fR = similarity \f(CW$string1\fR, \f(CW$string2\fR, [$limit]" 4 .IX Item "$factor = similarity $string1, $string2, [$limit]" The \f(CW\*(C`similarity\*(C'\fR\-function calculates the similarity index of its two arguments. A value of \f(CW0\fR means that the strings are entirely different. A value of \f(CW1\fR means that the strings are identical. Everything else lies between 0 and 1 and describes the amount of similarity between the strings. .Sp It roughly works by looking at the smallest number of edits to change one string into the other. .Sp You can add an optional argument \f(CW$limit\fR (default 0) that gives the minimum similarity the two strings must satisfy. \f(CW\*(C`similarity\*(C'\fR stops analyzing the string as soon as the result drops below the given limit, in which case the result will be invalid but lower than the given \&\f(CW$limit\fR. You can use this to speed up the common case of searching for the most similar string from a set by specifying the maximum similarity found so far. .SH "SEE ALSO" .IX Header "SEE ALSO" .Vb 4 \& The basic algorithm is described in: \& "An O(ND) Difference Algorithm and its Variations", Eugene Myers, \& Algorithmica Vol. 1 No. 2, 1986, pp. 251\-266; \& see especially section 4.2, which describes the variation used below. \& \& The basic algorithm was independently discovered as described in: \& "Algorithms for Approximate String Matching", E. Ukkonen, \& Information and Control Vol. 64, 1985, pp. 100\-118. .Ve .SH AUTHOR .IX Header "AUTHOR" .Vb 2 \& Marc Lehmann \& http://home.schmorp.de/ \& \& (the underlying fstrcmp function was taken from gnu diffutils and \& modified by Peter Miller and Marc Lehmann \& ). .Ve