public static MiMFa_Percent ContentComparePerCent(string str1, string str2) { if (string.IsNullOrEmpty(str1) && string.IsNullOrEmpty(str2)) { return(new MiMFa_Percent(0, 0, 100)); } if (string.IsNullOrEmpty(str1) && !string.IsNullOrEmpty(str2)) { return(new MiMFa_Percent(-100, 0, 0)); } if (!string.IsNullOrEmpty(str1) && string.IsNullOrEmpty(str2)) { return(new MiMFa_Percent(0, -100, 0)); } if (str1 == str2) { return(new MiMFa_Percent(0, 0, 100)); } str1 = str1.Trim().Replace(Environment.NewLine, " ").Replace(" ", " ").Replace(" ", " "); str2 = str2.Trim().Replace(Environment.NewLine, " ").Replace(" ", " ").Replace(" ", " "); if (str1 == str2) { return(new MiMFa_Percent(-1, 0, 99)); } int ct = str1.CompareTo(str2); if (ct == 0) { return(new MiMFa_Percent(-5, 0, 95)); } string str1l = str1.ToLower(); string str2l = str2.ToLower(); if (str1l == str2l) { MiMFa_Percent mm = new MiMFa_Percent(0, 0, 90); decimal fu = Convert.ToDecimal(10) / str1.Length; for (int i = 0; i < str1.Length; i++) { mm.AddValue((str1[i] == str2[i]) ? fu : -fu); } return(mm.Normalization()); } ct = str1l.CompareTo(str2l); if (ct == 0) { return(new MiMFa_Percent(-10, 0, 90)); } MiMFa_Percent percent = ContentSameWordPerCent(str1, str2); percent = percent.Normalization(); return(percent); }
public static MiMFa_Percent LikePerCent(string str1, string str2) { if (string.IsNullOrEmpty(str1) && string.IsNullOrEmpty(str2)) { return(new MiMFa_Percent(0, 0, 100)); } if (string.IsNullOrEmpty(str1) && !string.IsNullOrEmpty(str2)) { return(new MiMFa_Percent(-100, 0, 0)); } if (!string.IsNullOrEmpty(str1) && string.IsNullOrEmpty(str2)) { return(new MiMFa_Percent(0, -100, 0)); } MiMFa_Percent percent; if ((percent = ComparePerCent(str1, str2)).Both > 70) { return(percent); } List <string> lst1 = str1.Split(new string[] { " ", " ", " ", "&", ",", "،", "'", "`", ":", "؛", ";", ".", "?", "؟", "!" }, StringSplitOptions.RemoveEmptyEntries).ToList(); List <string> lst2 = str2.Split(new string[] { " ", " ", " ", "&", ",", "،", "'", "`", ":", "؛", ";", ".", "?", "؟", "!" }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (lst1.Count < 2 && lst2.Count < 2) { return(percent.Normalization()); } if ((lst1.Count >= 2 * lst2.Count) || (lst2.Count >= 2 * lst1.Count)) { return(new MiMFa_Percent(-100, 0, 0)); } decimal unit = Convert.ToDecimal(93) / ((lst2.Count + lst1.Count) / 2); percent = new MiMFa_Percent(-7, 0, 0); MiMFa_Percent newf = new MiMFa_Percent(0, 0, 0); MiMFa_Percent maxf = new MiMFa_Percent(0, 0, 0); int maxindex = -1; for (int i = 0; i < lst1.Count; i++) { maxf = new MiMFa_Percent(0, 0, 0); for (int j = 0; j < lst2.Count; j++) { newf = ComparePerCent(lst1[i], lst2[j]); if (newf > maxf) { maxf.SetValue(newf); maxindex = j; } } if (maxf > 50) { if (maxindex > -1) { lst2.RemoveAt(maxindex); } percent.AddValue((maxf / 100) * unit); } else { percent.AddValue(-unit); } } return(percent.Normalization()); }
public static MiMFa_Percent ComparePerCent(string str1, string str2) { if (string.IsNullOrEmpty(str1) && string.IsNullOrEmpty(str2)) { return(new MiMFa_Percent(0, 0, 100)); } if (string.IsNullOrEmpty(str1) && !string.IsNullOrEmpty(str2)) { return(new MiMFa_Percent(-100, 0, 0)); } if (!string.IsNullOrEmpty(str1) && string.IsNullOrEmpty(str2)) { return(new MiMFa_Percent(0, -100, 0)); } if (str1 == str2) { return(new MiMFa_Percent(0, 0, 100)); } str1 = str1.Trim().Replace(Environment.NewLine, " ").Replace(" ", " ").Replace(" ", " "); str2 = str2.Trim().Replace(Environment.NewLine, " ").Replace(" ", " ").Replace(" ", " "); if (str1 == str2) { return(new MiMFa_Percent(-1, 0, 99)); } int ct = str1.CompareTo(str2); if (ct == 0) { return(new MiMFa_Percent(-5, 0, 95)); } string str1l = str1.ToLower(); string str2l = str2.ToLower(); if (str1l == str2l) { MiMFa_Percent mm = new MiMFa_Percent(0, 0, 90); decimal fu = Convert.ToDecimal(10) / str1.Length; for (int i = 0; i < str1.Length; i++) { mm.AddValue((str1[i] == str2[i]) ? fu : -fu); } return(mm.Normalization()); } ct = str1l.CompareTo(str2l); if (ct == 0) { return(new MiMFa_Percent(-10, 0, 90)); } decimal unit = Convert.ToDecimal(100) / ((str2.Length + str1.Length) / 2); int telor = Math.Abs(str1.Length - str2.Length); decimal tu = telor * unit; if (str1.Contains(str2l) || str2l.Contains(str1)) { return((new MiMFa_Percent(-tu, 0, 100 - tu)).Normalization()); } if (str1l.Contains(str2l) || str2l.Contains(str1l)) { return((new MiMFa_Percent(-10 - tu, 0, 90 - tu)).Normalization()); } if (str1.Length < 2 || str2.Length < 2) { return(new MiMFa_Percent(-100, 0, 0)); } int m1 = str1.Length / 2; int m2 = str2.Length / 2; MiMFa_Percent percent1 = ComparePerCent(str1.Substring(0, m1), str2.Substring(0, m2)) / 2; MiMFa_Percent percent2 = ComparePerCent(str1.Substring(m1), str2.Substring(m2)) / 2; MiMFa_Percent percent = percent1 + percent2; percent.Normalization(); if (percent.Positive > 60) { return(percent); } string s1 = str1, s2 = str2; if (str1.Length < str2.Length) { s1 = str2; s2 = str1; } int j = 0; percent = new MiMFa_Percent(-30, 0, 0); for (int i = 0; i < s2.Length; i++) { if (s1[i] != s2[j++] && s1[i] != s2[(j > 0)?j - 1: 0]) { percent.AddValue(-unit); } else { percent.AddValue(unit); } } percent.AddValue(-tu); percent = percent.Normalization(); return(percent); }
public MiMFa_Percent execute(MiMFa_Percent percent, decimal sensitivity) { percent.Positive += (((100 - sensitivity) / 100) * percent.Positive); percent.Normalization(); return(percent); }