Пример #1
0
        private SpellCheck.SpellCorrect spelling(string word)
        {
            int a = (char)97;

            if (mSc == null)
            {
                mSc = new SpellCheck.SpellCorrect[26];
                int z = (char)122;
                for (int i = a; i <= z; i++)
                {
                    string DictionaryFile = HttpContext.Current.Server.MapPath(DictionaryBase.SelectedDictionary()) + (char)i + ".txt";
                    if (!File.Exists(DictionaryFile))
                    {
                        throw new Exception("Failed to locate Dictionary File. " + DictionaryFile);
                    }

                    var fileContent = File.ReadAllText(DictionaryFile);
                    var corpus      = new SpellCheck.Corpus(fileContent);
                    mSc[i - a] = new SpellCheck.SpellCorrect(corpus);
                }
            }
            if (!string.IsNullOrWhiteSpace(word))
            {
                //int i = 0;
                //char alpha = Convert.ToChar(word.ToLower().Substring(0, 1));
                //i = alpha;
                return(mSc[findFirstChar(word) - a]);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
 private static IEnumerable <string> ExtractWords(string str)
 {
     return(Regex.Matches(str, DictionaryBase.SearchPattern(), RegexOptions.IgnoreCase)
            .Cast <Match>()
            .Select(m => m.Value));
     //return Regex.Matches(str, "[a-z' ]+", RegexOptions.IgnoreCase) //space added for supporting words with space inside: example: Abdulraoof Arakkal
     //            .Cast<Match>()
     //            .Select(m => m.Value);
 }
Пример #3
0
        private void add2Dictionary(string word, string user)
        {
            char   alpha          = Convert.ToChar(word.Substring(0, 1));
            string DictionaryFile = HttpContext.Current.Server.MapPath(DictionaryBase.SelectedDictionary()) + alpha + ".txt";

            if (!File.Exists(DictionaryFile))
            {
                throw new Exception("Cannot find Dictionary File. " + DictionaryFile);
            }
            string fileContent = File.ReadAllText(DictionaryFile);

            fileContent += "\r\n" + word;
            File.WriteAllText(DictionaryFile, fileContent);
            add2CustomDictionary(word, user);
        }
Пример #4
0
        private void add2CustomDictionary(string word, string user)
        {
            char   alpha   = Convert.ToChar(word.Substring(0, 1));
            string UawFile = HttpContext.Current.Server.MapPath(DictionaryBase.SelectedDictionary()) + alpha + ".uaw";

            if (!File.Exists(UawFile))
            {
                FileStream fs = File.Create(UawFile);
                fs.Close();
                fs.Dispose();
                if (!File.Exists(UawFile))
                {
                    throw new Exception("Cannot find Dictionary File. " + UawFile);
                }
            }

            string fileContent = File.ReadAllText(UawFile);

            fileContent += string.Format("\r\n{0} [added by:{1} on:{2}]", word, user, DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss"));
            File.WriteAllText(UawFile, fileContent);
        }
Пример #5
0
        public string ContentSuggest(string content)
        {
            string ret1      = "";
            string words     = "";
            string comma     = "";
            int    wordCount = 0;
            IEnumerable <string> Contents = Regex.Matches(content, DictionaryBase.SearchPattern(), RegexOptions.IgnoreCase)
                                            .Cast <Match>()
                                            .Select(m => m.Value);

            //IEnumerable<string> Contents2= Regex.Matches(content, DictionaryBase.SearchPattern(), RegexOptions.IgnoreCase)
            //                .Cast<Match>()
            //                .Select(m => SuggestTest(m.Value));
            //var m1 = Contents2.ToArray();

            List <string> wordsAdded = new List <string>();
            DateTime      d          = DateTime.Now;

            foreach (string word in Contents)
            {
                //try
                //{
                if (!string.IsNullOrWhiteSpace(word))
                {
                    string w = "";
                    w = word.Replace("\r", "");;
                    w = w.Replace("\n", "");
                    if (!string.IsNullOrWhiteSpace(w))
                    {
                        if (!isNumeric(w) && !isNumeric(w[0].ToString()))
                        {
                            if (!exist(w.ToLower(), wordsAdded))
                            {
                                List <string> wordSuggestions = Suggest(w);
                                if (wordSuggestions.Count() >= 1)
                                {
                                    bool go = true;
                                    if (wordSuggestions.Count() == 1)
                                    {
                                        if (wordSuggestions[0].ToString() == "no spelling mistake found")
                                        {
                                            go = false;
                                        }
                                    }
                                    if (exist(word.ToLower(), wordsAdded))
                                    {
                                        go = false;
                                    }
                                    if (go)
                                    {
                                        string comma2 = "";
                                        words += comma + "{\"Word\":\"" + word + "\",\"TotalSuggestions\":\"" + wordSuggestions.Count() + "\",\"Suggestions\":[";
                                        comma  = ",";
                                        foreach (string str in wordSuggestions)
                                        {
                                            words += comma2 + "\"" + str + "\"";
                                            comma2 = ",";
                                        }
                                        wordsAdded.Add(word.ToLower());
                                        words += "]}";
                                        wordCount++;
                                    }
                                }
                            }
                        }
                    }
                }
                //}
                //catch (Exception)
                //{
                //}
            }
            DateTime dd = DateTime.Now;

            System.TimeSpan tt = dd - d;
            ret1  = "{\"TotalWords\":\"" + wordCount + "\",\"Words\":[" + words;
            ret1 += "]}";
            return(ret1);
        }