Ejemplo n.º 1
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     try {
         if (ErrorCount > 0 && PreprocessSuggestions && !SuggestionLoaded && DictionaryLoaded && SpellCheckEnable)
         {
             SuggestionLoaded = true;
             TextSuggestions  = new Suggestion[ErrorCount];
             string[] Words = Text.Split(WordSeparators);
             for (int i = 0, s = 0, len = 0; i < Words.Length; i++)
             {
                 if (i + len + Words[i].Length != SelectionStart && !SpellChecker.Spell(Words[i]))
                 {
                     TextSuggestions[s++] = new Suggestion()
                     {
                         Word        = Words[i],
                         Suggestions = SpellChecker.Suggest(Words[i])
                     };
                 }
                 len += Words[i].Length;
             }
         }
     }
     catch { }
     base.OnMouseMove(e);
 }
Ejemplo n.º 2
0
        private void SpellingFormHighlight(int startIndex)
        {
            Word firstWord = GetFirstMisspelledWord(editor.Text, startIndex);

            spellingForm.HighlightedRange = new CharacterRange(firstWord.Start, firstWord.Length);
            if (hunspell != null)
            {
                spellingForm.SuggestionsInBox = hunspell.Suggest(firstWord.Text ?? "");
            }
        }
Ejemplo n.º 3
0
    public void MemoryLeakTest()
    {
        // Libraries etc should be loaded two times to init the static backbone of the classes (first and repeat code path)
        // On the third run all code paths are established and all allocated memory should free
        Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic");

        hunspell.Spell("Recommendation");
        hunspell.Suggest("Recommendatio");
        hunspell.Dispose();

        hunspell = new Hunspell("en_us.aff", "en_us.dic");
        hunspell.Spell("Recommendation");
        hunspell.Suggest("Recommendatio");
        hunspell.Dispose();

        GC.Collect();
        GC.WaitForPendingFinalizers();
        long memoryOnBegin = GC.GetTotalMemory(true);

        hunspell = new Hunspell("en_us.aff", "en_us.dic");
        hunspell.Spell("Recommendation");
        hunspell.Suggest("Recommendatio");
        hunspell.Dispose();

        GC.Collect();
        GC.WaitForPendingFinalizers();
        long memoryOnEnd = GC.GetTotalMemory(true);

        Assert.AreEqual(memoryOnBegin, memoryOnEnd);
    }
Ejemplo n.º 4
0
        private string CheckAndCorrectSpelling(List <string> wordsInVariableName)
        {
            var affFile = RetrieveEmbeddedResourceFile("en_US.aff");
            var dicFile = RetrieveEmbeddedResourceFile("en_US.dic");

            using (var hunspell = new Hunspell(affFile, dicFile))
            {
                foreach (var word in wordsInVariableName)
                {
                    if (hunspell.Spell(word))
                    {
                        continue;
                    }

                    var suggestions = hunspell.Suggest(word);
                    if (suggestions == null || suggestions.Count == 0)
                    {
                        return("<No suggestions>");
                    }

                    return(suggestions[0]);
                }

                return(null);
            }
        }
Ejemplo n.º 5
0
        public string AnalyzeString(string text)
        {
            //reference-
            //https://stackoverflow.com/questions/17975103/is-there-a-native-spell-check-method-for-datatype-string

            var options = string.Empty;

            using (var hunspell = new Hunspell("Resources\\en_GB.aff", "Resources\\en_GB.dic"))
            {
                var words = Regex.Split(text, @"\W+", RegexOptions.IgnoreCase);
                IEnumerable <string> misspelledWords;
                // ReSharper disable once AccessToDisposedClosure
                misspelledWords = words.Where(word => !hunspell.Spell(word));

                foreach (var word in misspelledWords)
                {
                    IEnumerable <string> suggestions = hunspell.Suggest(word);
                    options += " Suggested Replacements for " + word + ",         ";
                    for (var i = 0; i < suggestions.Count(); i++)
                    {
                        options += i + 1 + " : " + suggestions.ElementAt(i) + ", ";
                    }
                }
            }

            return(options);
        }
Ejemplo n.º 6
0
        public bool CheckText(string text, out List <string> suggests)
        {
            suggests = null;

            bool result;

            if (RussianAlphabet.Contains(text[0].ToString().ToLower()))
            {
                result = _russian.Spell(text);
                if (!result)
                {
                    suggests = _russian.Suggest(text);
                }
            }
            else
            {
                result = _english.Spell(text);
                if (!result)
                {
                    suggests = _english.Suggest(text);
                }
            }

            return(result);
        }
Ejemplo n.º 7
0
        public static void GetInfo(string word)
        {
            Console.WriteLine("Spelled TestCorrects:" + HunspellTr.Spell(word));
            var stems = HunspellTr.Stem(word);

            Console.WriteLine("Stems:");
            foreach (var stem in stems)
            {
                Console.WriteLine(stem);
            }

            var suggestions = HunspellTr.Suggest(word);

            Console.WriteLine("Suggestions:");
            foreach (var suggestion in suggestions)
            {
                Console.WriteLine(suggestion);
            }

            Console.WriteLine("Analyses:");
            var analyses = HunspellTr.Analyze(word);

            foreach (var analysis in analyses)
            {
                Console.WriteLine(analysis);
            }
        }
Ejemplo n.º 8
0
 void FindMeaningFarsi(string word, out string foundWord, out string meaning)
 {
     foundWord = word;
     meaning   = notFoundMessage;
     if (_spellCheckLoaded)
     {
         var suggestList = _spellFa.Suggest(word);
         if (suggestList != null && suggestList.Count > 0)
         {
             txtWord.Items.Clear();
             txtWord.Items.AddRange(suggestList.ToArray());
             txtWord.ShowSuggestions();
         }
         else
         {
             txtWord.HideSuggestions();
             txtWord.Items.Clear();
         }
     }
     using (var session = dicenfaSession.OpenStatelessSession())
     {
         var farsiMeaning = session.QueryOver <FarsiToEnglish>().Where(x => x.Farsi == word).Take(1).SingleOrDefault();
         if (farsiMeaning != null)
         {
             foundWord = farsiMeaning.Farsi;
             meaning   = farsiMeaning.English;
         }
     }
 }
Ejemplo n.º 9
0
        private void fillDataGrid(string word)
        {
            dGVSuggest.Rows.Clear();
            dGVSuggest.Columns.Clear();
            string sDirectory = Directory.GetCurrentDirectory();

            using (Hunspell hunspell = new Hunspell(sDirectory + @"\de_DE_frami.aff",
                                                    sDirectory + @"\de_DE_frami.dic"))
            {
                List <string> lstSuggest = hunspell.Suggest(word);
                if (lstSuggest.Count > 0)
                {
                    btnReplace.Enabled = true;
                }

                DataGridViewTextBoxColumn txt1 = new DataGridViewTextBoxColumn();
                dGVSuggest.Columns.Add(txt1);
                txt1.Name = "Vorschläge";
                this.dGVSuggest.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

                foreach (string sug in lstSuggest)
                {
                    DataGridViewRow         myDataRow = new DataGridViewRow();
                    DataGridViewTextBoxCell txtCell1  = new DataGridViewTextBoxCell();
                    txtCell1.Value = sug;
                    myDataRow.Cells.Add(txtCell1);
                    dGVSuggest.Rows.Add(myDataRow);
                }
            }
        }
Ejemplo n.º 10
0
        private string UsingSpellChecker(string a, string b, string input)
        {
            using (Hunspell hunspell = new Hunspell(a, b))
            {
                string[] collectedWords = GetWords(input); // all words without punctuation
                foreach (string word in collectedWords)
                {
                    bool correct = hunspell.Spell(word);
                    if (correct == true)
                    {
                        Globals.CorectWords.Add(word);
                    }
                    else if (correct == false)
                    {
                        Globals.test = 1;
                        List <string> suggestions = hunspell.Suggest(word);
                        var           corected    = suggestions.FirstOrDefault();
                        Globals.CorectWords.Add(corected);
                    }
                }
                Globals.combindedString = string.Join(" ", Globals.CorectWords.ToArray());
                if (Globals.test == 1)
                {
                    return("Did you mean " + Globals.combindedString + "?");
                }
            }

            return("");
        }
Ejemplo n.º 11
0
        public void AutocorrectNewWordNodes()
        {
            foreach (InkWordNode inkWordNode in uncheckedNewWordNodes)
            {
                string recognizedString = inkWordNode.GetRecognizedString();
                bool   correct          = !Regex.IsMatch(recognizedString, @"^[a-zA-Z]+$") ||
                                          spellchecker.Spell(recognizedString);

                if (!correct)
                {
                    List <string> suggestions             = spellchecker.Suggest(inkWordNode.GetRecognizedString());
                    List <string> alphabeticalSuggestions = new List <string>();

                    foreach (string suggestion in suggestions)
                    {
                        if (Regex.IsMatch(suggestion, @"^[a-zA-Z]+$"))
                        {
                            alphabeticalSuggestions.Add(suggestion);
                        }
                    }

                    if (alphabeticalSuggestions.Count > 0)
                    {
                        suggestionsBox.SetSuggestions(inkWordNode, alphabeticalSuggestions, fontData);
                        suggestionsBox.Visibility         = Visibility.Visible;
                        strokesAddedSinceSuggestionsShown = 0;

                        // For now, only autocorrect one word at once.
                        break;
                    }
                }
            }

            uncheckedNewWordNodes.Clear();
        }
Ejemplo n.º 12
0
        public string SpellCheck(string word)
        {
            if (string.IsNullOrEmpty(word))
            {
                return("");
            }

            if (!_spc.Spell(word))
            {
                List <string> sg = _spc.Suggest(word);
                if (sg.Count > 0)
                {
                    word = sg[0];
                }
            }
            return(word);
        }
Ejemplo n.º 13
0
            public override IList <string> Suggest(string word)
            {
                if (!String.IsNullOrEmpty(word) && _hunspell != null)
                {
                    return(_hunspell.Suggest(word));
                }

                return(null);
            }
Ejemplo n.º 14
0
    public void GermanUmlautTest()
    {
        Hunspell hunspell = new Hunspell("de_de_frami.aff", "de_de_frami.dic");

        var correct = hunspell.Spell("Änderung");
        var suggest = hunspell.Suggest("Änderun");

        hunspell.Dispose();
    }
Ejemplo n.º 15
0
    public void UnicodeFilenameTest()
    {
        Hunspell hunspell = new Hunspell("de_de_ö_frami.aff", "de_de_ö_frami.dic");

        var correct = hunspell.Spell("Änderung");
        var suggest = hunspell.Suggest("Änderun");

        hunspell.Dispose();
    }
Ejemplo n.º 16
0
        public List <String> Recommended(List <SpellCheckRange> ranges, int index)
        {
            if (index < 0 || index > ranges.Count)
            {
                return(null);
            }

            return(Hunspell.Suggest(ranges[index].Word));
        }
Ejemplo n.º 17
0
        public List <string> suggestions(string word)
        {
            List <string> suggestions;

            using (Hunspell hunspell = new Hunspell("ug.aff", "ug.dic"))
            {
                suggestions = hunspell.Suggest(word);
            }
            return(suggestions);
        }
Ejemplo n.º 18
0
        private static List <string> Suggestions(string word)
        {
            List <string> result;

            using (var hunspell = new Hunspell(AffFilePath, DictionaryFilePath))
            {
                result = hunspell.Suggest(word);
            }

            return(result);
        }
Ejemplo n.º 19
0
    private static Array <string> GetSuggestions(string word)
    {
        var outputArr = new Array <string>();

        foreach (var suggestion in Hunspell.Suggest(word))
        {
            outputArr.Add(suggestion);
        }

        return(outputArr);
    }
Ejemplo n.º 20
0
 /// <summary>
 /// get spelling suggestions for the current CorrectionCandidate
 /// </summary>
 /// <returns></returns>
 public List <string> GetCurrentSuggestions()
 {
     if (currentIndex < 0)
     {
         return(new List <string>());
     }
     if (hunspell != null && allTextParameters.Count > 0 && currentIndex < allTextParameters.Count)
     {
         return(hunspell.Suggest(allTextParameters[currentIndex].CurrentAsString));
     }
     return(new List <string>());
 }
Ejemplo n.º 21
0
        public frmSpeller(string origWord, Hunspell speller)
        {
            InitializeComponent();
            txtProblemWord.Text = origWord;
            _Speller = speller;
            List<string> suggestions = speller.Suggest(origWord);

            foreach (string suggestion in suggestions)
            {
                lstOptions.Items.Add(suggestion);
            }
        }
Ejemplo n.º 22
0
        void FindMeaningEnglish(string word, out string foundWord, out string meaning)
        {
            foundWord = word;
            meaning   = notFoundMessage;
            List <string> foundList = null;

            using (var session = dicenfaSession.OpenStatelessSession())
            {
                var farsiMeaning = session.QueryOver <EnglishToFarsi>().Where(x => x.English == word).Take(1).SingleOrDefault();
                if (farsiMeaning != null)
                {
                    foundWord = farsiMeaning.English;
                    meaning   = farsiMeaning.Farsi;
                }
                else
                {
                    var corrections = session.Query <EnglishToFarsi>().Where(x => x.English.StartsWith(word)).Take(5).ToList();
                    if (corrections.Count > 0)
                    {
                        foundList = corrections.Select(toFarsi => toFarsi.English).ToList();
                    }
                    else
                    {
                        corrections = session.Query <EnglishToFarsi>().Where(x => x.English.EndsWith(word)).Take(5).ToList();
                        if (corrections.Count > 0)
                        {
                            foundList = corrections.Select(toFarsi => toFarsi.English).ToList();
                        }
                    }
                }
            }

            if (_spellCheckLoaded)
            {
                var suggestList = _spellEn.Suggest(word);
                if (suggestList != null && suggestList.Count > 0)
                {
                    txtWord.Items.Clear();
                    txtWord.Items.AddRange(suggestList.ToArray());
                    if (foundList != null)
                    {
                        txtWord.Items.AddRange(foundList.ToArray());
                    }
                    txtWord.ShowSuggestions();
                }
                else
                {
                    txtWord.HideSuggestions();
                    txtWord.Items.Clear();
                }
            }
        }
Ejemplo n.º 23
0
 public void LoadSuggestions(Word misspelledWord)
 {
     if (misspelledWord != null)
     {
         SuggestedWords = new ObservableCollection <Word>(hunSpell.Suggest(misspelledWord.Text).Select(s => new Word(s, misspelledWord.Index)));
         //if (SuggestedWords.Count == 0) SuggestedWords = new ObservableCollection<Word> { new Word(StringResources.NoSuggestions, 0) };
     }
     else
     {
         SuggestedWords = new ObservableCollection <Word>();
     }
     OnPropertyChanged("SuggestedWords");
 }
Ejemplo n.º 24
0
        /// <summary>
        /// This method is used in order to check if a word is misspelled
        /// </summary>
        /// <param name="word">the word we want to check</param>
        /// <param name="getSuggestions">if true, then a list of suggestions will be returned, alongside the boolean value</param>
        /// <returns>
        ///     a pair of elements
        ///     where item1 represents a boolean (checking if the word is misspelled or not)
        ///     and   item2 represents a list of suggestions, that may be similar with the word you've entered
        /// </returns>
        public Tuple <bool, IList <string> > IsMisspelled(string word, bool getSuggestions = false)
        {
            var result = IsMisspelled(word);

            if (result)
            {
                return(new Tuple <bool, IList <string> >(false, new List <string>()));
            }

            return(!getSuggestions
                ? new Tuple <bool, IList <string> >(true, new List <string>())
                : new Tuple <bool, IList <string> >(true, _grammarEngine.Suggest(word)));
        }
Ejemplo n.º 25
0
 private void button_Click(object sender, RoutedEventArgs e)
 {
     using (Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic"))
     {
         var           input       = txtInput.Text;
         List <string> suggestions = hunspell.Suggest(input);
         var           sb          = new StringBuilder();
         foreach (string suggestion in suggestions)
         {
             sb.AppendLine(suggestion);
         }
         this.txtOutput.Text = sb.ToString();
     }
 }
Ejemplo n.º 26
0
        private void button3_Click(object sender, EventArgs e)
        {
            using (Hunspell hunspell = new Hunspell("uz-lat.aff", "uz-lat.dic"))
            {
                bool correct = hunspell.Spell("Nurzod");
                MessageBox.Show("Kiritilgan so'z " + (correct ? "to'g'ri" : "noto'g'ri"));

                List <string> suggestions = hunspell.Suggest("Nurzod");
                MessageBox.Show("There are " + suggestions.Count.ToString() + " suggestions");
                foreach (string suggestion in suggestions)
                {
                    listBox1.Items.Add("Suggestion is: " + suggestion);
                }
            }
        }
Ejemplo n.º 27
0
        private void CheckSpellings()
        {
            mistakes.Clear();
            listBox1.Items.Clear();

            foreach (string word in swords)
            {
                string cword = Regex.Replace(word, @"[^a-zA-Z0-9]", "");

                bool correct = hunspell.Spell(cword);

                if (!correct)
                {
                    InHighligtWord(cword);

                    mistakes.Add(cword);
                }
            }

            if (mistakes.Count > 0)
            {
                start             = 0;
                indexOfSearchText = 0;

                currentword = mistakes[0];

                HighligtWord(currentword);

                List <string> suggestions = hunspell.Suggest(currentword);

                foreach (String entry in suggestions)
                {
                    listBox1.Items.Add(entry);
                }
            }
        }
Ejemplo n.º 28
0
        public List <String> Suggest(string misspelled)
        {
            List <String> list = new List <String>();

            list.Add(misspelled);

            if (SpellCheck(list).Count == 0)
            {
                return(null);
            }
            else
            {
                return(spellChecker.Suggest(misspelled)); // TODO: exception thrown here.
            }
        }
Ejemplo n.º 29
0
 public SuggestionResult GenerateSuggestionResult()
 {
     try
     {
         string word        = FormatWord(QueryName);
         var    suggestions = _hunspell.Suggest(word);
         if (suggestions != null && suggestions.Any())
         {
             return(new SuggestionResult(suggestions.ToArray()));
         }
     }
     catch (Exception) {
     }
     return(null);
 }
Ejemplo n.º 30
0
        public string[] GetSuggestions(string query)
        {
            var terms = query.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            using (Hunspell hunspell = new Hunspell("en_AU.aff", "en_AU.dic"))
            {
                var term    = terms.Last();
                var correct = hunspell.Spell(term);
                if (!correct)
                {
                    var suggestions = hunspell.Suggest(term).ToArray();
                    return(suggestions);
                }
                return(null);
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        ///     Gets list of words from dictionary for the misspelled word.
        /// </summary>
        /// <param name="word">Misspelled word.</param>
        /// <created>art2m,5/10/2019</created>
        /// <changed>art2m,5/10/2019</changed>
        public static void CheckDictionary(string word)
        {
            var sugWords = new SuggestedWordsCollection();

            List <string> suggestions;

            using (var hunspell = new Hunspell("en_us.aff", "en_us.dic"))
            {
                suggestions = hunspell.Suggest(word);
            }

            foreach (var item in suggestions)
            {
                sugWords.AddItem(item);
            }
        }