예제 #1
0
        ///<summary>
        /// Generates respelling suggestions in given edit distance for a word
        ///</summary>
        ///<param name="word">Word</param>
        ///<param name="editDistance">Edit Distance</param>
        ///<param name="respellingType">Type of generating respelling, logically OR desired types</param>
        ///<param name="alphabet">List of charachters used to generate respelling</param>
        ///<returns>Respelling Suggestions</returns>
        public static string[] GenerateRespelling(string word, int editDistance, RespellingGenerationType respellingType, params char[] alphabet)
        {
            try
            {
                List <string> suggestion = new List <string>();

                if (editDistance == 1)
                {
                    suggestion.AddRange(GetWordsWithOneEditDistance(word, respellingType, alphabet));
                }
                else
                {
                    suggestion.AddRange(GetWordsTillAnyEditDistance(GetWordsWithOneEditDistance(word, respellingType, alphabet), editDistance - 1, respellingType, alphabet));
                }

                return(suggestion.Distinct().ToArray());
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("Error in generating suggestions for any edit distance: {0}", ex.Message));
            }

            return(new string[] { word });
        }
예제 #2
0
        private static string[] GetWordsWithOneEditDistance(string word, RespellingGenerationType respellingType, params char[] alphabet)
        {
            try
            {
                List <string> suggestion = new List <string>();

                if ((respellingType & RespellingGenerationType.Delete) != 0)
                {
                    suggestion.AddRange(GetWordsWithOneEditDistanceDelete(word));
                }
                if ((respellingType & RespellingGenerationType.Substitute) != 0)
                {
                    suggestion.AddRange(GetWordsWithOneEditDistanceSubstitute(word, alphabet));
                }
                if ((respellingType & RespellingGenerationType.Insert) != 0)
                {
                    suggestion.AddRange(GetWordsWithOneEditDistanceInsert(word, alphabet));
                }
                if ((respellingType & RespellingGenerationType.Transpose) != 0)
                {
                    suggestion.AddRange(GetWordsWithOneEditDistanceTranspose(word));
                }

                //Added on 28-March-2010
                //Commented on 30-March-2010
                //suggestion.Add(word);

                return(suggestion.ToArray());
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("Error in generating suggestions: {0}", ex.Message));
            }

            return(new string[] { word });
        }
예제 #3
0
        private static string[] GetWordsTillAnyEditDistance(string[] word, int editDistance, RespellingGenerationType respellingType, params char[] alphabet)
        {
            try
            {
                List <string> suggestion = new List <string>();

                if (editDistance == 1)
                {
                    foreach (string localWord in word)
                    {
                        suggestion.AddRange(GetWordsWithOneEditDistance(localWord, respellingType, alphabet));
                    }
                }
                else
                {
                    foreach (string localWord in word)
                    {
                        suggestion.AddRange(GetWordsTillAnyEditDistance(GetWordsWithOneEditDistance(localWord, respellingType, alphabet), editDistance - 1, respellingType, alphabet));
                    }
                }

                return(suggestion.ToArray());
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("Error in generating suggestions: {0}", ex.Message));
            }

            return(new string[0]);
        }