/// <summary> /// Adds new user word to the dictionary. /// The word is saving in the .usr file. /// </summary> /// <param name="word"></param> /// <param name="saveOnDisk"></param> /// <returns>false, if word wasn't added (e.g. the word already exists)</returns> public bool AddUserWord(string word, bool saveOnDisk) { // checking... word = word.Trim (); if (word == "") return false; if (words.ContainsKey (word)) return false; // adding to words list SpellWord spellWord = new SpellWord (); spellWord.AffixRules = new AffixRule[0]; words.Add (word, spellWord); // save to disk if (saveOnDisk) { using (StreamWriter f = File.AppendText (userDicPath)) f.WriteLine (word); } return true; }
/// <summary> /// /// </summary> /// <param name="path"></param> private void LoadWordsFile(string path) { StreamReader f = File.OpenText (path); words = new Dictionary<string, SpellWord> (); string word; f.ReadLine (); // read 1st line with words count while ((word = f.ReadLine ()) != null) { int p = word.IndexOf ('/'); SpellWord spellWord= new SpellWord(); AffixRulesCollection wordRules = new AffixRulesCollection(); if (p != -1) { int n = word.Length; for (int i = p+1; i < n; ++i) { char c = word[i]; if (c< affixRulesLookup.Length) { AffixRule rule= affixRulesLookup[c]; if (rule!= null) wordRules.Add (rule); } } word = word.Substring (0, p); } spellWord.AffixRules = wordRules.ToArray<AffixRule>(); try { words.Add (word, spellWord); } catch (Exception) { } } f.Close (); }
/// <summary> /// /// </summary> /// <param name="path"></param> private void LoadUserWordsFile(string path) { using (StreamReader f = File.OpenText (path)) { string s; while ((s = f.ReadLine ()) != null) { if (!words.ContainsKey (s)) { SpellWord spellWord = new SpellWord (); spellWord.AffixRules = new AffixRule[0]; words.Add (s, spellWord); } } } }