private void LoadCustomDictonary(Hunspell speller) { try { var file = CustomDictionaryFile(); foreach (var word in File.ReadAllLines(file)) speller.Add(word); } catch (Exception ex) { Notify.Alert($"{ex.Message} while loading custom dictionary"); } }
public SpellChecker() { myPluginPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof (SpellChecker)).Location) + Path.DirectorySeparatorChar; Hunspell.NativeDllPath = myPluginPath; myHunspell = new Hunspell(myPluginPath + "dic/en_us.aff", myPluginPath + "dic/en_us.dic"); try { myCustomDictionary.AddRange(File.ReadAllLines(myPluginPath + CustomDictionaryPath)); myCustomDictionary.ForEach(s => myHunspell.Add(s)); } catch { } string userDicDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ResharperSpellChecker"); if (!Directory.Exists(userDicDirectory)) { Directory.CreateDirectory(userDicDirectory); } myUserDicFilename = Path.Combine(userDicDirectory, "user.dic"); try { string[] readAllLines = File.ReadAllLines(myUserDicFilename); foreach (var line in readAllLines) { myUserDictionary.Add(line); myHunspell.Add(line); } } catch { } }
private void InitializeCustomDictionary(Hunspell _hunspell, string[] dictionaryLines) { foreach (var dictionaryLine in dictionaryLines) { if (string.IsNullOrEmpty(dictionaryLine) || dictionaryLine.StartsWith("#")) continue; var tokens = dictionaryLine.Split(':'); if (tokens.Length == 1) { _hunspell.Add(tokens[0].Trim()); } else { _hunspell.AddWithAffix(tokens[0].Trim(), tokens[1].Trim()); } } }
public Result GetSuggestions(string input) { string dictionaryPath = Hunspell.NativeDllPath; spellEngine = new SpellEngine(); LanguageConfig enConfig = new LanguageConfig(); enConfig.LanguageCode = "en"; enConfig.HunspellAffFile = Path.Combine(dictionaryPath, "en_us.aff"); enConfig.HunspellDictFile = Path.Combine(dictionaryPath, "en_us.dic"); enConfig.HunspellKey = ""; enConfig.HyphenDictFile = Path.Combine(dictionaryPath, "hyph_en_us.dic"); enConfig.MyThesDatFile = Path.Combine(dictionaryPath, "th_en_us_new.dat"); spellEngine.AddLanguage(enConfig); Result objResult = new Result(); bool correct1; using (var hunspell = new Hunspell(enConfig.HunspellAffFile, enConfig.HunspellDictFile)) { string[] lines = System.IO.File.ReadAllLines(@ConfigurationManager.AppSettings["FilePath"].ToString()); foreach (var line in lines) { hunspell.Add(line.ToLower()); } correct1 = hunspell.Spell(input.ToLower()); } bool correct = false; try { correct = SpellEngine["en"].Spell(input); if (correct = correct1 == false) { objResult.Suggestions = SpellEngine["en"].Suggest(input); objResult.State = "false"; } else { objResult.State = "true"; } } catch (Exception ex) { } return objResult; }