Example #1
0
        private EditDistance.ngram_similarity getNgramEditDistance(JToken f1, JToken f2, int n)
        {
            List <string> mnemonics1 = this.toStringList(f1["mnemonics"].ToList());
            List <string> mnemonics2 = this.toStringList(f2["mnemonics"].ToList());

            int min = Math.Min(mnemonics1.Count(), mnemonics2.Count());

            if (mnemonics1.Count() > min)
            {
                mnemonics1.RemoveRange(min, mnemonics1.Count() - min);
            }
            if (mnemonics2.Count() > min)
            {
                mnemonics2.RemoveRange(min, mnemonics2.Count() - min);
            }
            if (min < n)
            {
                n = min;
            }

            EditDistance ed = new EditDistance();

            ed.ngramset_edit_distance(mnemonics1, mnemonics2, n);

            return(ed.similarity);
        }
Example #2
0
        static void Main(string[] args)
        {
            string s1 = "intention";
            string s2 = "execution";

            EditDistance ed = new EditDistance();

            int num = ed.editDistance(s1, s2);

            Console.WriteLine(num);
            Console.ReadKey();
        }
Example #3
0
        private EditDistance.ngram_similarity getNgramEditDistance(JToken f1, JToken f2, int n)
        {
            timer.Reset();
            timer.Start();
            List <string> mnemonics1 = this.toStringList(f1["mnemonics"].ToList());
            List <string> mnemonics2 = this.toStringList(f2["mnemonics"].ToList());

            int min = Math.Min(mnemonics1.Count(), mnemonics2.Count());

            if (mnemonics1.Count() > min)
            {
                mnemonics1.RemoveRange(min, mnemonics1.Count() - min);
            }
            if (mnemonics2.Count() > min)
            {
                mnemonics2.RemoveRange(min, mnemonics2.Count() - min);
            }
            if (min < n)
            {
                n = min;
            }

            /*
             * int count1 = mnemonics1.Count();
             * int count2 = mnemonics2.Count();
             * int max = Math.Max(count1, count2);
             * if (mnemonics1.Count() < max)
             *  for (int i = 0; i < max - count1; i++)
             *      mnemonics1.Add("");
             * if (mnemonics2.Count() < max)
             *  for (int i = 0; i < max - count2; i++)
             *      mnemonics2.Add("");
             * if (max < n)
             *  n = max;
             */

            EditDistance ed = new EditDistance();

            ed.ngramset_edit_distance(mnemonics1, mnemonics2, n);
            timer.Stop();

            return(ed.similarity);
        }