Interactive Parsing

version 3 by Jon Ingold

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 2 - Does a word replacement help the parser?

    [
        Here's the clever bit. Stitch a suggestion into the input, run the parser, and see if it matches more words than the line did without that word. If it does, this word is worth suggesting.

        We store results of this, because it's the slowest part of the whole deal.

        Would be good to optimise this section more; for example, the game will do the same Scope calculations over and over again.
    ]


    Include (-

    [ WordImprovesParsing input_buffer new_word word_start_point word_length
        alternate_suggestion_flag
        result
        ;
        ! a cheeky lookahead
        ! if we replace the new_word for the wordnum, does the parser improve on the word_understood_to count?
        
    ! glk_set_window((+main-window+).ref_number);
    ! print "Scoring up for ", (address) new_word, ".^";
    ! print "Previous score for word_understood_to is ", word_understood_to, ".^";



        switch(PreviousParseResult(new_word))
        {
            1: rtrue;
            -1: rfalse;
            0:
                
                BuildSecondBuffer(input_buffer, word_start_point, word_length, new_word);
                
    ! glk_set_window((+main-window+).ref_number);
    ! print "Considering NEW ", (address) new_word, "...^";
                result = AdvanceParseFromSecondBuffer();
                if (result > word_understood_to || (result == word_understood_to && alternate_suggestion_flag))
                {
                    if (previous_checks_passed-->0 < MAX_PREVIOUS_CHECKS)
                    {
                        
                        (previous_checks_passed-->0)++;
                        previous_checks_passed-->(previous_checks_passed-->0) = new_word;

                    }
                    rtrue;
                    
                } else {
            
                    if (previous_checks_failed-->0 < MAX_PREVIOUS_CHECKS)
                    {
                        (previous_checks_failed-->0)++;
                        previous_checks_failed-->(previous_checks_failed-->0) = new_word;
                    }
                    rfalse;
                    
                }
                
        }

    ];

    -).