Interactive Parsing

version 3 by Jon Ingold

  • Home page
  • Beginning
  • Previous
  • Next



  • Book 4 - Suggestions for an unfinished word

    Chapter 1 - Main Suggestion System

    Section 1 - Hub

    [ We use different algorithms for verbs and for nouns/preps. Verbs don't require use to run the parser at all! ]

    Include (-

    Array analysed_word_buffer -> DICT_WORD_SIZE + 1;

    [ CreateSuggestionForWord
        ! input_buffer : whole text input
        ! word_buffer : 0 indexed array holding characters typed so far
        ! length : number of characters (so use < length in loops)
        ! wordnum : the number of the word in the current line; we can use parse if it's helpful

        input_buffer word_buffer length wordnum run_to_halt

        ! current word's valid, but in the wrong context
        alternate_suggestion_flag
        ;

    ! glk_set_window((+main-window+).ref_number);
    ! print "Suggesting for word num = ", wordnum, "^";

        ! We allow the previous best score to be just as good again, otherwise the player can
        ! lose a good suggestion by typing an unhelpful letter

        ! but don't do this if we're mid-search
        if (current_analysis_stage == PENDING)
        {
            if (previous_suggestion_best_score > BASE_LINE_MATCH_SCORE)
                previous_suggestion_best_score--;
        }
        
        if (previous_checks_wordnum == 0)
            previous_checks_wordnum = wordnum;

        ! Flag that we consider matching *the same* number of words to be okay under the circumstances
        ! allows "Thesaurus" to win over "the"...
        alternate_suggestion_flag = (WordCount() == word_understood_to);
        
        CopyBufferWritingLength(word_buffer, analysed_word_buffer, length, DICT_WORD_SIZE);

        ! we always suggest verbs at word 1, even though you could talk to people. Them's the breaks.

    ! print "Verb wordnum = ", verb_wordnum, ".^";

        if ( next_token_type == EX_VERB || wordnum == verb_wordnum)
        {
    ! print "Suggesting verb-type.^";
                SuggestVerb(analysed_word_buffer, run_to_halt);
        } else
        {
                if (wordnum > word_understood_to + 1) ! eg. word 3 when word 2 failed and we knew word 1
                {
                    !glk_set_window((+main-window+).ref_number);
                    !print "Word ", word_understood_to + 1, " failed already so word ", wordnum, " isn't worth suggesting for.";
                    rfalse;
                }
                SuggestNonVerb(analysed_word_buffer, CharacterNumber(wordnum), input_buffer, alternate_suggestion_flag, run_to_halt);
        }

        ! repair the parse table after tests
        VM_Tokenise(input_buffer, parse);

        return (prompted_word > 0);

    ];

    -).