RadSpell not catching simple spelling errors

3 posts, 0 answers
  1. Martha
    Martha avatar
    26 posts
    Member since:
    Aug 2011

    Posted 11 Sep 2012 Link to this post

    I'm using the latest reease (RadControls for ASP.NET AJAX Q2 2012 SP1) and it is not catching simple spelling errors (like goodby, thimg, etc.) Is there something wrong with the en-US.tdf dictionary??
    I have attached a screen print.
  2. Martha
    Martha avatar
    26 posts
    Member since:
    Aug 2011

    Posted 12 Sep 2012 Link to this post

    OK so I've given up on using the dictionary that comes with RadSpell becase it definitely has problems.

    I've implemented the MSWord Spell Check provider & it works much better & I still have the ability to use a custom dictionary.
    But... it has a problem with the word 'the' when it is the first word in the text and the word that follows it has a spelling error. What's going on here?
    I have attached a couple of screen prints to give you an idea of what's happening.

    BTW I had to modify the example posted in the forum here:
    http://www.telerik.com/community/forums/aspnet-ajax/spell/enabling-ms-word-spell-checking.aspx
    I had to change ApplicationClass to Application to work with the newer version of Word.
    Here is the new WordSpellCheckProvider:
    /// <summary>
    /// MS Word Spell Checking Provider for RadSpell (ASP.NET AJAX version)
    /// </summary>
    public class WordSpellCheckProvider : ISpellCheckProvider
    {
        private WordIgnoreOptions _wordIgnoreOptions;
        private Application application = new Application();
        private Document document;
        private string _language = "en-US";
        private object missing = Missing.Value;
        private List<string> customWords = new List<string>();
        public WordSpellCheckProvider()
        {
            this.application.Visible = false;
            this.CreateDocument();
        }
     
        public WordSpellCheckProvider(Telerik.Web.UI.SpellChecker checker)
            : this()
        {
            if (checker.DictionaryLanguage != string.Empty)
            {
                Language = checker.DictionaryLanguage;
            }
            this.WordIgnoreOptions = checker.WordIgnoreOptions;
            this.Text = checker.Text;
     
     
            //read custom dictionary
            checker.CustomDictionarySource.DictionaryPath = HttpContext.Current.Server.MapPath("~/App_Data/RadSpell/");
            checker.CustomDictionarySource.CustomAppendix = checker.CustomAppendix;
            checker.CustomDictionarySource.Language = checker.DictionaryLanguage;
            string customWord = checker.CustomDictionarySource.ReadWord();
            customWords = new List<string>();
            while (!string.IsNullOrEmpty(customWord))
            {
                customWords.Add(customWord);
                customWord = checker.CustomDictionarySource.ReadWord();
            }
        }
     
        public bool CheckWord(ITextWord current, ITextWord previous)
        {
            if (this.CheckForRepeatWords && previous != null && (current.Word == previous.Word))
            {
                return false;
            }
            if (!this.CheckCapital && current.StartsWithUpper())
            {
                return true;
            }
            if (customWords.Contains(current.Word))
            {
                return true;
            }
            MicrosoftTextWord word = null;
            foreach (Range range in this.document.Words)
            {
                if (range.Text.Trim() == current.Word)
                {
                    word = new MicrosoftTextWord(range, Language);
                    break;
                }
            }
            return (word.Container.SpellingErrors.Count == 0);
        }
     
        public void Close()
        {
            if (this.application != null)
            {
                this.document = null;
                object saveChanges = null;
                this.application.Quit(ref saveChanges, ref saveChanges, ref saveChanges);
                this.application = null;
            }
        }
     
        private void CreateDocument()
        {
            Document document = this.application.Documents.Add(ref this.missing, ref this.missing, ref this.missing, ref this.missing);
            document.LanguageDetected = true;
            this.document = document;
        }
     
        ~WordSpellCheckProvider()
        {
            this.Close();
        }
     
        private SpellingSuggestions GetAppSuggestions(ITextWord word)
        {
            SpellingSuggestions suggestionsForRange = null;
            MicrosoftTextWord word2 = null;
            foreach (Range range in this.document.Words)
            {
                if (range.Text.Trim() == word.Word)
                {
                    word2 = new MicrosoftTextWord(range, Language);
                    break;
                }
            }
            if (word2 != null)
            {
                suggestionsForRange = this.GetSuggestionsForRange(word2);
            }
            return suggestionsForRange;
        }
     
        private string GetDocumentText()
        {
            if (this.document == null)
            {
                return string.Empty;
            }
            return this.document.Content.Text;
        }
     
        public string[] GetSuggestions(ITextWord word)
        {
            SpellingSuggestions appSuggestions = this.GetAppSuggestions(word);
            if ((appSuggestions == null) || (appSuggestions.SpellingErrorType == WdSpellingErrorType.wdSpellingCorrect))
            {
                return new string[0];
            }
            string[] strArray = new string[appSuggestions.Count];
            for (int i = 0; i < appSuggestions.Count; i++)
            {
                SpellingSuggestion suggestion = appSuggestions[i + 1];
                strArray[i] = suggestion.Name;
            }
            return strArray;
        }
     
        private SpellingSuggestions GetSuggestionsForRange(MicrosoftTextWord word)
        {
            Range container = word.Container;
            object ignoreUppercase = !this.CheckAllCaps;
            return container.GetSpellingSuggestions(ref this.missing, ref ignoreUppercase, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing);
        }
     
        private SpellingSuggestions GetSuggestionsForString(string word)
        {
            object ignoreUppercase = !this.CheckAllCaps;
            return this.application.GetSpellingSuggestions(word, ref this.missing, ref ignoreUppercase, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing, ref this.missing);
        }
     
        public ITextWord GetWord(int index)
        {
            return new MicrosoftTextWord(this.document.Words[index + 1], Language);
        }
     
        private void SetDocumentText(string text)
        {
            this.CreateDocument();
            Range content = this.document.Content;
            content.Text = text;
            content.LanguageID = MicrosoftTextWord.GetLanguage(Language);
        }
     
        // Properties
        private bool CheckAllCaps
        {
            get
            {
                return ((this.WordIgnoreOptions & Telerik.Web.UI.WordIgnoreOptions.UPPERCASE) == 0);
            }
        }
     
        private bool CheckCapital
        {
            get
            {
                return ((this.WordIgnoreOptions & Telerik.Web.UI.WordIgnoreOptions.WordsWithCapitalLetters) == 0);
            }
        }
     
        private bool CheckForRepeatWords
        {
            get
            {
                return ((this.WordIgnoreOptions & Telerik.Web.UI.WordIgnoreOptions.RepeatedWords) == 0);
            }
        }
     
        private bool CheckWordsWNumbers
        {
            get
            {
                return ((this.WordIgnoreOptions & Telerik.Web.UI.WordIgnoreOptions.WordsWithNumbers) == 0);
            }
        }
     
        [CLSCompliant(false)]
        public Document CurrentDocument
        {
            get
            {
                return this.document;
            }
        }
     
        public string Language
        {
            get
            {
                return _language;
            }
            set
            {
                _language = value;
            }
        }
     
        public string Text
        {
            get
            {
                return this.GetDocumentText();
            }
            set
            {
                this.SetDocumentText(value);
            }
        }
     
        public int WordCount
        {
            get
            {
                return this.document.Words.Count;
            }
        }
     
        public WordIgnoreOptions WordIgnoreOptions
        {
            get
            {
                return this._wordIgnoreOptions;
            }
            set
            {
                this._wordIgnoreOptions = value;
            }
        }
    }
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rumen
    Admin
    Rumen avatar
    12846 posts

    Posted 13 Sep 2012 Link to this post

    Hi,

    I was able to replicate the reported problem with the MSWordSpellCheck provider and logged it for investigation in our bug tracking system. Here you can find the PITS Issue: Public URL. I also updated your Telerik points.

    You can currently try the other available providers for RadSpell: Custom OpenOffice NHunspell provider and Custom Google spellcheck provider.

    Greetings,
    Rumen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top