日期:2014-05-17 浏览次数:20900 次
/// <summary> /// 获取两个字符串的相似度 /// </summary> /// <param name=”sourceString”>第一个字符串</param> /// <param name=”str”>第二个字符串</param> /// <returns></returns> public static decimal GetSimilarityWith(this string sourceString, string str) { decimal Kq = 2; decimal Kr = 1; decimal Ks = 1; char[] ss = sourceString.ToCharArray(); char[] st = str.ToCharArray(); //获取交集数量 int q = ss.Intersect(st).Count(); int s = ss.Length – q; int r = st.Length – q; return Kq * q / (Kq * q + Kr * r + Ks * s); }
------解决方案--------------------
C#实现字符串相似度比较[Levenshtein Distance算法]