Interactive Parsing

version 3 by Jon Ingold

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 2 - Score verbs and suggest the best match


    Include (-

    Array recorded_search_values --> 4;

    [ SuggestVerb word_array run_to_halt
        i best_yet this_score ar j
        first_pass skipping_out
        k
        top_score start_word_list
        ;
        ! word_arrays runs WORDSIZE -> WORDSIZE + word_array-->0 - 1

        best_yet = 0;
        
        switch(word_array-->0)
        {
            1:
                ! 65-90 = A to Z
                ! 97 - 122 = a to z
                i = word_array->WORDSIZE;
                if (i >=65 && i <= 90) i = i + 32;
                (+ initial verb letter +) = i;
                (+ suggest verb from single letter rule +)();
                best_yet = (+ verb suggestion +);
                previous_suggestion_best_score = BASE_LINE_MATCH_SCORE + 1;
                current_analysis_stage = PERFORMED;

    !glk_set_window((+main-window+).ref_number);
    !print "Suggesting a verb...", (string) (+ verb suggestion +);

            !2:
                
            default:
                
                
                skipping_out = false;

                if (current_analysis_stage == PENDING)
                {
                    best_yet = 0;
                    top_score = previous_suggestion_best_score;
                    start_word_list = 1;
                    current_analysis_stage = PROCESSING;

                ! print "Setting up a new run-through...^^";
                
                }
                else
                {
                    ! we're picking up a search in progress
                    
                    top_score = recorded_search_values-->0; !PRERECORDED TOP SCORE;
                    best_yet = recorded_search_values -->1; ! PRERECORDED BEST YET;
                    start_word_list = recorded_search_values -->3; !PRERECORDED DICTIONARY POSITION;

            ! print "Picking up the previous run-through with top_score = ", top_score, " best_yet = ", (address) best_yet, " start_pass_number = ", start_pass_number, " and start_dict_position = ", start_dict_position, " word_understood_to = ", word_understood_to , "...^^";
                
                }

                for (j = start_word_list : j <= word_for_verb_list-->0 && ~~skipping_out : j ++)
                {
                
                    if (~~run_to_halt) k++;
                        
                    this_score = CompareWithDictionaryWord(word_array, word_for_verb_list-->j);

                    if (this_score > top_score)
                    {
                        top_score = this_score;
                        best_yet = word_for_verb_list-->j;
                    }
                    else if (this_score == top_score && top_score > 0)
                    {
                        ! we've found a tie. TODO: Do something with this information?
                        if (word_array-->0 == 1)
                            best_yet =-1;
                            ! if one letter only, we use this info to wipe the suggestion
                    }
                    
                    
                    if (k > MAX_TESTS)
                    {
                        skipping_out = CheckForExitCondition(k); k = 0;
                    }

                }

                ! record data

                ! *** if we're exiting mid-search, we return here, and miss out the next few steps
                if (skipping_out)
                {
                    recorded_search_values --> 3 = j; !RECORD J (DICT POSITION)
                    recorded_search_values --> 1 = best_yet; !RECORD BEST YET
                    recorded_search_values --> 0 = top_score; !RECORD TOP SCORE
                
            ! print "Skipping out with top_score = ", top_score, " best_yet = ", (address) best_yet, " start_pass_number = ", pass_number, " and start_dict_position = ", j, " word_understood_to = ", word_understood_to , "...^^";
                    
                    rfalse;
                }

        }

        if (best_yet > 0)
        {
            prompted_word = best_yet;
            previous_suggestion_best_score = top_score;
        }
        
        if (current_analysis_stage == PROCESSING)
        {
            current_analysis_stage = PERFORMED;
        }

    ];


    -).