<HTML><HEAD><link type="text/css" href="../css/main_styles.css" rel="stylesheet"></HEAD>
<BODY><TITLE>%mqc_spell_check_annotations</TITLE><H1>%mqc_spell_check_annotations </H1><P CLASS="Paragraph">Classname: <B>%mqc_spell_check_annotations </B></P><P CLASS="Paragraph">Inherits from: <B><A href=..\checkmate\xug_base_checker.html>%ug_base_checker </A></B></P><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"> </PRE><PRE STYLE=\"text-align : left;\" CLASS=\"Code\">
<B>Description:</B>
    Spelling check of NX annotation objects in the part file.
    This checker will detect the possible spelling error words found in NX annotations,
    it will exclude the words listed in the default MS Word dictionary and/or
    customer specified dictionary.
    If show_tips is set to true, this checker will log the suggestion words in the results.
    It checks the text of notes, labels and dimensions and lists of
    the words not found in the dictionaries.
    For tabular note and parts list, it checks the text in the cells, and list the words
    not to be ignored (listed in the dictionary files).
    This checker does not support the languages with multi-byte characters set (MBCS).
    Such as Chinese, Japanese, Korean and some of German words (umlauts).
    The implementation is based on the Microsoft Word spelling check COM interface.
    It can ONLY run on the Windows platform with MS Word installed.
Parameters:
    ( Boolean )  disabled?  - If it is true, the checker is disabled.
                              Default is False.
    ( Boolean )  save_log_in_part
                              The flag indicates whether the checking results
                              can be saved to the part file.
                              Default is True.
    ( Name )     check_type - specify the type of annotation objects to check:
                                  All           - check spelling for all the following types,
                                  Note          - check spelling for notes,
                                  Label         - check spelling for labels,
                                  Tabular_Note  - check spelling for tabular notes,
                                  Dimension     - check spelling for dimension appended text,
                                  Parts_list     - check spelling for the parts lists,
                              Default is All.
    ( Boolean )  show_tips  - Whether or not to show spelling suggestions for target words.
                                 True    -  Show tips
                                 False   -  Not to show tips
                              Default is set to False, not to show tips.
    ( Boolean )  ignoreUppercase                              Ignore words in UPPERCASE or not
                              Default is False
    ( Boolean )  ignoreMixedDigits                              Ignore words with numbers or not
                              Default is False
    ( Boolean )  ignoreInternetAndFileAddresses                              Ignore Internet and file addresses or not
                              Default is False
    ( String )   custom_dictionary                              The custom dictionary contains the words to be ignored in
                              spelling check.
                              It is one word per line in the file.
                              For example, if 'prt' is to be ignored,
                              and is defined in a dictionary file,
                              all 'prt' found in the objects will be ignored.
    ( Boolean )  use_custom_dictionary_only                              Indicates whether or not to use custom dictionary exclusively.
                              True  - Only use the custom dictionary, and
                                      Ignore the default MS word dictionaries.
                              False - Use the custom dictionary plus the MS word
                                      dictionary when performing spell check.
                              Default is True.
    ( Name )     log_type   - Indicate which logging type to use to report the violation.
                                  LOG_ERROR
                                  LOG_WARNING
                                  LOG_INFO
                              Default is LOG_ERROR
Results:
    FAILED  - Any word found as possible spelling error, and it is not listed in the dictionary
              to be ignored.
              The detected entities will be logged with spelling error words and tips if show_tips
              is set to true.
    PASS    - No words are detected as spelling errors, or words detected but are ignored as they are
              listed in the dictionary.
</PRE><PRE><FONT COLOR= blue>DefClass: %mqc_spell_check_annotations( %ug_base_checker );
</FONT></PRE><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>   ( String )    %test_category:  "Spell Check";
   ( String )    %displayed_name: "Spell Check on Annotations";

</SPAN></FONT></PRE></DIV><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>   ( Boolean Parameter )    disabled?: false;
   ( Boolean Parameter )    save_log_in_part: true;
</SPAN></FONT></PRE></DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\">   Attributes for this class</PRE><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>   ( String )             check_type_label: "Entity Type";
   ( List )               check_type_init:  { Note, Label, Dimension, Tabular_Note, Parts_List };

</SPAN></FONT></PRE></DIV><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>   ( String )             show_tips_label: "Show Spelling Tips";
   
</SPAN></FONT></PRE></DIV><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>   ( String )             ignoreUppercase_label: "Ignore words in UPPERCASE";
   
</SPAN></FONT></PRE></DIV><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>   ( String )             ignoreMixedDigits_label: "Ignore words with numbers";

</SPAN></FONT></PRE></DIV><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>   ( String )             ignoreInternetAndFileAddresses_label: "Ignore Internet and file addresses";
   
</SPAN></FONT></PRE></DIV><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>   ( String )             use_custom_dictionary_only_label: "Check with Custom Dictionary Only";
   
</SPAN></FONT></PRE></DIV><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>   ( String )             custom_dictionary_label: "Custom Dictionary";

</SPAN></FONT></PRE></DIV><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>   ( List Parameter )     check_type:       { Note, Label, Dimension, Tabular_Note, Parts_List };
   ( Boolean Parameter )  show_tips:       False;
   ( Boolean Parameter )  ignoreUppercase: False;
   ( Boolean Parameter )  ignoreMixedDigits: False;
   ( Boolean Parameter )  ignoreInternetAndFileAddresses: False;
   ( Boolean Parameter )  use_custom_dictionary_only:       True;
   ( String Parameter )   custom_dictionary:       "";
   ( Name Parameter )     log_type:        LOG_ERROR;
</SPAN></FONT></PRE></DIV><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>   ( String )             log_type_label:  "Log Option";
   ( List )               log_type_option: { LOG_ERROR, LOG_WARNING, LOG_INFO };

   # For better performance, the internal function should be invoked only once to check all the collected words.
   # The checker will collect all the words from the NX annotations such as notes, labels, 
   # dimensions, tabular notes, tabular labels and parts lists. Then send them to MS Words to check.
   # 
   ( Any Uncached ) do_check:
   @{

       # get all notes and their texts
       $notes_info << If( Member(All, check_type:) | Member(Note, check_type:) )
                      Then mqc_ask_note_text:(Note)
                      Else {{}, {}};

       # get all labels and their texts
       $labels_info << If( Member(All, check_type:) | Member(Label, check_type:) )
                       Then mqc_ask_note_text:(Label)
                       Else {{}, {}};

       # get all dimensions and their texts
       $dims_info <<  If( Member(All, check_type:) | Member(Dimension, check_type:) )
                      Then mqc_ask_note_text:(Dimension)
                      Else {{}, {}};

       # get all tabular notes and their texts and their cell locations in table
       $tabular_notes_info << If( Member(All, check_type:) | Member(Tabular_Note, check_type:) ) 
                              Then mqc_ask_tabnot_text:(Tabular_note )
                              Else {{}, {}, {}};

       # get all parts list and their texts and their cell locations in table
       $parts_lists_info << If( Member(All, check_type:) | Member(Parts_List, check_type:) )
                            Then  mqc_ask_tabnot_text:(Parts_list)
                            Else {{}, {}, {}};

       # compile the words from the entities
       $sentences_list << mqc_make_sentences:( second($notes_info), 
                                               second($labels_info), 
                                               second($dims_info), 
                                               third($tabular_notes_info), 
                                               third($parts_lists_info) );

       $sentences        << first ($sentences_list);
       $sentence_indexes << second($sentences_list);

       # check spelling
       $spellingcheck_result << mqc_checkSentencesSpelling($sentences, 
                                    needTips?, show_tips:, 
                                    user_dictionary, custom_dictionary:,
                                    specified_dic_only?, use_custom_dictionary_only:,
                                    ignoreUppercase?,ignoreUppercase:,
                                    ignoreMixedDigits?,ignoreMixedDigits:,
                                    ignoreInternetAndFileAddresses?,ignoreInternetAndFileAddresses:);

       If( first($spellingcheck_result) = "No-Word" ) Then
           ug_mqc_log( log_type:, {}, "Microsoft Office Word was not Installed in this System." )
       Else
       @{
           # Log spelling check result for notes
           mqc_log_typo_notes:(nth(1, $notes_info), nth(1, $sentence_indexes), $spellingcheck_result);

           # Log spelling check result for labels
           mqc_log_typo_notes:(nth(1, $labels_info), nth(2, $sentence_indexes), $spellingcheck_result);

           # Log spelling check result for dimensions
           mqc_log_typo_notes:(nth(1, $dims_info), nth(3, $sentence_indexes), $spellingcheck_result);

           # Log spelling check result for tabular notes and tabular labels
           mqc_log_typo_tabnot:(nth(1, $tabular_notes_info), nth(2, $tabular_notes_info), nth(4, $sentence_indexes), $spellingcheck_result);

           # Log spelling check result for parts lists
           mqc_log_typo_tabnot:(nth(1, $parts_lists_info), nth(2, $parts_lists_info), nth(5, $sentence_indexes), $spellingcheck_result);
       };
   };


</SPAN></FONT></PRE></DIV><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>(Method List) mqc_ask_note_text:( Name $note_type )
@{
    $note_type_tags  << mqc_selectEntitiesWithFilters(select_by_entity_type, {$note_type});

    Loop
    {
        For $each_tag in $note_type_tags;

        For $each_text is
            If( ($note_type = Note) | ($note_type = Label) ) 
            Then mqc_askNoteText($each_tag)
            Else If ( $note_type = Dimension ) 
            Then
            @{
                 $dimension_text_list << mqc_askDimensionText($each_tag);

                 $text_list << Loop
                 {
                     For $each_text_list in $dimension_text_list;

                     If (-Empty?($each_text_list))
                     Append { first($each_text_list) };
                 };

                 { mqc_list_to_string($text_list, " ") };
            }
            Else { "" };

        For $isNullString? is ( first($each_text) = "" );

        Append If( $isNullString? ) Then {} Else {$each_tag} Into $tags;
        Append If( $isNullString? ) Then {} Else $each_text  Into $texts;

        Return is {$tags, $texts};
    };
};


</SPAN></FONT></PRE></DIV><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>(Method List) mqc_ask_tabnot_text:(Name $tabular_type)
@{
    $tabnot_tags << mqc_selectEntitiesWithFilters( select_by_entity_type, {$tabular_type} );

    Loop 
    {
       For $each_tag          in $tabnot_tags;
       For $cells_and_texts   is If( ($tabular_type = Tabular_note) | ($tabular_type = Parts_list) ) 
                                 Then mqc_askTabularNoteText($each_tag)
                                 Else {};
       For $cells_and_texts_2 is Loop
       {
           For $each_cell in $cells_and_texts;

           Append If( -empty?($each_cell) ) {{second($each_cell), third($each_cell)}} Else {} Into $cell_locations2;
           Append If( -empty?($each_cell) ) {first($each_cell)} Else {} Into $cell_texts2;

           Return is {$cell_locations2, $cell_texts2};
       };

       Append If( -empty?($cells_and_texts) ) {$each_tag}                  Else {} Into $tags;
       Append If( -empty?($cells_and_texts) ) {first($cells_and_texts_2)}  Else {} Into $cell_locations;
       Append If( -empty?($cells_and_texts) ) {second($cells_and_texts_2)} Else {} Into $cell_texts;

       Return is { $tags, $cell_locations, $cell_texts };
    };
};


</SPAN></FONT></PRE></DIV><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>(Method List) mqc_make_sentences:( List $note_texts, 
                                   List $label_texts, 
                                   List $dimension_texts, 
                                   List $tabular_note_texts, 
                                   List $parts_list_texts)
@{
    $sentences << flatten( { $note_texts, $label_texts, $dimension_texts, 
                             flatten($tabular_note_texts), 
                             flatten($parts_list_texts) } );

    $sentence_indexes <<
    @{
        # { start index, end index } of sentence of note, label, dimension.
        $note_indexes  << {1, length($note_texts)};
        $label_indexes << {second($note_indexes)  + 1, second($note_indexes)  + length($label_texts)};
        $dim_indexes   << {second($label_indexes) + 1, second($label_indexes) + length($dimension_texts)};

        # start index of sentence of tabular note
        $ts << second($dim_indexes);
        
        # start index of sentence of parts list
        $ps << $ts + length(flatten($tabular_note_texts));

        $tabnot_indexes <<  Loop 
        {
            With $indexes Is {};

            For $each_sentence_list in $tabular_note_texts;
            For $sentence_num is length( $each_sentence_list );            
            For $tabnot_index Is {1 + $ts, $sentence_num + $ts} Then
            @{ 
               $end_index << second(Last($indexes)); 
               {$end_index + 1 , $end_index + $sentence_num}; 
            };
            Collect  $tabnot_index  Into  $indexes;
            Return Is $indexes;
        };
        
        $parts_list_indexes << Loop 
        {
            With $indexes Is {};

            For $each_sentence_list in $parts_list_texts;
            For $sentence_num       is length( $each_sentence_list );
            For $tabnot_index       is {1 + $ps, $sentence_num + $ps} Then
            @{ 
               $end_index << second(Last($indexes));
               {$end_index + 1 , $end_index + $sentence_num}; 
            };
            Collect  $tabnot_index  Into  $indexes;
            Return Is $indexes;
        };

        { $note_indexes, $label_indexes, $dim_indexes, $tabnot_indexes, $parts_list_indexes };
    };

    { $sentences, $sentence_indexes };
};


</SPAN></FONT></PRE></DIV><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>(Method Any) mqc_log_typo_notes:(List $tags, List $indexes, List $spellingcheck_result )
@{
    # a list of the error note
    # { 
    #      { tag1, tag2, ...}, -->note tags which have spelling error words.
    #
    #      {
    #          {
    #            {"word", "tip1", "tip2", ...}, 
    #            {},
    #            ...
    #          },  --> error word and its tips in tag1 note.
    #          {
    #            {},
    #            ...
    #          },  --> error word and its tips in tag2 note.
    #          ...
    #      }
    # }
    $tags_words_tips << Loop 
    {
        With $si                      is nth(1, $indexes);
        With $error_tags              is {};
        With $error_word_and_its_tips Is {};
        
        For $iter from nth(1, $indexes) to nth(2, $indexes);
        For $isNullList? is empty?(nth($iter, $spellingcheck_result));
        
        Append If($isNullList?) Then {} Else {nth($iter - $si + 1, $tags)} into $error_tags;
        Append If($isNullList?) Then {} Else {nth($iter, $spellingcheck_result)} into $error_word_and_its_tips;
        
        Return is { $error_tags, $error_word_and_its_tips };
    };
    
    $error_num << Length(First($tags_words_tips));
    If ($error_num <= 0) Then
        Donothing
    Else 
    @{
        Loop
        {
            For $tag_iter from 1 to length(first($tags_words_tips));
            For $each_tag is nth($tag_iter, first($tags_words_tips));
            For $words_tips is nth($tag_iter, second($tags_words_tips));
            For $word_tips_strings is Loop
            {
                For $word_iter from 1 to length($words_tips);
                For $word_tips is nth($word_iter, $words_tips);
                For $word is first($word_tips);
                For $tips is  Sublist($word_tips,2,Length($word_tips));
                For $tips_string is 
                    If (show_tips: & Empty?($tips))
                    Then "No tips"
                    Else mqc_list_to_string($tips, ",");
                For $word_tips_string is "~t"+$word+@{If ($tips_string="") Then "" Else "~t - "+$tips_string+".";};
                Append { $word_tips_string };
            };

            For $words_tips_string is mqc_list_to_string($word_tips_strings, "~n");
            Do  ug_mqc_log_object_detail( log_type:, {$each_tag}, $words_tips_string);
        };
    };
};


</SPAN></FONT></PRE></DIV><DIV><PRE STYLE=\"text-align : left;\" CLASS=\"Code\"><FONT COLOR=blue>(Method Any) mqc_log_typo_tabnot:(List $tags, List $cell_locations, List $indexes, List $spellingcheck_result )
@{
    # a list of the error table.
    # { 
    #      { tag1, tag2, ...}, -->table tags which have spelling error words.
    #
    #      {
    #          {{2,1}, {3,5}, ...},         -->locations of cells which have a string in tag1 tabular note.
    #          {{1,2}, {3,4}, {5,1}, ...},  -->locations of cells which have a string in tag2 tabular note.
    #          ...
    #      },
    #
    #      {
    #          {
    #            {
    #              {"word", "tip1", "tip2", ... }, 
    #              {},
    #              ...
    #            },  --> error word and its tips of cell [2,1] in tag1 tabular note.
    #            {
    #              {},
    #              {},
    #              ...
    #            },  --> error word and its tips of cell [3,5] in tag1 tabular note.
    #            ...
    #          },  -->tag1 tabular note's spelling check result.
    #          {
    #            ...
    #          },  -->tag2 tabular note's spelling check result.
    #          ...
    #      }
    # }
    $tags_cells_words_tips << Loop 
    {
        For $tag_iter from 1 to length($tags);
        For $each_tag            Is nth($tag_iter, $tags);
        For $each_cell_locations Is nth($tag_iter, $cell_locations);
        For $each_index          Is nth($tag_iter, $indexes);
        For $cell_locs_and_words_tips Is Loop 
        {
            For $word_iter from first($each_index) to second($each_index);
            For $word_and_its_tips Is nth($word_iter, $spellingcheck_result);
            For $cell_with_error?  Is -empty?($word_and_its_tips);

            Append If($cell_with_error?) 
                   Then {nth($word_iter - first($each_index) + 1, $each_cell_locations)} 
                   Else {} 
                   Into $cell_locs_with_error;
            Append If($cell_with_error?) 
                   Then {$word_and_its_tips} 
                   Else {} 
                   Into $error_word_tips;
            
            Return is {$cell_locs_with_error, $error_word_tips};
        };
        
        For $cell_locs_of_each_tag is first($cell_locs_and_words_tips);
        For $words_tips_of_each_tag is second($cell_locs_and_words_tips);
        For $isNullList? is empty?($cell_locs_of_each_tag);
        
        Append If($isNullList?) Then {} Else {$each_tag}               into $tags_with_error;
        Append If($isNullList?) Then {} Else {$cell_locs_of_each_tag}  into $cell_locs_with_error;
        Append If($isNullList?) Then {} Else {$words_tips_of_each_tag} into $words_and_tips;

        Return is { $tags_with_error, $cell_locs_with_error, $words_and_tips };
    };

    $error_num << Length(First($tags_cells_words_tips));
    If ($error_num <= 0)
    Then Donothing
    Else 
    @{
        Loop 
        {
            For $tag_iter from 1 to $error_num;
            For $each_tag is nth($tag_iter, first($tags_cells_words_tips) );
            For $cells_words_tips is { nth($tag_iter, second($tags_cells_words_tips) ), nth($tag_iter, third($tags_cells_words_tips) ) };
            For $cell_words_tips_strings is Loop 
            {
                For $cell_iter from 1 to length(first($cells_words_tips));
                For $each_cell is nth($cell_iter, first($cells_words_tips));
                For $words_tips is nth($cell_iter, second($cells_words_tips));
                For $word_tips_strings is Loop 
                {
                    For $word_iter from 1 to length($words_tips);
                    For $word_tips is nth($word_iter, $words_tips);
                    For $word is first($word_tips);
                    For $tips is  Sublist($word_tips,2,length($word_tips));
                    For $tips_string is 
                        If ( show_tips: & Empty?($tips) )
                        Then "No tips"
                        Else mqc_list_to_string($tips, ",");
                    For $word_tips_string is $word+@{If ($tips_string="") Then "" Else "~t - "+$tips_string+".";};
                    Append { $word_tips_string };
                };

                For $cell_words_tips_string is "~t["+stringvalue(nth(1, $each_cell))
                                               + ", "
                                               + stringvalue(nth(2, $each_cell))
                                               + "] "
                                               + mqc_list_to_string($word_tips_strings, "~n~t~t");
                Append {$cell_words_tips_string};
            };

            For $cells_words_tips_string is mqc_list_to_string($cell_words_tips_strings, "~n");
            Do  ug_mqc_log_object_detail( log_type:, {$each_tag}, $cells_words_tips_string);
        };
    };
};


</SPAN></FONT></PRE></DIV></TABLE><p class=EndLine>&nbsp;</p><p class=blank>&nbsp;</p></BODY></HTML>