/// <summary> /// Croatia croatian dictionary. /// </summary> public Croatia() { // Load the data. _hyphen = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_hr_HR); _thesaurus = null; _hunspell = new Hunspell(Nequeo.Spelling.Properties.Resources.hr_HR, Nequeo.Spelling.Properties.Resources.hr_HR1); }
/// <summary> /// Israel hebrew dictionary. /// </summary> public Israel() { // Load the data. _hyphen = null; _thesaurus = null; _hunspell = new Hunspell(Nequeo.Spelling.Properties.Resources.he_IL, Nequeo.Spelling.Properties.Resources.he_IL1); }
private void SetLanguage(string language) { try { ClearLanguage(); var speller = new Hunspell(); var path = SpellCheckFolder(); var aff = Path.Combine(path, language + ".aff"); var dic = Path.Combine(path, language + ".dic"); if (File.Exists(aff) && File.Exists(dic)) { speller.Load(aff, dic); LoadCustomDictonary(speller); _speller = speller; _language = language; } else { Notify.Alert(language + " dictionary not found"); } } catch (Exception ex) { Notify.Alert($"{ex.Message} in {language ?? "null"} file"); } }
/// <summary> /// Lataina latin dictionary. /// </summary> public Lataina() { // Load the data. _hyphen = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_la); _thesaurus = null; _hunspell = new Hunspell(Nequeo.Spelling.Properties.Resources.la, Nequeo.Spelling.Properties.Resources.la1); }
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 void SetErrorCounts(Hunspell hunspell) { foreach (SpellCheckProperty spellCheckProperty in this.m_PropertyList) { spellCheckProperty.SetErrorCount(hunspell); } }
/// <summary> /// Russia russian dictionary. /// </summary> public Russia() { // Load the data. _hyphen = null; _thesaurus = null; _hunspell = new Hunspell(Nequeo.Spelling.Properties.Resources.ru_RU, Nequeo.Spelling.Properties.Resources.ru_RU1); }
/// <summary> /// France french dictionary. /// </summary> public France() { // Load the data. _hyphen = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_fr); _thesaurus = new MyThes(Nequeo.Spelling.Properties.Resources.thes_fr); _hunspell = new Hunspell(Nequeo.Spelling.Properties.Resources.fr_moderne, Nequeo.Spelling.Properties.Resources.fr_moderne1); }
/// <summary> /// Australia english dictionary. /// </summary> public Australia() { // Load the data. _hyphen = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_en_AU); _thesaurus = new MyThes(Nequeo.Spelling.Properties.Resources.th_en_AU_v2); _hunspell = new Hunspell(Nequeo.Spelling.Properties.Resources.en_AU, Nequeo.Spelling.Properties.Resources.en_AU1); }
/// <summary> /// Constructs a new NHunspell spell checker. /// </summary> public SpellChecker(string name = "EN_US") { var dictionaryFolder = FindDictionaryPath(); if (String.IsNullOrEmpty(dictionaryFolder)) { throw new FileNotFoundException("Dictionary folder not found!"); } var targetDicFilePath = Path.Combine(dictionaryFolder, Path.ChangeExtension(name, "dic")); if (!File.Exists(targetDicFilePath)) { throw new InvalidOperationException("Dictionary not found(.dic): " + name); } var targetAffFilePath = Path.Combine(dictionaryFolder, Path.ChangeExtension(name, "aff")); if (!File.Exists(targetAffFilePath)) { throw new InvalidOperationException("Dictionary not found(.aff): " + name); } _dicFilePath = targetDicFilePath; _affFilePath = targetAffFilePath; _dicName = name; _core = new Hunspell( targetAffFilePath, targetDicFilePath ); }
private static List <string> Synonyms(string word) { var result = new List <string>(); var thes = new MyThes(DatFilePath); using (var hunspell = new Hunspell(AffFilePath, DictionaryFilePath)) { var stemmedWordResult = hunspell.Stem(word); if (stemmedWordResult.Any()) { var stemmedWord = stemmedWordResult.FirstOrDefault(); if (!string.IsNullOrEmpty(stemmedWord)) { var thesaurusResult = thes.Lookup(stemmedWord); if (thesaurusResult != null && thesaurusResult.Meanings != null && thesaurusResult.Meanings.Any()) { thesaurusResult.Meanings.ForEach(m => m.Synonyms .Where(s => s.ToLower() != stemmedWord.ToLower()) .Where(s => s.ToLower() != word.ToLower()) .ToList() .ForEach(s => result.Add(s.ToLower())) ); } } } } return(result); }
/// <summary> /// Germany german dictionary. /// </summary> public Germany() { // Load the data. _hyphen = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_de_DE); _thesaurus = new MyThes(Nequeo.Spelling.Properties.Resources.th_de_DE_v2); _hunspell = new Hunspell(Nequeo.Spelling.Properties.Resources.de_DE_frami, Nequeo.Spelling.Properties.Resources.de_DE_frami1); }
/// <summary> /// Dispose(bool disposing) executes in two distinct scenarios. /// If disposing equals true, the method has been called directly /// or indirectly by a user's code. Managed and unmanaged resources /// can be disposed. /// If disposing equals false, the method has been called by the /// runtime from inside the finalizer and you should not reference /// other objects. Only unmanaged resources can be disposed. /// </summary> private void Dispose(bool disposing) { if (!_disposed) { if (disposing) { // dispose managed state (managed objects). if (_hyphen != null) { _hyphen.Dispose(); } if (_hunspell != null) { _hunspell.Dispose(); } } // free unmanaged resources (unmanaged objects) and override a finalizer below. // set large fields to null. _hyphen = null; _hunspell = null; _thesaurus = null; _disposed = true; } }
public SuggestionParameter(string word, Hunspell hunspell) { InputWord = word; Suggestions = new List <string>(); Hunspell = hunspell; Success = false; }
public PInvokeSpellingProjectPlugin( string affixFilename, string dictionaryFilename) { // Create the Hunspell wrapper. hunspell = new Hunspell(affixFilename, dictionaryFilename); }
private void SaveNewCustomWord(Hunspell hunSpell, string word) { hunSpell.Add(word); File.AppendAllLines(@"..\..\CustomDictionary.txt", new[] { word }); File.AppendAllLines(@"CustomDictionary.txt", new[] { word }); Console.WriteLine($"\nСлово {word} было добавлено в персональный словарь"); }
/// <summary> /// Checks if hunspell files were found, and loads them /// </summary> internal bool checkHuspell() { bool output; // = new Boolean(); bool change = false; try { if (hunspellEngine == null) { hunspellEngine = new Hunspell(affixFilePath, dictFilePath); hunspellHypen = new Hyphen(affixFilePath); // NHunspell.Hyphen(hunspellDictStream); change = true; } } catch (Exception ex) { throw new aceGeneralException("checkHuspellFailed", ex, this, "Huspell check failed"); return(false); } return(hunspellEngine != null); }
/// <summary> /// Returns valid words that not recognized by the spellchecker /// </summary> /// <param name="hunspell">spellchecker</param> /// <param name="words"></param> /// <param name="testCorrects"></param> /// <returns></returns> public static void TestWords(Hunspell hunspell, IEnumerable <string> words, bool testCorrects) { var failed = testCorrects ? words.Where(word => !hunspell.Spell(word)).ToList() : words.Where(word => hunspell.Spell(word)).ToList(); var testType = testCorrects ? "False Positive Test\n" : "False Negative Test\n"; if (failed.Any()) { Console.WriteLine(testType + "Failed for " + failed.Count + " words:"); foreach (var word in failed) { Console.WriteLine(word); } } else { Console.WriteLine(testType + "Passed."); } Console.WriteLine(); }
static Hunspell GetSpellChecker(string language = "EN_US", bool reload = false) { if (reload || _spellChecker == null) { string dictFolder = Path.Combine(Environment.CurrentDirectory, "Editor\\"); string aff = dictFolder + language + ".aff"; string dic = Path.ChangeExtension(aff, "dic"); _spellChecker = new Hunspell(aff, dic); // Custom Dictionary if any string custFile = Path.Combine(mmApp.Configuration.CommonFolder, language + "_custom.txt"); if (File.Exists(custFile)) { var lines = File.ReadAllLines(custFile); foreach (var line in lines) { _spellChecker.Add(line); } } } return(_spellChecker); }
public virtual IEnumerable <(string word, int count)> GetAllWords(IEnumerable <string> text) { using (var hunspell = new Hunspell("ru_RU.aff", "ru_RU.dic")) { var result = new Dictionary <string, int>(); foreach (var word in text.SelectMany(SplitToWords)) { if (string.IsNullOrEmpty(word)) { continue; } var stems = hunspell.Stem(word); var stem = stems.Any() ? stems[0] : word; if (!result.TryGetValue(stem, out var count)) { count = 0; } result[stem] = count + 1; } return(result .Select(kvp => (kvp.Key, kvp.Value))); } }
private void LoadHunspell(string dictionary) { _currentDictionary = dictionary; _hunspell?.Dispose(); _hunspell = null; _hunspell = Hunspell.GetHunspell(dictionary); }
private void spellcheck(string line) { char[] spliter = { ' ', '\r', '\n', ')', '(', ',', ';', '.' }; string[] words = line.Split(spliter); //nuget http://www.nuget.org/packages/NHunspell/ string afffilepath; string dicfilepath; WritefilesintempFolder(out afffilepath, out dicfilepath); try { using (Hunspell hunspell = new Hunspell(afffilepath, dicfilepath)) { foreach (string word in words) { if (!hunspell.Spell(word)) { spellingMistakes.Add(word); } } } } catch (Exception ex) { Log("Exception occurred. " + ex.Message); } }
private Result <List <string> > PrepareWords(IEnumerable <string> words) { var dir = Path.Combine(Directory.GetCurrentDirectory(), "Resources", "HunspellDicts", "Russian"); var affFile = Path.Combine(dir, "ru.aff"); var dictFile = Path.Combine(dir, "ru.dic"); var hunspellDictsPresent = CheckIfHunspellDictsPresent(affFile, dictFile); if (!hunspellDictsPresent.IsSuccess) { return(hunspellDictsPresent); } var preprocessedWords = new List <string>(); using (var hunspell = new Hunspell(affFile, dictFile)) { foreach (var word in words) { var lemma = hunspell.Stem(word).FirstOrDefault(); if (lemma != null && CheckIfWordMeetsAllRequirements(lemma)) { preprocessedWords.Add(lemma.ToLower()); } } } return(preprocessedWords); }
public void SetLanguage(SpellingLanguages language) { speller = new Hunspell(); var languageKey = LangLookup[language]; var assembly = Assembly.GetExecutingAssembly(); var dictionaryFileStart = string.Format("{0}.Document.SpellCheck.Dictionaries.{1}", assembly.GetName().Name, languageKey); var dictionaryFiles = assembly .GetManifestResourceNames() .Where(name => name.StartsWith(dictionaryFileStart)) .ToArray(); var affixes = dictionaryFiles.Where(name => name.EndsWith(".aff")).OrderBy(s => s); var dictionaries = dictionaryFiles.Where(name => name.EndsWith(".dic")).OrderBy(s => s); var dictionaryPairs = affixes.Zip(dictionaries, (aff, dic) => new { aff, dic }); foreach (var pair in dictionaryPairs) { using (var affStream = assembly.GetManifestResourceStream(pair.aff)) using (var dicStream = assembly.GetManifestResourceStream(pair.dic)) { if (affStream != null && dicStream != null) { var affBytes = new BinaryReader(affStream).ReadBytes((int)affStream.Length); var dicBytes = new BinaryReader(dicStream).ReadBytes((int)dicStream.Length); speller.Load(affBytes, dicBytes); } } } }
/// <summary> /// United states english dictionary. /// </summary> public UnitedStates() { // Load the data. _hyphen = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_en_US); _thesaurus = new MyThes(Nequeo.Spelling.Properties.Resources.th_en_US_v2); _hunspell = new Hunspell(Nequeo.Spelling.Properties.Resources.en_US, Nequeo.Spelling.Properties.Resources.en_US1); }
public ReadOnlyCollection <string> Format(IEnumerable <string> words) { var result = new List <string>(); var r = new Regex("st:(\\w+[#]?)"); var affFileData = Resources.ru_aff; var dicFileData = Encoding.UTF8.GetBytes(Resources.ru_dic); using (var hunspell = new Hunspell(dictionaryFileData: dicFileData, affixFileData: affFileData)) { foreach (var word in words) { var suggestions = hunspell.Analyze(word.ToLower()); if (suggestions.Count == 0) { result.Add(word.ToLower()); continue; } var w = r.Match(suggestions.First()).Groups[1].Value; result.Add(w); } } return(new ReadOnlyCollection <string>(result)); }
//VERY VERY SLOW private static bool CheckIsEnglish(string prospectiveWord) { if (!CheckIsValidPhonology(prospectiveWord) && prospectiveWord.Length > 1) { string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); if (path.ContainsCheck(@"file:\")) { path = path.Replace(@"file:\", ""); } using ( Hunspell hunspell = new Hunspell(Path.Combine(path, "en_us.aff"), Path.Combine(path, "en_us.dic"))) { return(hunspell.Spell(prospectiveWord)); //if (correct) //{ // // errors.Add("This is English: " + prospectiveWord); // //It's Enlgish. // //throw new InvalidOperationException(); //} } } else { return(false); } }
/// <summary> /// Italy italian dictionary. /// </summary> public Italy() { // Load the data. _hyphen = new Hyphen(Nequeo.Spelling.Properties.Resources.hyph_it_IT); _thesaurus = new MyThes(Nequeo.Spelling.Properties.Resources.th_it_IT_v2); _hunspell = new Hunspell(Nequeo.Spelling.Properties.Resources.it_IT, Nequeo.Spelling.Properties.Resources.it_IT1); }
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); } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var words = WordBuilder.GetWords(); var lengthLimitedWords = words.Where(w => w.Length <= 6); Console.WriteLine(lengthLimitedWords.Count()); var letters = lengthLimitedWords.SelectMany(w => w.Select(c => c)); var groupedLetters = letters.GroupBy(c => c); var lettersOrderedByOccurences = groupedLetters.OrderBy(x => x.Count()).Reverse(); foreach (var lettersOrderedByOccurence in lettersOrderedByOccurences) { Console.WriteLine($"{lettersOrderedByOccurence.Key} and {lettersOrderedByOccurence.Count()}"); } var lettersToCheck = new List <char> { 'e', 'r', 'a', 't', 'o', 'i', 's', 'l', 'n', 'c', 'u', 'h', 'd', 'm', 'y', 'w', 'f', 'p', 'g', 'b', 'k' }; using (var dict = new Hunspell()) { /* dict.Analyze();*/ } }
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); } }
private void LoadSpellingDictionariesViaDictionaryFileName(string threeLetterIsoLanguageName, CultureInfo culture, string dictionaryFileName, bool resetSkipList) { fiveLetterWordListLanguageName = Path.GetFileNameWithoutExtension(dictionaryFileName); if (fiveLetterWordListLanguageName != null && fiveLetterWordListLanguageName.Length > 5) { fiveLetterWordListLanguageName = fiveLetterWordListLanguageName.Substring(0, 5); } string dictionary = Utilities.DictionaryFolder + fiveLetterWordListLanguageName; if (resetSkipList) { wordSkipList = new HashSet<string> { Configuration.Settings.Tools.MusicSymbol, "*", "%", "#", "+", "$" }; } // Load names etc list (names/noise words) namesList = new NamesList(Configuration.DictionariesFolder, fiveLetterWordListLanguageName, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl); namesEtcList = namesList.GetNames(); namesEtcMultiWordList = namesList.GetMultiNames(); namesEtcListUppercase = new HashSet<string>(); foreach (string name in namesEtcList) { namesEtcListUppercase.Add(name.ToUpper()); } namesEtcListWithApostrophe = new HashSet<string>(); if (threeLetterIsoLanguageName.Equals("eng", StringComparison.OrdinalIgnoreCase)) { foreach (string namesItem in namesEtcList) { if (!namesItem.EndsWith('s')) { namesEtcListWithApostrophe.Add(namesItem + "'s"); } else { namesEtcListWithApostrophe.Add(namesItem + "'"); } } } // Load user words userWordList = new HashSet<string>(); userWordListXmlFileName = Utilities.LoadUserWordList(userWordList, fiveLetterWordListLanguageName); // Find abbreviations abbreviationList = new HashSet<string>(); foreach (string name in namesEtcList.Where(name => name.EndsWith('.'))) { abbreviationList.Add(name); } if (threeLetterIsoLanguageName.Equals("eng", StringComparison.OrdinalIgnoreCase)) { if (!abbreviationList.Contains("a.m.")) { abbreviationList.Add("a.m."); } if (!abbreviationList.Contains("p.m.")) { abbreviationList.Add("p.m."); } if (!abbreviationList.Contains("o.r.")) { abbreviationList.Add("o.r."); } } foreach (string name in userWordList.Where(name => name.EndsWith('.'))) { abbreviationList.Add(name); } // Load Hunspell spell checker try { if (!File.Exists(dictionary + ".dic")) { var fileMatches = Directory.GetFiles(Utilities.DictionaryFolder, fiveLetterWordListLanguageName + "*.dic"); if (fileMatches.Length > 0) { dictionary = fileMatches[0].Substring(0, fileMatches[0].Length - 4); } } if (hunspell != null) { hunspell.Dispose(); } hunspell = Hunspell.GetHunspell(dictionary); IsDictionaryLoaded = true; spellCheckDictionaryName = dictionary; DictionaryCulture = culture; } catch { IsDictionaryLoaded = false; } }
public void Dispose() { if (hunspell != null) { hunspell.Dispose(); hunspell = null; } if (spellCheck == null) { return; } spellCheck.Dispose(); spellCheck = null; }