[Next] [Up] [Previous]
Next: Exercises Up: Appendix: Representing Knowledge Previous: Using Variables in Patterns

Reviewing the answer Procedure

With the behaviour of the list pattern-matching variables explained, we shall summarize how the answer procedure works. In brief, the procedure takes as input a tourist's enquiry, processes the question by searching its database, and produces and answer as output. In the course of this operation, the procedure links up no less than six different lists or list-patterns. These are

  1. the list given as the initial question,
  2. a matching query-pattern picked up by one of answer's if ... then clauses,
  3. the associated database search pattern,
  4. the actual database entry,
  5. the response pattern used to build up the answer to the input question, and
  6. the answer itself.

We can thus divide the working of the procedure into five steps, as follows:

  1. A question, in the form of a list, is given as an argument to the procedure, for example:

        answer([what is the closest underground station
    
                to the science museum])=>
  2. The enquiry is matched to a question pattern, in one of the if ...then clauses (the last one in the version of answer shown earlier). In the course of this matching, some variables in the question pattern will acquire values. Thus, the above question matches the pattern

    [what == underground station to ??x]

    The double-equals matches the words `is the closest' and this information is discarded. The pattern-variable ??x matches the words `the national gallery', so the variable x is set to the list [the science museum].

  3. An associated pattern is used to search the database. In this case, the search pattern will be

      [^x underground ?y]

    The search pattern can be partially filled out, using the value assigned to x:

    [[the science museum] underground ?y]

    A matching database entry is found, using present. In this case the database entry is

    [[the science museum] underground [south kensington]]

    This results in the variable y being given the value [south kensington].

  4. The response pattern is then used to build up the final response. In this case the response pattern is

    [the nearest underground station to ^^x is ^^y]

    Since both x and y how have lists as their value, the items in these lists (without the outer brackets) are inserted into the slots in the answer pattern.

  5. The final result is returned by answer and is printed out. So, given our original question, the printed output is

    ** [the nearest underground station to the science museum is south kensington]

[Next] [Up] [Previous]
Next: Exercises Up: Appendix: Representing Knowledge Previous: Using Variables in Patterns

Cogsweb Project: luisgh@cogs.susx.ac.uk