CS 161 Lab #8

November 5th

Goals:

This week you'll make some changes to the TechSupport project from the book. We'll add the ability to map each of the user's input words to a "root synonym" before attempting to respond to them. This will eliminate the need for duplicate entries in the responseMap. (For example, there are identical responses for "crash" and "crashes" in the map.) It will also give you a chance to get more familiar with maps, and to explore the TechSupport project in more detail.

Directions:

  1. Download the TechSupport project and extract its contents, then start BlueJ and open the project.
  2. Take a moment to familiarize yourself with the project. This is the same code we went through in class, with the exception of the new SynonymMapper class that you'll be working with. You should be able to compile and run the project in its current state:

    > SupportSystem s = new SupportSystem();
    > s.start();
    Welcome to the DodgySoft Technical Support System.
    
    Please tell us about your problem.
    We will assist you with any problem you might have.
    Please type 'bye' to exit our system.
    > I think your software is buggy!
    Well, you know, all software has some bugs. But our software engineers
    are working very hard to fix them. Can you describe the problem a bit
    further?
    > It crashes when I try to open a file.
    Well, it never crashes on our system. It must have something
    to do with your system. Tell me more about your configuration.
    > It didn't used to crash.
    Well, it never crashes on our system. It must have something
    to do with your system. Tell me more about your configuration.
    > No thanks -- this is pointless.  Bye.
    Nice talking to you. Bye...
    
  3. In the sample interaction above, note that the system produced the same output message for input containing the keyword "crashes" as it did for "crash". A glance at the fillResponseMap method in the Responder class shows that there are duplicate entries — one for each of the variations. We could simplify the Responder class, and provide better output, if we took the user's input words and mapped them to a root synonym before consulting the responseMap. For example, "crashes", "quits", and "dies" might all map to "crash". Then we'd only need one entry in the responseMap — an entry for the root synonym "crash". We'll complete a new class to do the synonym mapping, then integrate it into the project.

    I've written most of the SynonymMapper class for you. You just need to finish the body of the rootSynonym method. Finish the method now: Write code that checks for the input word in our synonym map. If we find it, return the corresponding root synonym. If we don't find the input word in the map, just return the original word. You can test your SynonymMapper class by itself when you're finished:

    > SynonymMapper sm = new SynonymMapper();
    > sm.rootSynonym("dies")
    "crash"  (String)
    > sm.rootSynonym("quits")
    "crash"  (String)
    > sm.rootSynonym("crashes")
    "crash"  (String)
    > sm.rootSynonym("aardvark")
    "aardvark"  (String)
    
  4. The final step is to integrate the SynonymMapper into the rest of the project. Find the generateResponse method in the Responder class and make sure you understand how it works: It looks through each of the words in the input set, hoping to find a word it recognizes. If it finds a known word it returns the corresponding output message, otherwise it selects a default response randomly. Modify this code so that it maps each word from the set to its root synonym, then looks for the synonym in responseMap. Before testing, remove the lines in fillResponseMap that add entries for "crashes" and "buggy" — we don't need them anymore. Compile and run the system:

    > SupportSystem s = new SupportSystem();
    > s.start();
    Welcome to the DodgySoft Technical Support System.
    
    Please tell us about your problem.
    We will assist you with any problem you might have.
    Please type 'bye' to exit our system.
    > It just quits!
    Well, it never crashes on our system. It must have something
    to do with your system. Tell me more about your configuration.
    > Well it crashes on MY system!
    Well, it never crashes on our system. It must have something
    to do with your system. Tell me more about your configuration.
    > When I open a file, the program dies.
    Well, it never crashes on our system. It must have something
    to do with your system. Tell me more about your configuration.
    > No!
    Could you elaborate on that?
    > bye
    Nice talking to you. Bye...
    
If time permits, consider trying one of the following exercises:


Brad Richards, 2009