Esempio n. 1
0
        private Hunspell BuildHunspell(bool initialize = false)
        {
            // If cache item is not found, then reload hunspell object again.
            if (initialize || _cacheManager.IsSet(BRAND_ALL_KEY) == false || _cacheManager.IsSet(CUSTOM_DICTIONARY_ALL_KEY) == false)
            {
                var affFilePath  = _nhunspellSettings.NHunspellResourceAffFilePath;
                var dictFilePath = _nhunspellSettings.NHunspellResourceDictFilePath;
                _hunspell = new Hunspell(affFilePath, dictFilePath);

                var brands = _brandService.GetBrandList();
                foreach (var brand in brands)
                {
                    _hunspell.Add(brand.Name);

                    var cleanedName = RemoveDiacritics(brand.Name);
                    if (cleanedName != brand.Name)
                    {
                        _hunspell.Add(cleanedName);
                    }
                }

                var dictionaries = GetAllCustomDictionary();
                foreach (var item in dictionaries)
                {
                    _hunspell.Add(item.Word);
                    var cleanedName = RemoveDiacritics(item.Word);
                    if (cleanedName != item.Word)
                    {
                        _hunspell.Add(cleanedName);
                    }
                }
            }

            return(_hunspell);
        }
Esempio n. 2
0
 public void LoadCustomDictionary()
 {
     string[] strings = File.ReadAllLines(box.CustomDictionaryPath);
     foreach (var str in strings)
     {
         hunSpell.Add(str);
     }
 }
Esempio n. 3
0
 private void LoadCustomDictionary()
 {
     string[] strings = File.ReadAllLines(_customDictionaryPath);
     foreach (var str in strings)
     {
         _hunSpell.Add(str);
     }
 }
Esempio n. 4
0
 /// <inheritdoc/>
 public void Add(string word)
 {
     if (!_core.Add(word))
     {
         _core.Add(word.ToUpper());
         _core.Add(word.ToLower());
     }
 }
Esempio n. 5
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(currentword))
            {
                hunspell.Add(currentword);
                AddWord(currentword);
            }

            ContSearch();
        }
Esempio n. 6
0
 private void btnIgnoreAll_Click(object sender, EventArgs e)
 {
     if (m_oHunspell != null)
     {
         Globals.ThisAddIn.ByPassAppWinSelectChange = true;
         m_oHunspell.Add(sSCIIOutput);
         CheckNext_U();
     }
     SetSpellingState("Անտեսել");
 }
Esempio n. 7
0
 public void LoadCustomDictionary()
 {
     if (!File.Exists(box.CustomDictionaryPath))
     {
         return;
     }
     string[] strings = File.ReadAllLines(box.CustomDictionaryPath);
     foreach (var str in strings)
     {
         hunSpell.Add(str);
     }
 }
Esempio n. 8
0
        void AutocorrectInit()
        {
            using (Stream stream = new FileStream("rudi_hand_font.txt", FileMode.Open))
            {
                var serializer = new DataContractJsonSerializer(typeof(Dictionary <char, DataStylusToken>));
                var data       = (Dictionary <char, DataStylusToken>)serializer.ReadObject(stream);

                foreach (var token in data)
                {
                    StrokeCollection strokes = token.Value.Representation();

                    // We made our characters in 100x100 boxes.
                    StylusToken stylusToken = new StylusToken(strokes);
                    stylusToken.Normalize();
                    fontData.Add(token.Key, stylusToken);
                }
            }

            spellchecker.Add("hackathon");

            // To display autocorrect stuff.
            suggestionsBox = new SuggestionsBox(this);

            OverlayCanvas.Children.Add(suggestionsBox);
            Grid.SetRow(suggestionsBox, 0);
            Grid.SetColumn(suggestionsBox, 0);
            suggestionsBox.Background = new SolidColorBrush(Colors.LightGray);
            suggestionsBox.Visibility = Visibility.Collapsed;
        }
Esempio n. 9
0
 public void AddWord(string word)
 {
     if (!_hunspell.Spell(word))
     {
         _hunspell.Add(word);
     }
 }
        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);
        }
Esempio n. 11
0
 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} было добавлено в персональный словарь");
 }
Esempio n. 12
0
        public SpellChecker(Document document)
        {
            if (hunspell != null)
            {
                hunspell.Dispose();
            }

            this.document = document;

            ignoreList = new List <string>();
            UpdateIgnoreList();

            string dll = System.IO.Path.GetDirectoryName(
                System.Reflection.Assembly.GetExecutingAssembly().Location);

            try
            {
                if (Hunspell.NativeDllPath != dll)
                {
                    Hunspell.NativeDllPath = dll;
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

#if DEBUG
            //// SCaddinsApp.WindowManager.ShowMessageBox(System.IO.Path.Combine(dll, "Assets"));
            hunspell = new Hunspell(
                System.IO.Path.Combine(dll, @"Assets/en_AU.aff"),
                System.IO.Path.Combine(dll, @"Assets/en_AU.dic"));
#else
            hunspell = new Hunspell(
                System.IO.Path.Combine(Constants.InstallDirectory, "etc", "en_AU.aff"),
                System.IO.Path.Combine(Constants.InstallDirectory, "etc", "en_AU.dic"));
#endif

            // add some arch specific words
            hunspell.Add("approver");
            hunspell.Add(@"&");
            hunspell.Add(@"-");
            hunspell.Add(@"Autodesk");

            allTextParameters = GetAllTextParameters(document);
            currentIndex      = -1;
        }
Esempio n. 13
0
        private void InitCustomDictionary(Hunspell hunSpell)
        {
            var customWords = File.ReadAllLines("CustomDictionary.txt");

            foreach (var line in customWords)
            {
                hunSpell.Add(line);
            }
        }
Esempio n. 14
0
        public void SpellCheck()
        {
            if (this.needs_checking)
            {
                this.needs_checking = false;
                StringBuilder rtf = new StringBuilder();
                rtf.Append("{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1040{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0" + this.Font.FontFamily.Name + ";}}");
                rtf.Append("{\\colortbl ;\\red0\\green0\\blue0; \\red255\\green0\\blue0; }");
                rtf.Append("\\fs20");

                using (Hunspell sc = new Hunspell(SpellChecker.AFF, SpellChecker.DIC))
                {
                    SpellChecker.AllowedWords.ForEach(x => sc.Add(x));
                    String[] words   = this.Text.Split(' ');
                    bool     correct = false;

                    for (int i = 0; i < words.Length; i++)
                    {
                        if (words[i].Length > 0)
                        {
                            correct = (words[i].StartsWith("http://") || words[i].StartsWith("www.") || words[i].Contains("arlnk"));

                            if (!correct)
                            {
                                correct = sc.Spell(new String(words[i].Where(x => Char.IsLetter(x) || Char.IsNumber(x)).ToArray()));
                            }

                            if (correct)
                            {
                                rtf.Append("\\cf0\\cf1");
                            }
                            else
                            {
                                rtf.Append("\\cf0\\cf2");
                            }

                            foreach (char c in words[i].ToCharArray())
                            {
                                rtf.Append("\\u" + ((int)c) + "?");
                            }
                        }

                        if (i < (words.Length - 1))
                        {
                            rtf.Append("\\u" + ((int)' ') + "?");
                        }
                    }
                }

                rtf.Append("\\cf0\\cf1}");
                int ss = this.SelectionStart;
                int sl = this.SelectionLength;
                this.Rtf             = rtf.ToString();
                this.SelectionStart  = ss;
                this.SelectionLength = sl;
            }
        }
Esempio n. 15
0
 /// <summary>
 /// Adds a new word to add-on the dictionary for a given locale
 /// </summary>
 /// <param name="word"></param>
 /// <param name="lang"></param>
 public static bool AddWordToDictionary(string word, string lang = "en-US")
 {
     return(LanguageUtils.IgnoreErrors(() =>
     {
         var dictPath = Path.Combine(ExternalDictionaryFolder, lang + "_custom.txt");
         File.AppendAllText(dictPath, word + "\r\n");
         _spellChecker.Add(word);
     }));
 }
Esempio n. 16
0
        private void LoadCustomDictonary(Hunspell speller)
        {
            var file = CustomDictionaryFile();

            foreach (var word in File.ReadAllLines(file))
            {
                speller.Add(word);
            }
        }
Esempio n. 17
0
 private void spellingForm_AdddedWord(object sender, SpellingEventArgs e)
 {
     if (hunspell != null)
     {
         hunspell.Add(e.Word);
     }
     UpdateSpellingForm(e.TextIndex);
     CallPropertiesChanged();
 }
Esempio n. 18
0
 public void Add(string word)
 {
     if (_speller == null)
     {
         return;
     }
     _speller.Add(word);
     UpdateCustomDictionary(word);
 }
Esempio n. 19
0
        private static void SaveNewCustomWord([NotNull] Hunspell hunSpell, string word)
        {
            hunSpell.Add(word);
#if DEBUG
            File.AppendAllLines(@"..\..\CustomDictionary.txt", new[] { word });
#endif
            File.AppendAllLines(@"CustomDictionary.txt", new[] { word });
            ConsoleUtilities.WriteGreenLine($"\nСлово {word} было добавлено в персональный словарь");
        }
Esempio n. 20
0
        public static Hunspell GetSpellChecker(string language = "en-US", bool reload = false)
        {
            if (reload || _spellChecker == null)
            {
                string dic = Path.Combine(InternalDictionaryFolder, language + ".dic");
                string aff = Path.ChangeExtension(dic, "aff");

                if (!File.Exists(dic))
                {
                    dic = Path.Combine(ExternalDictionaryFolder, language + ".dic");
                    aff = Path.ChangeExtension(dic, "aff");

                    if (!File.Exists(dic))
                    {
                        mmApp.Configuration.Editor.Dictionary = "en-US";
                        if (mmApp.Model?.Window != null)
                        {
                            mmApp.Model.Window.ShowStatusError($"Dictionary for language {language} not found. Resetting to en-US. Please reinstall your language.");
                        }

                        return(GetSpellChecker("en-US", true));
                    }
                }

                _spellChecker?.Dispose();
                try
                {
                    _spellChecker = new Hunspell(aff, dic);
                }
                catch
                {
                    if (!DownloadDictionary(language))
                    {
                        if (language != "en-US")
                        {
                            mmApp.Configuration.Editor.Dictionary = "en-US";
                            return(GetSpellChecker("en-US", true));
                        }
                        throw new InvalidOperationException("Language not installed. Reverting to US English.");
                    }
                }

                // Custom Dictionary if any
                string custFile = Path.Combine(ExternalDictionaryFolder, language + "_custom.txt");
                if (File.Exists(custFile))
                {
                    var lines = File.ReadAllLines(custFile);
                    foreach (var line in lines)
                    {
                        _spellChecker.Add(line);
                    }
                }
            }

            return(_spellChecker);
        }
Esempio n. 21
0
        public bool add(string word)
        {
            bool added;

            using (Hunspell hunspell = new Hunspell("ug.aff", "ug.dic"))
            {
                added = hunspell.Add(word);
            }
            return(added);
        }
Esempio n. 22
0
 public SpellChecker(AvailableDictionaries dictionaryName = AvailableDictionaries.en_US)
 {
     if (_currentSpellChecker == null)
     {
         _currentSpellChecker = SpellCheckerFactory.GetSpellChecker(dictionaryName);
         var projectDictionaryWords = AryaTools.Instance.InstanceData.Dc.ProjectDictionaries.Select(pd => pd.Word);
         foreach (string word in projectDictionaryWords.ToList())
         {
             _currentSpellChecker.Add(word);
         }
     }
 }
Esempio n. 23
0
        public Spellcheck(string dictionaryPath)
        {
            var affix    = Path.Combine(dictionaryPath, "en-GB.aff");
            var dict     = Path.Combine(dictionaryPath, "en-GB.dic");
            var specials = Path.Combine(dictionaryPath, "specials.txt");

            Hunspell = new Hunspell(affix, dict);
            foreach (var line in File.ReadAllLines(specials))
            {
                Hunspell.Add(line);
            }
        }
Esempio n. 24
0
 internal void AddToProjectDictinary(string dictionaryWord)
 {
     if (!String.IsNullOrEmpty(dictionaryWord))
     {
         Arya.Data.ProjectDictionary currntWord = new Arya.Data.ProjectDictionary
         {
             Word = dictionaryWord
         };
         AryaTools.Instance.InstanceData.Dc.ProjectDictionaries.InsertOnSubmit(currntWord);
         AryaTools.Instance.SaveChangesIfNecessary(false, false);
         _currentSpellChecker.Add(dictionaryWord);
     }
 }
 /// <summary>
 /// Adds the to dictionary.
 /// </summary>
 /// <param name="word">The word.</param>
 public void AddTodictionary(string word)
 {
     try
     {
         if (hunSpell != null)
         {
             hunSpell.Add(word);
         }
     }
     catch (Exception generalException)
     {
         _logger.Info("Error occurred in AddTodictionary()" + generalException.ToString());
     }
 }
Esempio n. 26
0
 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");
     }
 }
Esempio n. 27
0
        private void ReadWords()
        {
            using (CsvFileReader reader = new CsvFileReader(dic + ".csv"))
            {
                CsvRow row = new CsvRow();

                while (reader.ReadRow(row))
                {
                    foreach (string s in row)
                    {
                        hunspell.Add(s);
                    }
                }

                reader.Dispose();
            }
        }
Esempio n. 28
0
        private Hunspell CreateSpellChecker(IList <string> dictionary)
        {
            dictionary = this.SplitWords(dictionary);

            string mergedDictionary = string.Join(Environment.NewLine, dictionary);

            mergedDictionary = string.Format("{0}{1}{2}", dictionary.Count, Environment.NewLine, mergedDictionary);

            var hunspell = new Hunspell(new byte[1], GetBytes(mergedDictionary));

            foreach (var word in dictionary)
            {
                hunspell.Add(word);
            }

            return(hunspell);
        }
Esempio n. 29
0
 public static void AddCustomWords(Hunspell hunspell)
 {
     try
     {
         var lines = File.ReadAllLines("CustomWords.txt");
         foreach (string line in lines)
         {
             string word = line.Trim();
             if (!string.IsNullOrWhiteSpace(word))
             {
                 hunspell.Add(word);
             }
         }
     }
     catch (Exception)
     {
     }
 }
Esempio n. 30
0
        private void btnAddToDictionary_Click(object sender, EventArgs e)
        {
            string customWords = _dictionaryPath + CUSTOM_DICTIONARY_FILE;

            StreamWriter writer = new StreamWriter(customWords, true);

            try
            {
                writer.WriteLine(txtNotFound.Text);
            }
            finally
            {
                writer.Close();
                writer = null;
            }

            _spellChecker.Add(txtNotFound.Text);
            SpellCheckTextBox(ControlsToSpellCheck[_currentTextBox], ++_currentPosition);
        }