Esempio n. 1
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);
        }
Esempio n. 2
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);
        }