private static void TestSimScore(string srcStr, string tarStr)
        {
            double score = GetScore(srcStr, tarStr);
            int    cost  = EditDistance.GetEditDistance(srcStr, tarStr, 96, 90, 100, 94, 10, false);

            Console.WriteLine(srcStr + "|" + tarStr + "|" + cost + "|" + score);
        }
Example #2
0
        private static void TestEdSimScore(string srcStr, string tarStr)
        {
            double score   = GetScore(srcStr, tarStr);
            int    cost    = EditDistance.GetEditDistance(srcStr, tarStr, 96, 90, 100, 94, 10, false);
            int    penalty = OrthographicUtil.GetSplitPenalty(srcStr, tarStr, 90);

            Console.WriteLine(srcStr + "|" + tarStr + "|" + cost + "|" + penalty + "|" + score);
        }
Example #3
0
        public static double GetScore(string srcStr, string tarStr, int deleteCost, int insertCost, int replaceCost, int swapCost, int caseChangeCost, bool enhancedFlag, int splitCost)
        {
            int    cost    = EditDistance.GetEditDistance(srcStr, tarStr, deleteCost, insertCost, replaceCost, swapCost, caseChangeCost, enhancedFlag);
            int    penalty = OrthographicUtil.GetSplitPenalty(srcStr, tarStr, splitCost);
            double score   = OrthographicUtil.GetNormScore(cost + penalty, 1000.0);

            return(score);
        }
        public static int GetDistance(string str1, string str2)
        {
            string str1Lc   = str1.ToLower();
            string str2Lc   = str2.ToLower();
            string str1Code = GetCode(str1Lc);
            string str2Code = GetCode(str2Lc);
            int    dist     = EditDistance.GetEditDistance(str1Code, str2Code);

            return(dist);
        }
        public static string GetDistanceDetailStr(string str1, string str2)
        {
            string str1Lc    = str1.ToLower();
            string str2Lc    = str2.ToLower();
            string str1Code  = GetCode(str1Lc);
            string str2Code  = GetCode(str2Lc);
            int    dist      = EditDistance.GetEditDistance(str1Code, str2Code);
            string detailStr = str1Code + GlobalVars.FS_STR + str2Code + GlobalVars.FS_STR + dist;

            return(detailStr);
        }
Example #6
0
        private static void TestPhoneticDistance(string srcStr, string tarStr)
        {
            int    edDist        = EditDistance.GetEditDistance(srcStr, tarStr, 95, 95, 100, 90, 10, false);
            int    pDist         = GetDistance(srcStr, tarStr);
            int    maxCodeLength = 10;
            string srcStrLc      = srcStr.ToLower();
            string tarStrLc      = tarStr.ToLower();
            //String srcM2 = Metaphone2.GetCode(srcStrLc, maxCodeLength);
            //String tarM2 = Metaphone2.GetCode(tarStrLc, maxCodeLength);
            string srcM2 = RefinedSoundex.GetCode(srcStrLc);
            string tarM2 = RefinedSoundex.GetCode(tarStrLc);

            Console.WriteLine(srcStr + "|" + tarStr + "|" + edDist + "|" + srcM2 + "|" + tarM2 + "|" + pDist);
        }
        // TBD: read the values from config file
        public static double GetScore(string srcStr, string tarStr)
        {
            /// <summary>
            /// init value form ensemble
            /// int deleteCost = 95;
            /// int insertCost = 95;
            /// int replaceCost = 100;
            /// int swapCost = 90;
            ///
            /// </summary>
            // new value
            int  deleteCost     = 100;
            int  insertCost     = 100;
            int  replaceCost    = 100;
            int  swapCost       = 100;
            int  caseChangeCost = 10;
            bool enhancedFlag   = false;
            int  splitCost      = insertCost;
            int  maxCodeLength  = 10;
            /// <summary>
            /// Test on different phonetic methods
            /// String srcM2 = Metaphone2.GetCode(srcStr, maxCodeLength);
            /// String tarM2 = Metaphone2.GetCode(tarStr, maxCodeLength);
            /// String srcM2 = RefinedSoundex.GetCode(srcStr);
            /// String tarM2 = RefinedSoundex.GetCode(tarStr);
            /// String srcM2 = Caverphone2.GetCaverphone(srcStr);
            /// String tarM2 = Caverphone2.GetCaverphone(tarStr);
            /// String srcM2 = Metaphone.GetMetaphone(srcStr, maxCodeLength);
            /// String tarM2 = Metaphone.GetMetaphone(tarStr, maxCodeLength);
            /// Metaphone3 m3 = new Metaphone3();
            /// m3.SetKeyLength(maxCodeLength);
            /// String srcM2 = m3.GetMetaphone(srcStr);
            /// String tarM2 = m3.GetMetaphone(tarStr);
            ///
            /// </summary>
            string srcM2   = Metaphone2.GetCode(srcStr, maxCodeLength);
            string tarM2   = Metaphone2.GetCode(tarStr, maxCodeLength);
            int    cost    = EditDistance.GetEditDistance(srcM2, tarM2, deleteCost, insertCost, replaceCost, swapCost, caseChangeCost, enhancedFlag);
            int    penalty = OrthographicUtil.GetSplitPenalty(srcStr, tarStr, splitCost);
            double score   = OrthographicUtil.GetNormScore(cost + penalty, 1000.0);

            return(score);
        }
Example #8
0
        public static int GetDistance(string srcStr, string tarStr)
        {
            int    deleteCost     = 1;
            int    insertCost     = 1;
            int    replaceCost    = 1;       // penity on the replace
            int    swapCost       = 1;
            int    caseChangeCost = 0;
            bool   enhancedFlag   = false;
            int    splitCost      = insertCost;
            int    maxCodeLength  = 10;
            string srcStrLc       = srcStr.ToLower();
            string tarStrLc       = tarStr.ToLower();
            //String srcM2 = Metaphone2.GetCode(srcStrLc, maxCodeLength);
            //String tarM2 = Metaphone2.GetCode(tarStrLc, maxCodeLength);
            string srcM2 = RefinedSoundex.GetCode(srcStrLc);
            string tarM2 = RefinedSoundex.GetCode(tarStrLc);
            int    dist  = EditDistance.GetEditDistance(srcM2, tarM2, deleteCost, insertCost, replaceCost, swapCost, caseChangeCost, enhancedFlag);

            return(dist);
        }