Home > X++ stuffs > AX Spell Checker Suggestion

AX Spell Checker Suggestion

 

“SysSpellChecker” as the name suggest checks the spelling mistake and provides you with the list of spellings that may be useful or applicable.

Sample job is illustrated using SysSpellChecker class. AX spell checker class is integrated with Word where methods like below are provided by COM classes.

·         activeSpellingDictionary

·         Checkspelling

·         getSpellingSuggestions

static void SysSpellChecker_AX(Args _args)

{

    SysSpellChecker    sysSpellChecker;

    container             spellings;

    ListEnumerator    listEnumerator;

    List                     spellingsSuggestions;

    int                       i;

    ;

 

    spellings = [‘Tble’, ‘Comput’, ‘Mcrosft’, ‘Rlease’];

 

    // Get AX –> Current Language id

    // Construct the sysSpellChecker object.

    sysSpellChecker = SysSpellChecker::newCurrentDocumentationLanguage();

 

    startLengthyOperation();

 

    for(i=1; i<= conlen(spellings); i++)

    {

        if(! sysSpellChecker.checkSpelling(conpeek(spellings, i)))

        {

            spellingsSuggestions = sysSpellChecker.getSpellingSuggestions(conpeek(spellings, i));

            listEnumerator         = spellingsSuggestions.getEnumerator();

 

            while(listEnumerator.moveNext())

            {

                print "Suggested Spellings are:" + listEnumerator.current();

                pause;

            }

        }

    }

    sysSpellChecker.finalize();

 

    print "Your done with Spell check.";

    pause;

 

   endLengthyOperation();

}

 

 Above example is shown using AX class. But using COM class we can still get the suggested spellings if it’s incorrect.

static void SpellChecker_COM_Word(Args _args)

{

    System.Globalization.CultureInfo cultureInfo;

 

    COM                              wordDocs;

    COM                              languages, language;

    COM                              dictionaries;

    COM                              word;

    COM                              languageDictionary;

    COM                              customDictionary;

    COM                              suggestionsObj;

    COM                              suggestion;

 

    List                               suggestions    = new List(Types::String);

    ListEnumerator              listEnumerator;

 

    int                                  lines = infolog.line();

    int                                  languageId;

    int                                  i;

 

    Session                          session = new Session(sessionid()) ;

 

    void initDictionary(LanguageId _language)

    {

        Set dictionary;

        ;

 

        dictionary = new Set(Types::String);

 

        dictionary.add(‘Axapta’);

        dictionary.add(‘MorphX’);

        dictionary.add(‘Microsoft Dynamics AX’);

        dictionary.add(‘Damgaard’);

        dictionary.add(‘nbsp’);      //HTML nonbreakable space

 

        if (_language == ‘En-Us’)

        {

            //Often used words added to speed up checking

            dictionary.add(‘is’);

            dictionary.add(‘isn’);

            dictionary.add(‘has’);

            dictionary.add(‘hasn’);

            dictionary.add(‘was’);

            dictionary.add(‘wasn’);

            dictionary.add(‘then’);

            dictionary.add(‘a’);

            dictionary.add(‘in’);

            dictionary.add(‘the’);

            dictionary.add(‘this’);

            dictionary.add(‘not’);

            dictionary.add(‘can’);

        }

    }

 

    cultureInfo  = new System.Globalization.CultureInfo(session.interfaceLanguage());

    languageId  = cultureInfo.get_LCID();

 

    if (!word)

    {

        try

        {

            word = new COM(‘Word.Application’);

        }

        catch (Exception::Internal)

        {

            infolog.clear(lines);

            throw error("@SYS74320");

        }

    }

 

    //Need to add a document or else Word97 will fail

    //the calls to Application.GetSpellingSuggestions

    wordDocs = word.documents();

    wordDocs.add();

    word.windowState(0);

    initDictionary(session.interfaceLanguage());

 

    try

    {

        languages                 = word.languages();

        language                  = languages.item(languageId);

        languageDictionary   = language.activeSpellingDictionary();

        dictionaries              = word.customDictionaries();

        customDictionary      = dictionaries.activeCustomDictionary();

 

        suggestionsObj         = word.getSpellingSuggestions(‘Speling’,

                                                                                    customDictionary,

                                                                                    languageDictionary);

        for (i=1; i<=suggestionsObj.count(); i++)

        {

            word.checkspelling(‘Speling’, customDictionary, true, languageDictionary);

            suggestion = suggestionsObj.item(i);

            suggestions.addEnd(suggestion.name());

        }

 

        listEnumerator = suggestions.getEnumerator();

        while(listEnumerator.moveNext())

        {

            print "Suggested Spellings are:" + listEnumerator.current();

            pause;

        }

 

        word.quit();

    }

    catch (Exception::Internal)

    {

        infolog.clear(lines);

        throw error(strfmt("@SYS84011", session.interfaceLanguage()));

    }

}

 

Happy Spell check dAXing.

Advertisements
Categories: X++ stuffs
  1. Santosh.
    November 11, 2009 at 8:18 pm

    Mm…thx anna…As usual i\’m always becoming active blogger by seeing you[:)]

  2. Santosh Kumar
    November 11, 2009 at 6:15 pm

    Good one Santhu…Simply Superb 🙂

  3. Santosh.
    November 11, 2009 at 5:45 pm

    Hey tanky!!! Anitu….You ppl are constantly encouraging me so i cum up with such small and useful stuffs in AX

  4. Anitha
    November 11, 2009 at 5:41 pm

    As always .. informative.. :)Awesum !!!

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: