Assignment 2: Applications of Pattern Matching and Production Systems
CSE 415: Introduction to Artificial Intelligence
The University of Washington, Seattle, Winter 2005
The reading for this assignment is Chapters 3 in The Elements of Artificial Intelligence With Python. Part I of the text (Chapters 1-3) is available at the Copy Center in the basement of the Communications Building, starting Tuesday morning, January 4.
Part A (required). Do exercise 12 (on page 94) of The Elements of Artificial Intelligence With Python. Point value: 100 points. Your solution should follow these guidelines:
  • You are welcome to use rules from the Shrink.py program, but each rule must be modified so that the response will be different.
  • Incorporate the memory feature (discussed in lab) into your agent. Make it work in a manner consistent with the character of your agent. (10 points).
  • Incorporate the cycle feature (discussed in lab) into your agent. At least 3 of your agent's rules should use this feature with at least 2 alternative reponses each. (10 points)
  • Make up at least one rule that uses a random-choice feature to select a response form. (10 points)
  • There should be at least 15 rules in your program.
  • Your program should be ready to use as a module in another program that runs your agent with another agent in a dialog. The interface will consist of three functions that you need to write: one called introduce(), one called respond(theInput), and called agentName().

    The introduce() function should return a string representing a message that tells the name of the agent, what the agent represents and the name and UWNetID of you the programmer. For example, it might return a string containing:

    My name is Rusty Sales, and I sell junky cars.
    I was programmed by Jenny Chrysler. If you don't like
    the way I deal, contact her at jchrysler@u.
    How can I help you?
    
    The respond function should work almost the same way as the one in Shrink.py. But there are two important differences. First, the function will take one argument: the input string. It should compute the wordlist and mapped_wordlist values at the beginning of the function body instead of receiving those as inputs as in Shrink.py. Second, instead of printing out its response, your respond function should return it as a string. This will allow the other agent to receive it as input in the joint-dialog program.

    The agentName function should return (as a string) a short nickname for your agent. This will be useful in printing out a prompt-like identifier when showing lines of a conversation among different agents. For example, the function might return Rusty for example above.

    You can test out your compliance to this interface by downloading the test harness programs.

  • Name your file in the following way, so that we can keep track of the different agents: YourUWNetID.py, where YourUWNetID represents your UWNetID code (i.e., your email user name within the u.washington.edu domain. For one thing, this will guarantee that each of our agents is implemented in a file with a unique name. It will also give the graders an easy way to find your agent within a group, if needed.

Due Friday, January 20. Your code should be turned in online by 11:30 AM (one hour before lab). A session transcript hardcopy is due at the beginning of lab. This should be a printout showing a session with your character, plus a printout of your source code. The session should have between 15 and 25 turns. (One turn is a cycle consisting of a prompt from the system, the user's input, and the system's response.) Each of your rules should come into play in this session.

Provide a comment in the code for each of your production rules. Turn in your code online here.
 

Part B (extra credit). Do as many of the following optional problems as you wish. The maximum amount of extra credit you can get is 10 points.
  1. (5 points, easy; Due Jan 20 at the beginning of lab.) Extend the program Roman2.py to handle Roman numerals conversion up to 3999. For this option, turn in hardcopy of both your source code and a transcript of a session that illustrates all of the new rules.
  2. (10 points, difficult; due Jan. 27 at the beginning of lab, and you may do this problem in partnerships, if you wish, with each partner getting up to 10 points of extra credit.) Write a Python program that analyzes algebra word problems and solves them. This program will have the following parts.
    1. Reading in the problem.  The problem should be read in
    as a piece of English text represented as a string.
    The general form of the problem will be "If (problem information)
    then (specific question).
    
    2. Separating the problem information from the specific
    question to be answered.
    
    3. Extracting a list of rough equations from the problem information
    
    4. Identifying variables and replacing phrases by the variables
    in the rough equations.
    
    5. Parsing the equations and building nested lists to represent
    the right-hand sides of the equations.
    
    6. Applying a set of production rules to solve for the unknown.
    
    7. Reporting the answer.
    
    Partial extra credit is available, too: Completing 1-4 only is worth 5 points. Completing 6 and 7 only is worth 5 points. More details will be given later.

    Here is an example of input to the program. The string is broken here for display purposes. You should not assume any particular line breaks.

    If the area of a circle is pi times the square of the radius
    and the radius is 10 meters
    then what is the area of the circle?
    
    The main output for this example should be something like this:
    The area of the circle is 314.159265.
    
    The problem information consists of the material between "If" and "then". The specific question consists of the material between "then" and "?". The rough equations are the components of the problem information that are separated by occurrences of "and". Each rough equation has the form: [variable phrase] ["is" or "equals"] [expression], and [unit] component such as "meters" is optional. In the given example, there are two rough equations. The first variable phrase is "the area of a circle is pi times the square of the radius", and this breaks down into a variable phrase: "the area of a circle" and an expression "pi times the square of the radius". The second rough equation is "the radius is 10 meters". The variable phrase for this one is "the radius" and the expression is "10". There is also a unit component, "meters".

    The parsing of the expressions (right-hand sides of equations) can assume that these are simple expressions involving only a limited set of operators and a limited set of forms, such as described by the following rules:

    An expression is either an individual term, a sum of two terms or a difference of two terms.

    A term is either a factor, a factor times a factor, or a factor divided by a factor.

    A factor is either an atom or a function applied to an atom.

    An atom is either a number, a variable, or a constant.


Here is a link to the class's collection of agents