コード例 #1
0
        static void Main(string[] args)
        {
            //(Date of Birth, 'DDMMYYYY') || SexID || FirstName || Surname
            var student1dob     = "30122000";
            var student1sexid   = "01";
            var student1fname   = "BOB";
            var student1surname = "SMITH";
            var student1        = student1dob + student1sexid + Soundex.Generate(student1fname) + Soundex.Generate(student1surname);

            var student2dob     = "30122000";
            var student2sexid   = "01";
            var student2fname   = "BOB";
            var student2surname = "SMYTH";
            var student2        = student2dob + student2sexid + Soundex.Generate(student2fname) + Soundex.Generate(student2surname);

            if (student1 == student2)
            {
                Console.WriteLine(student1);
                Console.WriteLine(student2);
                Console.WriteLine("Looks like a match");
            }
            else
            {
                Console.WriteLine("Looks like students are different.");
            }
            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // Initialization
            Trie words = new Trie();
            Dictionary <string, List <string> > soundexWords = new Dictionary <string, List <string> >();

            string[] lines = File.ReadAllLines("words_alpha.txt");

            for (int i = 0; i < lines.Length; i++)
            {
                string soundex = Soundex.StringToSoundex(lines[i]);

                if (!soundexWords.ContainsKey(soundex))
                {
                    soundexWords.Add(soundex, new List <string>());
                }

                soundexWords[soundex].Add(lines[i]);

                words.Insert(lines[i]);
            }

            // Look into https://en.wikipedia.org/wiki/Edit_distance
            // and https://en.wikipedia.org/wiki/Levenshtein_distance

            // The actual thing
            while (true)
            {
                Console.WriteLine("Gib word: ");
                string input   = Console.ReadLine().ToLower();
                string soundex = Soundex.StringToSoundex(input);

                Console.WriteLine("Matches: ");
                List <string> matches = words.GetAllMatchingWords(input);

                for (int i = 0; i < matches.Count; i++)
                {
                    Console.WriteLine(matches[i]);
                }

                Console.WriteLine("Similar: ");
                if (soundexWords.ContainsKey(soundex))
                {
                    List <string> similar = soundexWords[soundex];

                    for (int i = 0; i < similar.Count; i++)
                    {
                        Console.WriteLine(similar[i]);
                    }
                }
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: shaair/Soundex
 static void Main(string[] args)
 {
     while (true)
     {
         Console.WriteLine("Enter a name: ");
         string entered = Console.ReadLine();
         if (String.IsNullOrEmpty(entered))
         {
             break;
         }
         else
         {
             Console.WriteLine("Soundex: " + Soundex.GetSoundex(entered));
             Console.WriteLine("NYSIIS: " + NYSoundex.GetSoundex(entered));
             Console.WriteLine("**********");
         }
     }
 }