This is a migrated thread and some comments may be shown as answers.

RadSpell not catching simple spelling errors

2 Answers 51 Views
Spell
This is a migrated thread and some comments may be shown as answers.
Martha
Top achievements
Rank 1
Martha asked on 11 Sep 2012, 03:15 PM
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 Answers, 1 is accepted

Sort by
0
Martha
Top achievements
Rank 1
answered on 12 Sep 2012, 02:18 PM
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;
        }
    }
}
0
Rumen
Telerik team
answered on 13 Sep 2012, 03:07 PM
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.
Tags
Spell
Asked by
Martha
Top achievements
Rank 1
Answers by
Martha
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or