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); }
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 ?? ""); } }
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); }
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); } }
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); }
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); }
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); } }
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; } } }
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); } } }
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(""); }
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(); }
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); }
public override IList <string> Suggest(string word) { if (!String.IsNullOrEmpty(word) && _hunspell != null) { return(_hunspell.Suggest(word)); } return(null); }
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(); }
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(); }
public List <String> Recommended(List <SpellCheckRange> ranges, int index) { if (index < 0 || index > ranges.Count) { return(null); } return(Hunspell.Suggest(ranges[index].Word)); }
public List <string> suggestions(string word) { List <string> suggestions; using (Hunspell hunspell = new Hunspell("ug.aff", "ug.dic")) { suggestions = hunspell.Suggest(word); } return(suggestions); }
private static List <string> Suggestions(string word) { List <string> result; using (var hunspell = new Hunspell(AffFilePath, DictionaryFilePath)) { result = hunspell.Suggest(word); } return(result); }
private static Array <string> GetSuggestions(string word) { var outputArr = new Array <string>(); foreach (var suggestion in Hunspell.Suggest(word)) { outputArr.Add(suggestion); } return(outputArr); }
/// <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>()); }
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); } }
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(); } } }
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"); }
/// <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))); }
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(); } }
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); } } }
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); } } }
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. } }
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); }
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); } }
/// <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); } }