Пример #1
0
        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);
        }
Пример #2
0
 public override object EXECUTE(params object[] po)
 {
     if (po != null && po.Length > 0)
     {
         MiMFa_Percent percent = new MiMFa_Percent(0, 0, 0);
         percent.Negative = (po.Length > 0)? Convert.ToDecimal(po[0]):0;
         percent.Positive = (po.Length > 1)? Convert.ToDecimal(po[1]):0;
         decimal sens = (po.Length > 2)? Convert.ToDecimal(po[2]):100;
         percent.None = (po.Length > 3)? Convert.ToDecimal(po[3]):0;
         return(execute(percent, sens));
     }
     return(Null);
 }
Пример #3
0
        public static MiMFa_Percent NameLikePerCent(string str1, string str2)
        {
            MiMFa_Percent p = LikePerCent(str1, str2);

            if (p.Positive > 70)
            {
                return(p);
            }
            str1 = MiMFa_Convert.ToSeparatedWordsFast(str1).ToLower();
            str2 = MiMFa_Convert.ToSeparatedWordsFast(str2).ToLower();
            var lst1 = str1.Split(new string[] { "   ", "  ", " ", "&", ",", "،", "'", "`", ":", "؛", ";", ".", "?", "؟", "!" }, StringSplitOptions.RemoveEmptyEntries);
            var lst2 = str2.Split(new string[] { "   ", "  ", " ", "&", ",", "،", "'", "`", ":", "؛", ";", ".", "?", "؟", "!" }, StringSplitOptions.RemoveEmptyEntries);

            p = new MiMFa_Percent();
            decimal f = 100 / Math.Max(lst1.Length, lst2.Length);

            for (int i = 0; i < lst1.Length; i++)
            {
                for (int j = 0; j < lst2.Length; j++)
                {
                    if (lst1[i].Length > lst2[j].Length)
                    {
                        if (lst1[i].StartsWith(lst2[j]))
                        {
                            p.AddValue(f); break;
                        }
                    }
                    else
                    {
                        if (lst2[j].StartsWith(lst1[i]))
                        {
                            p.AddValue(f); break;
                        }
                    }
                }
            }
            return(p);
        }
Пример #4
0
        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());
        }
Пример #5
0
        public static MiMFa_Percent ContentSameWordPerCent(string str1, string str2)
        {
            MiMFa_Percent mp   = new MiMFa_Percent(0, 0, 0);
            MiMFa_Percent nnmp = new MiMFa_Percent(0, 0, 0);

            str1 = (str1 + "").ToUpper();
            str2 = (str2 + "").ToUpper();
            string[]      sa1  = str1.Split(new string[] { "   ", "  ", " ", "&", ",", "،", "'", "`", ":", "؛", ";", ".", "?", "؟", "!" }, StringSplitOptions.RemoveEmptyEntries);
            string[]      sa2  = str2.Split(new string[] { "   ", "  ", " ", "&", ",", "،", "'", "`", ":", "؛", ";", ".", "?", "؟", "!" }, StringSplitOptions.RemoveEmptyEntries);
            int           l    = Math.Abs(sa1.Length - sa2.Length);
            List <string> lmin = new List <string>();
            List <string> lmax = new List <string>();

            if (sa1.Length > sa2.Length)
            {
                lmin = sa2.ToList(); lmax = sa1.ToList();
            }
            else
            {
                lmin = sa1.ToList(); lmax = sa2.ToList();
            }
            if (l == 0)
            {
                mp.AddValue(20, true);
            }
            else if (l == 1)
            {
                mp.AddValue(-50);
            }
            else if ((lmin.Count - l) < 0)
            {
                mp.AddValue(-100);
            }
            else
            {
                mp.AddValue(-50);
            }
            decimal unit = 100 / lmin.Count;

            mp.AddValue(-unit * l);
            for (int i = 0; i < lmin.Count; i++)
            {
                for (int j = 0; j < Math.Min(lmax.Count, lmin.Count); j++)
                {
                    if (lmin[i].Contains(lmax[j]) || lmax[j].Contains(lmin[i]))
                    {
                        if (lmin[i] == lmax[j])
                        {
                            mp.AddValue(unit);
                            lmax.RemoveAt(j);
                            break;
                        }
                        else
                        {
                            if (i == 0 || i >= lmin.Count - 1)
                            {
                                mp.AddValue(-100);
                            }
                            else
                            {
                                mp.AddValue(-unit);
                            }
                            lmax.RemoveAt(j);
                            break;
                        }
                    }
                    else if ((nnmp = ComparePerCent(lmin[i], lmax[j])).Positive > 60)
                    {
                        mp.AddValue(nnmp.Positive * unit / 100);
                    }
                    else if (i >= lmin.Count - 1)
                    {
                        mp.AddValue(-1 * unit);
                    }
                }
            }
            if (mp.Negative < -1 * unit && mp.Positive >= 100)
            {
                mp.AddValue(-100);
            }
            return(mp);
        }
Пример #6
0
        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);
        }
Пример #7
0
 public MiMFa_Percent execute(MiMFa_Percent percent, decimal sensitivity)
 {
     percent.Positive += (((100 - sensitivity) / 100) * percent.Positive);
     percent.Normalization();
     return(percent);
 }