Difference between revisions of "CSC111 Homework 7"
(→Please meet Eliza) |
(→Problem #1) |
||
Line 18: | Line 18: | ||
#Copy the next [[CSC111 logging111.py | program]] in a file called logging111.py. '''Logging111.py''' is not the main program, but a simple library created for this class that will allow us to capture the dialog between the user and Eliza in a text file. | #Copy the next [[CSC111 logging111.py | program]] in a file called logging111.py. '''Logging111.py''' is not the main program, but a simple library created for this class that will allow us to capture the dialog between the user and Eliza in a text file. | ||
# Play with the program | # Play with the program | ||
− | + | # Every so often, try answering "no" or "never" and see how the program reacts. | |
− | from | + | # Also, from time to time, use "I", "you", "me", or "your" in your answer, as in "I like you" for example. See how the program responds. We call this a ''reflection.'' |
− | |||
− | + | ==Reflection== | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | Reflection | ||
When doing a reflection, your program should transform the string "you" at the beginnning of a sentence in "I". However, if the word "you" is not at the beginning of a sentence, your program will translate it into "me". | When doing a reflection, your program should transform the string "you" at the beginnning of a sentence in "I". However, if the word "you" is not at the beginning of a sentence, your program will translate it into "me". |
Revision as of 19:34, 10 March 2010
This assignment is currently under construction...
Eliza
Please meet Eliza
Please read this introduction to Eliza in Wikipedia. The goal of this assignment is to write our own version of Eliza.
Problem #1
- Copy the following program in a file called eliza1.py
- Copy the next program in a file called logging111.py. Logging111.py is not the main program, but a simple library created for this class that will allow us to capture the dialog between the user and Eliza in a text file.
- Play with the program
- Every so often, try answering "no" or "never" and see how the program reacts.
- Also, from time to time, use "I", "you", "me", or "your" in your answer, as in "I like you" for example. See how the program responds. We call this a reflection.
Reflection
When doing a reflection, your program should transform the string "you" at the beginnning of a sentence in "I". However, if the word "you" is not at the beginning of a sentence, your program will translate it into "me". The effect of this is that if the user says:
you do not understand
Eliza will respond with
I do not understand?
But if the user types
I told you so
Eliza will respond with
you told me so?
Picking up on keywords
If the user types the words mother or father anywhere in her input, the program will respond with a random sentence whose topic should include the word family. For example, if the user types "My mother always calls me at the wrong time", Eliza could respond something like "Is that typical in your family?" or "Is that a family trait?"
Let's be polite
If the user does not start the first sentence with "hello", the program will scold her. Feel free to find an appropriate sentence for this faux pas. Ending the conversation
Your program should stop not only if the user enters "bye," but it should also recognize "goodbye," and "ciao." Aggressive user
If the user enters a sentence of the form "I xxxx you", we can imagine that the word "xxxx" is a verb, and that the user is being aggressive. In this case Eliza should respond with a sentence of the form "Why do you xxxx me?" Recommendations
Use functions! What we have built so far is a very linear program, but it should use functions. For example, returning a canned sentence from a list of canned sentences can easily be done by a function. Only PG13 programs will be accepted! Be imaginative in creating your dialogs and responses, and make your programs enjoyable and fun to read and play with!
Optional and Extra Credit
This section is optional and worth 1/2 point of extra credit (bringing a B- to a B, for example). Dealing with exclamation marks and question marks
If the user enters a sentence of the form I lost you!, then the last word, "you" will not be reflected in "me" because the string.split() function will have kept the exclamation mark attached to the word "you." The last word is thus "you!" and will not be reflected by the current program. Figure out a way for your program to be able to reflect the last words of a sentence, even when they are terminated by a "!", "?", or "."
Be efficient in your coding. The fewer changes you need to make to your program to make it behave that way, the better.
Memory
Whenever the user enters a sentence of the form "I xxxx you", make your program remember it so that whenever it has to output a canned response, it will sometimes output "Is that why you xxxx me?". As an example, imagine that the user has already typed in her conversation with Eliza "I dislike you" and "I trust you", whenever the user enters a sentence that is not reflected and not negative, the program will sometimes, but not always, respond with "Is that why you dislike me?", or "Is that why you trust me?". This should really enhance the illusion that the program is intelligent and remembers the conversation.
You do not need to submit a separate version of your program if you implement the extra-credit questions. Put the enhanced version in hw7.py and submit it as mentioned above.