Esempio n. 1
0
        static void Main(string[] args)
        {
            JaroCalculator calc = JaroCalculator.New();

            string s = @"Quick brown fox jumps over a lazy dog";
            string t = @"Quick brown fox jumps over a lazy dog";

            Console.WriteLine("'{0}' <-> '{1}' = {2}", s, t, calc.Calculate(s, t).ToString("0.00000"));

            t = @"Quick brown fox jumps over a lazy fog";
            Console.WriteLine("'{0}' <-> '{1}' = {2}", s, t, calc.Calculate(s, t).ToString("0.00000"));

            t = @"Quick brown fox jumps over a quick dog";
            Console.WriteLine("'{0}' <-> '{1}' = {2}", s, t, calc.Calculate(s, t).ToString("0.00000"));

            t = @"Mammy, where you go, it's just a dream";
            Console.WriteLine("'{0}' <-> '{1}' = {2}", s, t, calc.Calculate(s, t).ToString("0.00000"));

            s = @"Abcdefgi";
            t = @"Rstuwxyz";
            Console.WriteLine("'{0}' <-> '{1}' = {2}", s, t, calc.Calculate(s, t).ToString("0.00000"));

            Console.Write(">>> PRESS ENTER");
            Console.ReadLine();
        }
Esempio n. 2
0
        public static JaroCalculator New()
        {
            JaroCalculator c = new JaroCalculator();

            c.ss     = new char[JaroCalculator.MaxWordSize];
            c.tt     = new char[JaroCalculator.MaxWordSize];
            c.ssp    = 0;
            c.ttp    = 0;
            c.matrix = new Mask64Bit[JaroCalculator.MaxWordSize];
            return(c);
        }
Esempio n. 3
0
        public static string[] SplitAndNormalize(string s)
        {
            if (s == null)
            {
                JaroCalculator.mapping = new KeyValueCollection <char, char>(128, 32, JaroCalculator.Compare);
                JaroCalculator.AddMapping(
                    @"харос",
                    @"xapoc");
                return(null);
            }
            char[]        buf = new char[JaroCalculator.MaxWordSize];
            int           p   = 0;
            List <string> l   = new List <string>();

            for (int i = 0; i < s.Length; i++)
            {
                char c = s[i];
                if (Char.IsLetter(c))
                {
                    if (p >= JaroCalculator.MaxWordSize)
                    {
                        continue;
                    }
                    c = Char.ToLower(c);
                    if (JaroCalculator.mapping.ContainsKey(c))
                    {
                        c = JaroCalculator.mapping[c];
                    }
                    buf[p++] = c;
                    continue;
                }
                switch (c)
                {
                case '\'':
                case '`':
                    if (p < JaroCalculator.MaxWordSize)
                    {
                        buf[p++] = '\'';
                    }
                    break;

                case '-':
                    if (p < JaroCalculator.MaxWordSize)
                    {
                        buf[p++] = '-';
                    }
                    break;

                default:
                    if (p > 0)
                    {
                        l.Add(new String(buf, 0, p));
                        p = 0;
                    }
                    break;
                }
            }
            if (p > 0)
            {
                l.Add(new String(buf, 0, p));
            }
            buf = null;
            if (l.Count == 0)
            {
                return(null);
            }
            return(l.ToArray());
        }