Esempio n. 1
0
        private void Initialize()
        {
            var config = new PersianSpellCheckerConfig()
            {
                DicPath         = GetFullPath("Dic.dat"),
                StemPath        = GetFullPath("Stem.dat"),
                EditDistance    = 2,
                SuggestionCount = 7,
            };

            m_spellEngine = new PersianSpellChecker(config);
            m_verifier    = new SpellCheckerInlineVerifier(false, m_spellEngine);
        }
        /// <summary>
        /// Checks the spelling of the given string.
        /// </summary>
        private string SpellCheck(IWin32Window dialogOwner, string content, out string message)
        {
            var verifier = new SpellCheckerInlineVerifier(false, m_speller);
            var stringReplacement = new StringReplacement(content);

            int errorCount = 0;
            foreach (var spellError in m_controller.RemoveConflicts(verifier.VerifyText(content)))
            {
                ++errorCount;

                bool shouldBreak = false;
                string misspelledWord = content.Substring(spellError.Index, spellError.Length);

                string replacementWord;
                var dialogResult = SpellingErrorDialog.ShowForm(
                    dialogOwner, misspelledWord, spellError.Suggestions, out replacementWord);

                switch (dialogResult)
                {
                    case SpellDialogResult.Cancel:
                        shouldBreak = true;
                        break;
                    case SpellDialogResult.Change:
                        stringReplacement.Replace(spellError.Index, spellError.Length, replacementWord);
                        break;
                    case SpellDialogResult.ChangeAll:
                        stringReplacement.Replace(misspelledWord, replacementWord);
                        break;
                    case SpellDialogResult.Ignore:
                        break;
                    case SpellDialogResult.IgnoreAll:
                        m_speller.AddToIgnoreList(misspelledWord);
                        break;
                }

                if (shouldBreak)
                    break;
            }

            message = string.Format("تعداد خطاهای املایی: {0}",  ParsingUtils.ConvertNumber2Persian(errorCount.ToString()));
            return stringReplacement.Text;
        }