Interactive Parsing

version 3 by Jon Ingold

  • Home page
  • Beginning
  • Previous
  • Next



  • Chapter 3 - Suggesting Non Verbs

    Include (-



    [ SuggestNonVerb word_array word_start_point input_buffer

                            alternate_suggestion_flag run_to_halt
                            
            ! run_to_halt indicates that we cannot leave this loop; we're here till we get an answer

        i best_yet this_score ar j k
        start_pass_number
        start_dict_position
        skipping_out
        pass_number top_score
        loop_start loop_end loop_incr loop_word
        max_word_score
        ;
    ! word_arrays runs 0-> word_length

    ! in this version, when we hit a tie we do nothing and stick with the result we have
    ! then (or rather, before) we use WordInScope to push sensible word choices
    ! through the system first, in the hope of preventing parser checks on stupider words.

        
    ! glk_set_window((+main-window+).ref_number);
    ! print "(Analyse)^";

        max_word_score = MaxPossibleScore(word_array-->0);

        skipping_out = false;

        if (current_analysis_stage == PENDING)
        {
            best_yet = 0;
            top_score = previous_suggestion_best_score;
            
            start_pass_number = 0;
            start_dict_position = dictstart;

            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_pass_number = recorded_search_values --> 2; !PRERECORDED PASS NUMBER;
            start_dict_position = 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 , "...^^";
        
        }
        

    !glk_set_window((+main-window+).ref_number);
    !for (i = 0: i< word_length: i++) print (char) word_array->i;
    !print "Current score to beat: ", top_score, "^";

        
    for (pass_number = start_pass_number: pass_number < 2 && skipping_out == false: pass_number++)
    {

        if (pass_number == 0)
        {
            loop_start = 1;
            loop_end = word_in_scope_list-->0 + 1;
            loop_incr = 1;
        } else {

    ! glk_set_window((+main-window+).ref_number);
    ! print "Current: ", (address) best_yet, " with score ", top_score, " against max ", 1 + word_length * MAX_LET_DIST + FIRST_LETTER_BOOST, ".^";
            
            if (top_score == max_word_score)
            {
                !glk_set_window((+main-window+).ref_number);
                !print "Found a maximum score in the word in scope part.^";
                break;
            }

            loop_start = start_dict_position;
            loop_end = dictstart + dictlen * entrylen;
            loop_incr = entrylen;
        }

    ! for (j = start_dict_position : j < dictstart + dictlen * entrylen && skipping_out == false : j = j + entrylen)
        for (j = loop_start : j < loop_end && skipping_out == false : j = j + loop_incr)
        {
            

            if (PreviousParseResult(j) ~= -1)
            {

        ! print "^Pass No. = ", pass_number, " ", (address) j, " tested ";
                if (~~run_to_halt) k++;

                if (pass_number == 0)
                {
                    loop_word = word_in_scope_list-->j;
                    this_score = 1 + CompareWithDictionaryWord(word_array, loop_word);
                    
                    !CheckWordDist(word_array, word_length, loop_word, top_score ) + 1; ! plus one, as we know it's in the list
                } else {
                    loop_word = j;
                    this_score = CompareWithDictionaryWord(word_array, loop_word);

        ! slight boost for actual nouns
                    this_score = this_score + (WordType(j) == EX_NOUN && ~~CheckCompassWords(loop_word));
                }

        ! print " and gets a score ", this_score;

                if (this_score > top_score)
                {
        
                    !print "Score for ", (address) j, " = ", this_score, " vs ", top_score, ".^";
                }
        
                if ( !!this_score > 2 * word_length + 1 + 2 * (1 - pass_number) &&
                        this_score > top_score
                             && WordImprovesParsing(input_buffer, loop_word, word_start_point, word_array-->0, alternate_suggestion_flag))
                {
        ! glk_set_window((+main-window+).ref_number);
        ! print "Scoring up for ", (address) j, ".^";
        
                    top_score = this_score;
                    best_yet = loop_word;
                }

            
                if (k > MAX_TESTS)
                {
                    skipping_out = CheckForExitCondition(k); k = 0;
                }


            }
        }
    }



        ! *** if we're exiting mid-search, we return here, and miss out the next few steps
        if (skipping_out)
        {
            recorded_search_values --> 2 = pass_number - 1; !RECORD PASS NUMBER
                                                        ! -1, because when we drop out of the inner loop, we get a +1 on the outer loop!!
            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;
        }

    ! print "Completed!^^";
        
        if (best_yet > 0)
        {
            prompted_word = best_yet;
            previous_suggestion_best_score = top_score;
        }
        
        if (current_analysis_stage == PROCESSING)
        {
            current_analysis_stage = PERFORMED;
        }


    ];

    -)