Code covered by the BSD License  

Highlights from
Calculation of distance between strings

from Calculation of distance between strings by Eduard Polityko
A function computes Levenshtein and editor distances with use of Vagner-Fisher algorithm.

Calculation of distance between strings

Calculation of distance between strings

 Function strdist(r,b,krk,cas) is intended for calculation of distance
between strings.It computes Levenshtein and editor distances with use of
Vagner-Fisher algorithm. Levenshtein distance is the minimal quantity of
character substitutions, deletions and insertions for transformation of
string r into string b. An editor distance is computed as Levenstein
distance with substitutions weight of 2.

Contents

DESCRIPTION

d=strdist(r) computes numel(r); d=strdist(r,b) computes Levenshtein distance between r and b. If b is empty string then d=numel(r); d=strdist(r,b,krk) computes both Levenshtein and editor distance when krk=2. d=strdist(r,b,krk,cas) computes a distance in accordance with krk and cas.If cas>0 then case is ignored.

EXAMPLE

d1 - Levenstein distance, d2 - Levenstein and editor distances

d1=strdist('statistics','mathematics')
d2=strdist('statistics','mathematics',2)
d1 =
     6
d2 =
     6     9

How to count substitutions:

disp('Quantity of substitutions:')
disp(diff(d2))
Quantity of substitutions:
     3

Case sensitive:

strdist('MATLAB','MathWorks',2)
ans =
     8    13

Case non-sensitive:

strdist('MATLAB','MathWorks',2,1)
ans =
     6     9

Contact us at files@mathworks.com