public bool IsMispelled(string word) { if (!spellChecker.Spell(word)) { // is mispelled word in user.dic? if (!userWordList.Contains(word.ToLower())) { return(true); } } return(false); }
public void SetErrorCount(Hunspell hunspell) { int errorCount = 0; foreach (Match match in this.Matches) { if (hunspell.Spell(match.Value) == false) { errorCount += 1; } } this.m_ErrorCount = errorCount; }
/// <summary> /// Check spelling word for the correct spelling. /// If incorrect spelling the get a list of possible correct spelling. /// </summary> /// <param name="word">The word to check spelling on.</param> /// <returns>True if word is spelled correctly else false.</returns> /// <created>art2m,5/10/2019</created> /// <changed>art2m,5/10/2019</changed> public static bool CheckWordSpelling(string word) { using (var hunspell = new Hunspell("en_us.aff", "en_us.dic")) { if (hunspell.Spell(word)) { return(true); } CheckDictionary(word); return(false); } }
public List <string> Spell(string words) { var mistakes = new List <string>(); foreach (var word in words.Replace(" ", " ").Replace(">", " ").Replace("<", " ").Replace("...", " ").Replace("×", " ").Replace("&", " ").Split().Select(word => word.Trim(Punctuation))) { if (Hunspell.Spell(word) == false) { mistakes.Add(word); } } return(mistakes); }
/// <summary> /// Проверяет, что слово имеет корректное написание. /// </summary> /// <param name="word">Слово, которое нужно проверить.</param> /// <returns>True, если слово написано корректно. False в противном случае.</returns> public static bool Spell(string word) { try { if (!hunspellRussian.Spell(word)) { return(hunspellEnglish.Spell(word)); } } catch (Exception) //При работе hunspell очень редко возникает exception, игнорируем и продолжаем работать. { } return(true); }
public IEnumerable <string> GetNormalizedWords(IEnumerable <string> text, HashSet <string> boringWords, Hunspell hunspell) { return(from line in text from word in line .Split() .Select(TrimPunctuation) .Where(w => w.Length > 0) let stemResult = hunspell.Stem(word) select stemResult.Count > 0 ? stemResult[0] : word.ToLower() into normalizedWord where hunspell.Spell(normalizedWord) && !boringWords.Contains(normalizedWord) select normalizedWord); }
public void AddWordTest() { using (Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic")) { Assert.IsFalse(hunspell.Spell("phantasievord")); Assert.IsTrue(hunspell.Add("phantasievord")); Assert.IsTrue(hunspell.Spell("phantasievord")); Assert.IsTrue(hunspell.Remove("phantasievord")); Assert.IsFalse(hunspell.Spell("phantasievord")); Assert.IsFalse(hunspell.Spell("phantasos")); Assert.IsFalse(hunspell.Spell("phantasoses")); Assert.IsTrue(hunspell.AddWithAffix("phantasos", "fish")); Assert.IsTrue(hunspell.Spell("phantasos")); Assert.IsTrue(hunspell.Spell("phantasoses")); Assert.IsTrue(hunspell.Remove("phantasos")); Assert.IsFalse(hunspell.Spell("phantasos")); Assert.IsFalse(hunspell.Spell("phantasoses")); } }
public static string TranslateToArconte(this string word) { using (var hspell = new Hunspell(PathAff, PathDic)) { string translate = " " + word + " "; translate = translate .Replace("ão ", "äi ") .Replace("ãos ", "air ") .Replace("õe ", "öi ") .Replace("ões ", "oir ") .Replace("am ", "amnu ") .Replace("em ", "emnu ") .Replace("im ", "imnu ") .Replace("om ", "omnu ") .Replace("um ", "umne ") .Replace("as ", "ärur ") .Replace("es ", "ërum ") .Replace("is ", "ïrum ") .Replace("os ", "örur ") .Replace("la ", "lan ") .Replace("le ", "len ") .Replace("li ", "lin ") .Replace("lo ", "lon ") .Replace("lu ", "lum ") .Replace("ch", "k") .Replace("sh", "ch") .Replace("t", "h") .Replace("d", "t") .Replace("cs", "d") .Replace("x", "cs") .Replace("á", "ra") .Replace(" ", ""); string verb = word; var removal = removeNonLetter(verb); string ch = removal[0]; verb = removal[1]; if (!hspell.Spell(word)) { translate = verb + ch; } translate = translate + " "; return(translate); } }
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); } } }
static private bool ElementMisspelled(Hunspell hunspell, XmlSchemaElement element, List <string> misspelling) { string name = element.Name ?? element.QualifiedName.Name; string[] split = name.SplitCamelCase().Split(spaces, StringSplitOptions.RemoveEmptyEntries); foreach (string part in split) { bool correct = hunspell.Spell(part); if (!correct) { misspelling.Add(part); } } return(misspelling.Count > 0); }
public static int Analyze(string text) { int results = -1; string pathToAff = HttpContext.Current.Server.MapPath("~/Content/en_US.aff"); string pathToDic = HttpContext.Current.Server.MapPath("~/Content/en_US.dic"); using (var hunspell = new Hunspell(pathToAff, pathToDic)) { MatchCollection matches = Regex.Matches(text, "[a-zA-Z]+", RegexOptions.IgnoreCase); string[] words = matches.Cast <Match>().Select(m => m.Value).ToArray(); results = words.Where(word => hunspell.Spell(word)).Count(); } return(results); }
/// <summary> /// Returns a list of misspelled words based on the passed input /// </summary> /// <param name="Text"> /// The Text to be checked for misspelled words /// </param> /// <param name="Language"> /// The language in which the check will be performed /// </param> /// <returns> /// A list of misspelled words /// </returns> public List <string> GetMisspelledWords(string Text, SupportedLanguages Language) { string[] words = Text.Split(' '); Hunspell spellEngine = this.getDictionary(Language); List <string> misspelledWords = new List <string>(); foreach (string word in words) { string trimmedword = word.Trim(IGNORED_MARKS.ToCharArray()); if (!spellEngine.Spell(trimmedword)) { misspelledWords.Add(trimmedword); } } return(misspelledWords); }
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); } }
private void richTextBox1_DoubleClick(object sender, EventArgs e) { string okteks = richTextBox1.SelectedText; using (Hunspell hunspell = new Hunspell("uz-lat.aff", "uz-lat.dic")) { bool correct = hunspell.Spell(okteks); MessageBox.Show("Kiritilgan so'z " + (correct ? "to'g'ri" : "noto'g'ri") + " " + okteks); List <string> suggestions = hunspell.Suggest(okteks); // MessageBox.Show("There are " + suggestions.Count.ToString() + " suggestions"); foreach (string suggestion in suggestions) { listBox1.Items.Add("Suggestion is: " + suggestion); } } }
public static int CheckSpelling(string body) { int errors = 0; string[] contents = body.Split(' '); using (Hunspell spell = new Hunspell()) { foreach (var item in contents) { if (!(spell.Spell(item))) { errors++; } } } return(errors); }
static private bool AttributeMisspelled(Hunspell hunspell, XmlSchemaAttribute attribute, List <string> misspelling) { if (attribute.Name == null) { return(false); // xml:lang } string[] split = attribute.Name.SplitCamelCase().Split(spaces, StringSplitOptions.RemoveEmptyEntries); foreach (string part in split) { bool correct = hunspell.Spell(part); if (!correct) { misspelling.Add(part); } } return(misspelling.Count > 0);; }
List <String> spellCheck(List <String> words) { List <String> misspelled = new List <String>(); foreach (String word in words) { if (!spellDict.Spell(word)) { // is mispelled word in user.dic? if (!userWordList.Contains(word.ToLower())) { misspelled.Add(word); } } } return(misspelled); }
/// <summary> /// Check spelling word for the correct spelling. /// If incorrect spelling the get a list of possible correct spelling. /// </summary> /// <param name="word">The word to check spelling on.</param> /// <returns>True if word is spelled correctly else false.</returns> /// <created>art2m,5/10/2019</created> /// <changed>art2m,5/10/2019</changed> public static bool CheckWordSpelling(string word) { using (var hunspell = new Hunspell("en_us.aff", "en_us.dic")) { if (hunspell.Spell(word)) { return(true); } msw.AddItem(word); MyMessagesClass.InformationMessage = string.Concat("This word is not spelled correctly: ", word); MyMessagesClass.ShowInformationMessageBox(); CheckDictionary(word); return(false); } }
public static IList <string> SplitToWords(string sentence, bool correct = false) { //if (lemmatize) //{ // return DoLemmatize(sentence); //} var words = SplitToWordsNoLemmatize(sentence); if (_spell == null) { _spell = new Hunspell("en_us.aff", "en_us.dic"); } var stems = new List <string>(); foreach (var word in words) { var tmpWord = _multipleCharacterRegex.Replace(word, "$1$1"); if (correct) { var correctlySpelled = _spell.Spell(word); if (!correctlySpelled) { var tmp = _spell.Suggest(word); if (tmp != null && tmp.Count == 1) { tmpWord = tmp[0]; } } } var wordStems = _spell.Stem(tmpWord); if (wordStems.Count > 0) { stems.AddRange(wordStems); } else { stems.Add(word); } } return(stems); }
// [Ignore("Dictionary Package (FullPackage.zip) isn't included in source code due t its size")] // [Test] public void AllDictionariesTest() { using (ZipFile fullPackageZip = new ZipFile("..\\..\\..\\..\\Dictionaries\\FullPackage.zip")) { foreach (ZipEntry fullPackageEntry in fullPackageZip) { if (!fullPackageEntry.Name.StartsWith("hyph") && !fullPackageEntry.Name.StartsWith("thes")) { var packageStream = fullPackageZip.GetInputStream(fullPackageEntry); var packageZip = new ZipFile(packageStream); foreach (ZipEntry fileEntry in packageZip) { try { if (fileEntry.Name.EndsWith(".aff") || fileEntry.Name.EndsWith(".dic")) { var inputStream = packageZip.GetInputStream(fileEntry); var outputStream = new FileStream(fileEntry.Name, FileMode.Create); byte[] buffer = new byte[4096]; StreamUtils.Copy(inputStream, outputStream, buffer); outputStream.Flush(); } } catch (Exception e) { } } string filePrefix = fullPackageEntry.Name.Replace(".zip", ""); Console.WriteLine("Dictionary: " + filePrefix); using (Hunspell hunspell = new Hunspell(filePrefix + ".aff", filePrefix + ".dic")) { var suggest = hunspell.Suggest("interne"); foreach (string suggestion in suggest) { hunspell.Spell(suggestion); } } } } } }
private string LemmatizeWordWithHunspell(string word, Hunspell speller) { if (word.Length == 0) { return(""); } else if (word.Length == 1) { return(word.Trim()); } else { if (speller.Spell(word)) { string theOne = ""; List <string> outcome = speller.Analyze(word.Trim()); if (outcome.Count == 0) { return(word.Trim()); } else { foreach (string o in outcome) { string tmp = Regex.Match(o, @"st:(.+?)\b").Groups[1].ToString(); if (theOne == "") { theOne = tmp; } if (tmp.Trim().ToLower() == word.Trim().ToLower()) { theOne = tmp; } } return(theOne); } } else { return(word.Trim()); } } }
static private bool DocumentationMisspelled(Hunspell hunspell, XmlSchemaDocumentation doc, List <string> misspelling) { if (doc.Markup.Count() == 0) { return(false); } string text = doc.Markup.FirstOrDefault().InnerText; // strip punctuation string stripped = text.Replace("ddi:", " "); stripped = stripped.Replace("xs:", " "); stripped = stripped.Replace(@"mm/dd/yyyy", " "); stripped = stripped.Replace(@"xml:lang", " "); stripped = stripped.Replace(@"xml:", " "); // camel cased acronyms stripped = stripped.Replace(@"EOLs", " "); stripped = stripped.Replace(@"IDs", " "); stripped = new string(stripped.Select(c => (char.IsLetterOrDigit(c) || c == '-') ? c : ' ').ToArray()); string[] split = stripped.Split(space, StringSplitOptions.RemoveEmptyEntries); foreach (string part in split) { string[] split2 = part.SplitCamelCase().Split(spaces, StringSplitOptions.RemoveEmptyEntries); foreach (string part2 in split2) { if (part2.Length > 2 && !part2.Any(c => char.IsLower(c))) { continue; //Acronym } bool correct = hunspell.Spell(part2); if (!correct) { misspelling.Add(part2); } } } return(misspelling.Count > 0); }
/// <summary> /// Check spelling word for the correct spelling. /// If incorrect spelling the get a list of possible correct spelling. /// </summary> /// <param name="word">The word to check spelling on.</param> /// <returns>True if word is spelled correctly else false.</returns> /// <created>art2m,5/10/2019</created> /// <changed>art2m,5/10/2019</changed> public static bool CheckWordSpelling(string word) { using (var hunspell = new Hunspell("en_us.aff", "en_us.dic")) { if (hunspell.Spell(word)) { return(true); } msw.AddItem(word); MyMessagesClass.InformationMessage = string.Concat("This word is not spelled correctly: ", word); const string Caption = "Spelling Incorrect."; MessageBox.Show(msg, Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); CheckDictionary(word); return(false); } }
/// <summary> /// Check if the word is spelled correctly. /// </summary> /// <param name="word"></param> /// <returns>true if word is correct</returns> private bool HunspellSpell(Word word) { bool result = true; if (word.Length > 0) { bool wordIsNumber = numberRegex.IsMatch(word.Text); bool wordContainsDigits = digitRegex.IsMatch(word.Text); bool wordIgnored = IgnoreList.Contains(word.Text); if (!wordIgnored && !wordIsNumber && (!wordContainsDigits || (wordContainsDigits && !options.IgnoreWordsWithDigits))) { if (hunspell != null) { result = hunspell.Spell(word.Text); } } } return(result); }
public static void CheckSpelling(Scintilla scintilla, Hunspell hunspell) { if (string.IsNullOrWhiteSpace(scintilla.Text)) { return; } scintilla.Indicators[8].Style = IndicatorStyle.Squiggle; scintilla.Indicators[8].ForeColor = Color.Red; scintilla.IndicatorCurrent = 8; scintilla.IndicatorClearRange(0, scintilla.TextLength); foreach (Match m in Regex.Matches(scintilla.Text, @"\b\w*\b")) { if (!hunspell.Spell(m.Value)) { scintilla.IndicatorFillRange(m.Index, m.Length); } } }
private void okButton_Click(object sender, EventArgs e) { LoadHunspell(); var wordDictionary = new Dictionary <string, int>(); foreach (var subtitle in _subtitleList) { foreach (var p in subtitle.Paragraphs) { if (p.Text.Contains("Synced and corrected by", StringComparison.OrdinalIgnoreCase) || p.Text.Contains("www.")) { continue; } var words = SpellCheckWordLists.Split(HtmlUtil.RemoveHtmlTags(p.Text, true)); foreach (var word in words) { if (!_hunspell.Spell(word.Text) || Utilities.IsNumber(word.Text)) { continue; } if (wordDictionary.ContainsKey(word.Text)) { wordDictionary[word.Text]++; } else { wordDictionary.Add(word.Text, 1); } } } labelStatus.Text = $"{wordDictionary.Count:#,###,##0} words..."; labelStatus.Refresh(); Application.DoEvents(); } SaveFile(wordDictionary); }
public string SpellCheck(string Text) { Hunspell hunspell = new Hunspell(System.Web.HttpContext.Current.Server.MapPath("~/Assets/SpellCheck/en_US.aff"), System.Web.HttpContext.Current.Server.MapPath("~/Assets/SpellCheck/en_US.dic")); try { //// Do spell check and look for suggested word. only if text does NOT contain number if (Text.text.Length >= 3) { var containsNumber = Text.text.Any(char.IsDigit); if (!containsNumber) { var Correct = hunspell.Spell(Text.text); if (!Correct) { List<string> suggestions = hunspell.Suggest(Text.text); foreach (string suggestion in suggestions.Take(1)) { //// Do something with the Suggested word ////// suggestion is the object that is corrected word } } } // check for Commas, Dashes, Periods right after Text var lastLetter = Text.text.Substring(Text.text.Length - 1); if ( (lastLetter == ",") || (lastLetter == ".") || (lastLetter == "-") ) { var suggestion = Text.text.Remove(Text.text.Length - 1); ////// Do something with word } } } hunspell.Dispose(); }
private static void Check(TableSectionData section) { using (Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic")) { for (int i = 0; i < section.NumberOfRows; i++) { for (int j = 0; j < section.NumberOfColumns; j++) { string text = section.GetCellText(i, j); foreach (string word in text.Split(' ')) { if (!hunspell.Spell(word)) { TableCellStyle style = section.GetTableCellStyle(i, j); style.BackgroundColor = INCORRECT_SPELLING_BACKGROUND_COLOR; section.SetCellStyle(i, j, style); } } } } } }
private void scintilla_TextChanged(object sender, EventArgs e, Hunspell hunspell) { var _scintilla = (Scintilla)sender; if (string.IsNullOrWhiteSpace(_scintilla.Text)) { return; } _scintilla.Indicators[8].Style = IndicatorStyle.Squiggle; _scintilla.Indicators[8].ForeColor = Color.Red; _scintilla.IndicatorCurrent = 8; _scintilla.IndicatorClearRange(0, _scintilla.TextLength); foreach (Match m in Regex.Matches(_scintilla.Text, @"\b\w*\b")) { if (!hunspell.Spell(m.Value)) { _scintilla.IndicatorFillRange(m.Index, m.Length); } } }
public void Test() { using (Hunspell hunspell = new Hunspell("en_us.aff", "en_us.dic")) { Console.WriteLine("Hunspell - Spell Checking Functions"); Console.WriteLine("¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯"); Console.WriteLine("Check if the word 'Recommendation' is spelled correct"); bool correct = hunspell.Spell("Recommendation"); Console.WriteLine("Recommendation is spelled " + (correct ? "correct" : "not correct")); Console.WriteLine(""); Console.WriteLine("Make suggestions for the word 'Recommendatio'"); List <string> suggestions = hunspell.Suggest("Recommendatio"); Console.WriteLine("There are " + suggestions.Count.ToString() + " suggestions"); foreach (string suggestion in suggestions) { Console.WriteLine("Suggestion is: " + suggestion); } } }