1 ## Copyright (C) 2006 Muthiah Annamalai <muthiah.annamalai@uta.edu>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {[@var{dist},@var{L}] =} editdistance (@var{string1}, @var{string2}, @var{weights})
18 ## Compute the Levenshtein edit distance between the strings @var{string1} and
19 ## @var{string2}. This operation is symmetrical.
21 ## The optional argument @var{weights} specifies weights for the
22 ## deletion, matched, and insertion operations; by default it is set to
23 ## +1, 0, +1 respectively, so that a least editdistance means a
24 ## closer match between the two strings. This function implements
25 ## the Levenshtein edit distance as presented in Wikipedia article,
26 ## accessed Nov 2006. Also the levenshtein edit distance of a string
27 ## with an empty string is defined to be its length.
29 ## The default return value is @var{dist} the edit distance, and
30 ## the other return value @var{L} is the distance matrix.
34 ## editdistance('marry','marie')
35 ## ##returns value +2 for the distance.
41 function [dist, L] = editdistance (str1, str2, weights)
42 if(nargin < 2 || (nargin == 3 && length(weights) < 3) )
66 if(str1(idx-1)==str2(idy-1))
71 m1=L(idx-1,idy-1) + score;
74 L(idx,idy)=min(m1,min(m2,m3));