Activity 4: Responses that Transform Statements

As stated previously, single keywords are interesting, but better chatbots look for groups of words. Statements like “I like cats,” “I like math class,” and “I like Spain” all have the form “I like something.” The response could be “What do you like about something?” This activity will respond to groupings of words.

Try each of the following as the value for the statement in the main method and see what they print.

You can also step through the code here. It may take a minute or two to load. Click the forward button to execute the next statement (the one with the red arrow).

Exercises:

Look at the code. See how it handles “I want to” and you/me statements.

Alter the code:

  • Have it respond to “I want something” statements with “Would you really be happy if you had something?” In doing this, you need to be careful about where you place the check. Be sure you understand why. For example:
    • Statement: I want fried chicken.
    • Response: Would you really be happy if you had fried chicken?
  • Have it respond to statements of the form “I something you” with the restructuring “Why do yo something me?” For example:
    • Statement: I like you.
    • Response: Why do you like me?

Find an example of when this structure does not work well. How can you improve it?

Next Section - Loops in Java