Exemplo n.º 1
0
        public void SoundexTest()
        {
            string s1 = Soundex.For("Jansen");
            string s2 = Soundex.For("Jenssen");

            Assert.AreEqual(s1, s2);
        }
Exemplo n.º 2
0
        public static int SoundExComparision(Person person)
        {
            string[] Words = new[] { "Spotify", "amal", "Sputfy", "Sputfi" };

            int val = 0;

            //MatchRatingApproach _generator = new MatchRatingApproach();
            //Console.WriteLine(_generator.IsSimilar(Words));

            if (Soundex.For(person.FirstName) == Soundex.For(fName))
            {
                val = val + 1;
            }


            if (Soundex.For(person.LastName) == Soundex.For(LName))
            {
                val = val + 1;
            }
            else
            {
                val = val + 0;
            }
            return(val);
        }
Exemplo n.º 3
0
        private static string GetSoundexCode(string text)
        {
            if (text == null)
            {
                return(null);
            }

            return(Soundex.GetCode(text));
        }
Exemplo n.º 4
0
        private static bool SoundsLike(string left, string right)
        {
            if (left == null || right == null)
            {
                return(false);
            }

            return(Soundex.GetCode(left) == Soundex.GetCode(right));
        }
Exemplo n.º 5
0
 private bool checkForWord(string word)
 {
     while (true)
     {
         if (rawWords.Any(x => Soundex.Generate(word) == Soundex.Generate(x.Word)))
         {
             return(true);
         }
     }
 }
Exemplo n.º 6
0
 private bool checkForCommand(string word, int applicationId)
 {
     while (true)
     {
         if (processedWords.Any(x => Soundex.Generate(word) == Soundex.Generate(x.Word) && x.WordType == VoiceWord.wordType.ApplicationCommand && x.ApplicationIdCommand == applicationId))
         {
             return(true);
         }
     }
 }
Exemplo n.º 7
0
        private void cmdSoundex2_Click(object sender, EventArgs e)
        {
            var msg = Soundex.Encode(txtSecondText.Text.Trim());

            MessageBox.Show(msg);
            var phonetic = new PhoneticMatch();
            var pMsg     = phonetic.CreateToken(txtSecondText.Text.Trim());

            MessageBox.Show(pMsg);
        }
Exemplo n.º 8
0
 public bool wordWasSaid(string word)
 {
     if (rawWords.Any(x => Soundex.Generate(word) == Soundex.Generate(x.Word)))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 9
0
 public bool commandWasSaid(string command, int applicationId)
 {
     if (processedWords.Any(x => Soundex.Generate(command) == Soundex.Generate(x.Word) && x.WordType == VoiceWord.wordType.ApplicationCommand && x.ApplicationIdCommand == applicationId))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 10
0
 public override bool IncrementToken()
 {
     if (input.IncrementToken())
     {
         string currentTerm = _termAttr.Term;
         // Any phonetic hash calculation will work here.
         var hash = Soundex.For(currentTerm);
         _termAttr.SetTermBuffer(hash);
         return(true);
     }
     return(false);
 }
Exemplo n.º 11
0
        private List <VoiceWord> getCommandMessage(string word, int applicationId)
        {
            var command = processedWords.Where(x => Soundex.Generate(word) == Soundex.Generate(x.Word) && x.WordType == VoiceWord.wordType.ApplicationCommand && x.ApplicationIdCommand == applicationId).FirstOrDefault();

            if (command != null)
            {
                var message = rawWords.Where(x => x.MessageId == command.MessageId).ToList();
                return(message);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 12
0
        private List <VoiceWord> getWordMessage(string word, int applicationId)
        {
            var requestedWord = rawWords.Where(x => Soundex.Generate(word) == Soundex.Generate(x.Word)).FirstOrDefault();

            if (requestedWord != null)
            {
                var message = rawWords.Where(x => x.MessageId == requestedWord.MessageId).ToList();
                return(message);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 13
0
    public static SqlString LongPhonetic(SqlInt16 PhoneticType, SqlString InputString)
    {
        BasePhonetics PhoneticObject;

        string _inputString;

        if (InputString.IsNull || InputString.Value.Trim() == String.Empty)
        {
            _inputString = " ";
        }
        else
        {
            _inputString = InputString.Value;
        }

        switch (PhoneticType.Value)
        {
        case 0:
            PhoneticObject = new Soundex(_inputString);
            break;

        case 1:
            PhoneticObject = new RefinedSoundex(_inputString);
            break;

        case 2:
            PhoneticObject = new NYSIIS(_inputString);
            break;

        case 3:
            PhoneticObject = new DaitchMokotoff(_inputString);
            break;

        case 4:
            PhoneticObject = new Metaphone(_inputString);
            break;

        case 6:
            PhoneticObject = new ColognePhonetic(_inputString);
            break;

        default:
            PhoneticObject = new Soundex(_inputString);
            PhoneticType   = 0;
            break;
        }
        PhoneticObject.Iterate();
        return(PhoneticObject.ReadOutput());
    }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            Soundex snd   = new Soundex("Riya");
            Soundex snd1  = new Soundex("Ria");
            Soundex snd2  = new Soundex("Rajeev");
            Soundex snd3  = new Soundex("Rajiv");
            Soundex snd6  = new Soundex("Pascal");
            Soundex snd7  = new Soundex("Pascul");
            Soundex snd8  = new Soundex("Sanket");
            Soundex snd9  = new Soundex("Sunket");
            Soundex snd10 = new Soundex("Sankat");


            Console.WriteLine("Soundex For Riya :" + snd.IN_Soundex + " Soundex For Ria :" + snd1.IN_Soundex);        //Matches
            Console.WriteLine("Soundex For Rajeev :" + snd2.IN_Soundex + " Soundex For Rajivv :" + snd3.IN_Soundex);  //Matches
            Console.WriteLine("Soundex For Pascal :" + snd6.IN_Soundex + " Soundex For Pascul :" + snd7.IN_Soundex);  //Matches
            Console.WriteLine("Soundex For Sanket :" + snd8.IN_Soundex + " Soundex For Sunket :" + snd9.IN_Soundex);  //Matches
            Console.WriteLine("Soundex For Sanket :" + snd8.IN_Soundex + " Soundex For Sunkat :" + snd10.IN_Soundex); //Doesn't Match

            Console.WriteLine("");

            while (true)
            {
                Console.WriteLine("Insert Name To calulate Soundex: ");
                string name = "";
                name = Console.ReadLine();
                if (String.IsNullOrEmpty(name.Trim()) || name.Trim() == "13")
                {
                    Console.WriteLine("Insert Some Text To calulate Soundex: ");
                    name = Console.ReadLine();
                }
                else
                {
                    Soundex result = new Soundex(name);
                    Console.WriteLine("Soundex For The text \" " + name + "  \": " + result.IN_Soundex);
                    string cont = "";
                    Console.WriteLine("Do you want to continue... Press Y/y to countinue: ");

                    cont = Console.ReadLine();
                    if (cont.ToUpper().Trim() != "Y")
                    {
                        break;
                    }
                }
            }
            Console.WriteLine("Press any key to exit....");
            Console.ReadKey();
        }
Exemplo n.º 15
0
        public void ForTests()
        {
            Soundex soundex = new Soundex();
            string  word, expected, actual;

            word     = "";
            expected = "0000";
            actual   = soundex.For(word);
            Assert.AreEqual(expected, actual);

            word     = null;
            expected = "0000";
            actual   = soundex.For(word);
            Assert.AreEqual(expected, actual);

            word     = "Robert";
            expected = "R163";
            actual   = soundex.For(word);
            Assert.AreEqual(expected, actual);

            word   = "Rupert".ToLower();
            actual = soundex.For(word);
            Assert.AreEqual(expected, actual);

            word     = "Rubin";
            expected = "R150";
            actual   = soundex.For(word);
            Assert.AreEqual(expected, actual);

            word     = "Ashcraft";
            expected = "A261";
            actual   = soundex.For(word);
            Assert.AreEqual(expected, actual);

            word   = "Ashcroft";
            actual = soundex.For(word);
            Assert.AreEqual(expected, actual);

            word     = "Tymczak";
            expected = "T522";
            actual   = soundex.For(word);
            Assert.AreEqual(expected, actual);

            word     = "Pfister";
            expected = "P236";
            actual   = soundex.For(word);
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 16
0
        public CheakSpell()
        {
            try
            {
                _globalDic      = new List <string>();
                _userDic        = new List <string>();
                _ignoreList     = new List <string>();
                _stopWordList   = new List <string>();
                _ignoreCharList = new List <char>();

                var persianWordFrequencyOpration = new PS_PersianWordFrequencyOpration(); //load from DB


                var listParsianWordfreq = persianWordFrequencyOpration.GetAll();
                _sundex = new Soundex(listParsianWordfreq.Where(x => x.Sundex.Length > 0).ToList());
                _norvan = new NorvigSpellChecker(listParsianWordfreq);
                _stemmr = new Stemmer(listParsianWordfreq);
                foreach (var item in listParsianWordfreq)
                {
                    _globalDic.Add(item.Val1.Trim());
                }


                var lsStop = new PS_StopWordOpration();


                foreach (var item in lsStop.GetAll())
                {
                    _stopWordList.Add(item.Val1.Trim());
                }

                var userDicOpration = new UserDicOpration();
                _userDic = userDicOpration.LoadAll();
            }
            catch (Exception)
            {
                // ignored
            }
        }
Exemplo n.º 17
0
        private bool compareWords(WordGuess firstWordGuess, WordGuess secondWordGuess)
        {
            var firstWordModel = new WordModel
            {
                Word = firstWordGuess.Word.ToLower().Trim()
            };

            var secondWordModel = new WordModel
            {
                Word = secondWordGuess.Word.ToLower().Trim()
            };


            var stringArray = new string[] { firstWordModel.Word, secondWordModel.Word };

            var metaphone        = new Metaphone();
            var soundex          = new Soundex();
            var similarMetaphone = metaphone.IsSimilar(stringArray);
            var similarSoundex   = soundex.IsSimilar(stringArray);

            return(similarMetaphone || similarSoundex);
        }
Exemplo n.º 18
0
        public static bool MISTpassed(
            string question,
            bool answer,
            string server_name,
            string database_name,
            string user_name,
            string password,
            string table_name)
        {
            bool passed = false;

            int hash = GetHashCode(question);

            if ((server_name == "") ||
                (server_name == null))
            {
                server_name = "localhost";
            }

            string connection_str =
                "server=" + server_name + ";"
                + "database=" + database_name + ";"
                + "uid=" + user_name + ";"
                + "password="******";";

            string Query = "SELECT * FROM " + table_name + " WHERE Hash = " + hash.ToString() + ";";

            int       YesVotes    = 0;
            int       NoVotes     = 0;
            Guid      best_result = Guid.Empty;
            ArrayList pixels      = RunMySqlCommand(Query, connection_str, 5);

            if (pixels.Count > 0)
            {
                char[] template  = Soundex.ToSoundexCode(question).ToCharArray();
                int    max_score = -1;
                // update existing pixel
                for (int ctr = 0; ctr < pixels.Count; ctr++)
                {
                    ArrayList row             = (ArrayList)pixels[ctr];
                    string    result_question = (string)row[2];
                    char[]    s     = Soundex.ToSoundexCode(result_question).ToCharArray();
                    int       score = 0;
                    for (int i = 0; i < s.Length; i++)
                    {
                        score += Math.Abs((int)s[i] - (int)template[i]);
                    }
                    if (score > max_score)
                    {
                        best_result = (Guid)row[0];
                        max_score   = score;
                        YesVotes    = Convert.ToInt32(row[3]);
                        NoVotes     = Convert.ToInt32(row[4]);
                    }
                }

                if (best_result != Guid.Empty)
                {
                    // update the mindpixel coherence
                    float coherence = YesVotes / (float)(YesVotes + NoVotes);
                    if ((answer == true) && (coherence >= 0.5))
                    {
                        passed = true;
                    }
                    if ((answer == false) && (coherence < 0.5))
                    {
                        passed = true;
                    }
                }
            }
            return(passed);
        }
Exemplo n.º 19
0
 public void CombinesDuplicateEncodingsSeparatedByHOrW()
 {
     Assert.AreEqual("J100", Soundex.EncodeToSoundex("Jbwb"));
 }
Exemplo n.º 20
0
 public void CombinesDuplicateCodesWhen2ndLetterDuplicates1st()
 {
     Assert.AreEqual("B230", Soundex.EncodeToSoundex("Bbcd"));
 }
Exemplo n.º 21
0
 public void DoesNotCombineDuplicateEncodingsSeparatedByVowels()
 {
     Assert.AreEqual("J110", Soundex.EncodeToSoundex("Jbob"));
 }
Exemplo n.º 22
0
 public void ReplacesConsonantsWithAppropriateDigitsIgnoresCase()
 {
     Assert.AreEqual("B234", Soundex.EncodeToSoundex("BCDL"));
 }
Exemplo n.º 23
0
 public void CombinesDuplicateEncodings()
 {
     Assert.AreEqual("G123", Soundex.EncodeToSoundex("Gbfcgdt"));
 }
Exemplo n.º 24
0
 public void IgnoresVowelLikeLetters()
 {
     Assert.AreEqual("C123", Soundex.EncodeToSoundex("CAaEeIiOoUuHhYybcd"));
 }
Exemplo n.º 25
0
 public void LimitsLengthToFourCharacters()
 {
     Assert.AreEqual("D123", Soundex.EncodeToSoundex("Dbcdlmr"));
 }
Exemplo n.º 26
0
 public void ReplacesThreeConsonantsWithAppropriateDigits()
 {
     Assert.AreEqual("A256", Soundex.EncodeToSoundex("Ajmr"));
 }
Exemplo n.º 27
0
 public void ReplacesTwoConsonantsWithAppropriateDigits()
 {
     Assert.AreEqual("A340", Soundex.EncodeToSoundex("Adl"));
 }
Exemplo n.º 28
0
        public static bool MISTpassedInterpolated(
            string question,
            bool answer,
            string server_name,
            string database_name,
            string user_name,
            string password,
            string table_name,
            int image_width,
            float[] coherence,
            int no_of_records)
        {
            bool passed = false;

            string index_ngram3 = phoneme.ToNgramStandardised(question, 3, false);
            string standardised_index_primary = "", standardised_index_secondary = "";
            //Metaphone.ToMetaphoneStandardised(question, false, ref standardised_index_primary, ref standardised_index_secondary);
            //string index_metaphone = standardised_index_primary;
            string index_soundex = Soundex.ToSoundexStandardised(question, false, false);
            string index_verbs   = verbs.GetVerbClasses(question);

            float coordinate_ngram3  = GetNgramIndex(index_ngram3, 80);
            float coordinate_soundex = GetNgramIndex(index_soundex, 80);
            float coordinate_verbs   = GetNgramIndex(index_verbs, 80);

            //float coordinate_metaphone = GetNgramIndex(index_metaphone, 80);

            if ((server_name == "") ||
                (server_name == null))
            {
                server_name = "localhost";
            }

            string connection_str =
                "server=" + server_name + ";"
                + "database=" + database_name + ";"
                + "uid=" + user_name + ";"
                + "password="******";";

            string    Query   = "SELECT Hash,Ngram3 FROM " + table_name + " WHERE Ngram3 < " + coordinate_ngram3.ToString() + " ORDER BY Ngram3;";
            ArrayList pixels  = RunMySqlCommand(Query, connection_str, 2);
            int       index_x = pixels.Count * image_width / no_of_records;

            Query  = "SELECT Hash,Soundex FROM " + table_name + " WHERE Soundex < " + coordinate_soundex.ToString() + " ORDER BY Soundex;";
            pixels = RunMySqlCommand(Query, connection_str, 2);
            int index_y = pixels.Count * image_width / no_of_records;

            Query  = "SELECT Hash,verbs FROM " + table_name + " WHERE verbs < " + coordinate_verbs.ToString() + " ORDER BY verbs;";
            pixels = RunMySqlCommand(Query, connection_str, 2);
            int index_z = pixels.Count * 3 / no_of_records;

            int   n    = (((index_y * image_width) + index_x) * 3) + index_z;
            float prob = LogOddsToProbability(coherence[n]);

            if (prob >= 0.5)
            {
                Console.WriteLine("System says YES");
            }
            else
            {
                Console.WriteLine("System says NO");
            }
            if (answer == true)
            {
                if (prob >= 0.5)
                {
                    passed = true;
                }
            }
            else
            {
                if (prob < 0.5)
                {
                    passed = true;
                }
            }

            return(passed);
        }
Exemplo n.º 29
0
 public void ReplacesConsonantCWithDigit2()
 {
     Assert.AreEqual("A200", Soundex.EncodeToSoundex("Ac"));
 }
Exemplo n.º 30
0
 public void UppercasesFirst()
 {
     Assert.AreEqual("A123", Soundex.EncodeToSoundex("abcd"));
 }