我正在遵循Levenshtein距离的代码 https://www.mathworks.com/examples/matlab/community/35304-word-error-rate 该代码将为我提供
这样的用法 [a]= WER('hi there how r u','hello there')
% a[1] = 2 (3 additions 1 substitution, so 4/2)
其中第一个字符串是假设,第二个字符串是参考。
计算距离的代码复制为:
function d=strd(a,b,cas)
% d=strd(r,b,cas) computes Levenshtein and editor distance
% between strings r and b with use of Vagner-Fisher algorithm.
% if CAS == 2 then a case is ignored.
aa=a;
bb=b;
if cas==2
aa=upper(a);
bb=upper(b);
end
luma=numel(bb); lima=numel(aa);
lu1=luma+1; li1=lima+1;
dl=zeros([lu1,li1]);
dl(1,:)=0:lima; dl(:,1)=0:luma;
%Distance
for i=2:lu1
bbi=bb(i-1);
for j=2:li1
kr=1;
if strcmp(aa(j-1),bbi)
kr=0;
end
dl(i,j)=min([dl(i-1,j-1)+kr,dl(i-1,j)+1,dl(i,j-1)+1]);
end
end
d=dl(end,end);
如何修改它以返回实际的替代,删除和添加的数量,所以类似
function [dist addit subst delet] = strd(a,b,cas)
谢谢
赛迪