Difference between revisions of "CSC111 Homework 7"
(→Memory) |
(→Submission) |
||
(16 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | {| style="width:100%; | ||
+ | | width="500" | | ||
+ | __TOC__ | ||
+ | | | ||
<bluebox> | <bluebox> | ||
− | This assignment is | + | This assignment is about ''Artificial Intelligence'', and will require you to use '''if/else''' statements in a program that will simulate a therapist. |
+ | |||
+ | The program is due on 3/25/10 at midnight. You are encouraged to pair-program this assignment. | ||
</bluebox> | </bluebox> | ||
+ | |} | ||
<br /> | <br /> | ||
− | |||
<br /> | <br /> | ||
− | |||
=Eliza= | =Eliza= | ||
Line 17: | Line 22: | ||
==Setup== | ==Setup== | ||
− | + | * Copy the following [[CSC111 Eliza 1 | program]] in a file called eliza1.py | |
− | + | * 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 | |
− | + | * 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.'' | |
+ | * At some point type '''bye''' at the prompt and verify that the program stops. Then look in your directory to see that there's a new file there: | ||
+ | |||
+ | ls | ||
+ | |||
+ | eliza1.py | ||
+ | logging111.py | ||
+ | logging111.pyc | ||
+ | '''eliza.log''' | ||
+ | |||
+ | * Open the file '''eliza.log''' with emacs. Observe that your interaction with the program has been recorded. This was performed by two functions that are defined in the [[CSC111 logging111.py | logging111.py]] program: | ||
+ | ** Print( ) | ||
+ | ** Raw_input( ) | ||
+ | |||
+ | :Instead of using the Python '''print''' function and the Python '''raw_input()''' function, we use the two similar-sounding functions '''Print()''' and '''Raw_input()''' which are designed to save whatever they write on the screen to a text file in your directory. This feature will be used when testing and grading your program. | ||
+ | |||
+ | <tanbox> | ||
+ | Make sure you do not use '''print''' or '''raw_input''' in your program. Instead use '''Print''' and '''Raw_input'''! | ||
+ | </tanbox> | ||
==Reflection== | ==Reflection== | ||
Line 39: | Line 62: | ||
* See the problem? | * See the problem? | ||
− | ==Part | + | ==Part 1: Improved Reflections == |
Improve the way your program performs reflections. | Improve the way your program performs reflections. | ||
Line 70: | Line 93: | ||
Modify your program so that it will perform reflections correctly (at least for '''I''', '''you''', and '''me'''). | Modify your program so that it will perform reflections correctly (at least for '''I''', '''you''', and '''me'''). | ||
− | |||
− | |||
− | |||
− | |||
==Part 2: Picking up on keywords== | ==Part 2: Picking up on keywords== | ||
Line 98: | Line 117: | ||
− | ==Part 6: Dealing with exclamation marks and question marks== | + | ==Part 6: 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. | 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. | ||
Line 107: | Line 126: | ||
==Part 7: Memory== | ==Part 7: Memory== | ||
− | Whenever the user enters a sentence of the form | + | 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 | + | |
+ | 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. | |
=Recommendations= | =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. | + | * 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! | + | |
+ | |||
+ | * '''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! | ||
+ | |||
+ | =Submission= | ||
+ | |||
+ | Submit your Eliza program as follows: | ||
+ | |||
+ | submit hw7 eliza1.py | ||
+ | |||
+ | |||
+ | You do not need to submit the logging111.py program. | ||
+ | |||
+ | <br /> | ||
+ | <br /><br /><br /><br /><br /><br /><br /><br /><br /> | ||
+ | <br /><br /><br /><br /><br /><br /><br /><br /><br /> | ||
+ | [[Category:CSC111]][[Category:Python]][[Category:Homework]] |
Latest revision as of 07:05, 1 May 2010
Contents |
This assignment is about Artificial Intelligence, and will require you to use if/else statements in a program that will simulate a therapist. The program is due on 3/25/10 at midnight. You are encouraged to pair-program this assignment. |
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.
For a weird implementation of Eliza, check this place out...
Setup
- 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.
- At some point type bye at the prompt and verify that the program stops. Then look in your directory to see that there's a new file there:
ls eliza1.py logging111.py logging111.pyc eliza.log
- Open the file eliza.log with emacs. Observe that your interaction with the program has been recorded. This was performed by two functions that are defined in the logging111.py program:
- Print( )
- Raw_input( )
- Instead of using the Python print function and the Python raw_input() function, we use the two similar-sounding functions Print() and Raw_input() which are designed to save whatever they write on the screen to a text file in your directory. This feature will be used when testing and grading your program.
Make sure you do not use print or raw_input in your program. Instead use Print and Raw_input!
Reflection
- Start your Eliza program and tell it: I like you
- Observe that it responds: you like me?
- This is a reflection!
- Unfortunately, your current version of Eliza is not very clever.
- Try: you do remind me of my mother
- Observe its output.
- See the problem?
Part 1: Improved Reflections
Improve the way your program performs reflections.
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 you type:
- you do not understand
Your Eliza program will respond with
- I do not understand?
But if you type:
- I told you so
your Eliza program will respond with
- you told me so?
Modify your program so that it will perform reflections correctly (at least for I, you, and me).
Part 2: Picking up on keywords
Modify your program so that if you type the words mother or father anywhere in your input, the program will respond with a random sentence whose topic should include the word family.
For example, if you type My mother always calls me at the wrong time, your Eliza program could respond with something like Is that typical in your family? or Is that a family trait?
Make sure your program recognizes different versions of the keywords, such as (but not limited to) mother, Mother, or MOTHER.
Remember that we have seen several examples of generation of random strings, in particular randomName2.py and the Solution programs for Homework #3.
Part 3: Let's be polite
Make your program scold the user if he/she does not start the first sentence that contains the word hello or Hello. Feel free to find an appropriate sentence for this faux pas.
Part 4: Ending the conversation
Your program should stop not only if the user enters bye, but it should also recognize goodbye, ciao.
Part 5: 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?
Part 6: 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.
Part 7: 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.
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!
Submission
Submit your Eliza program as follows:
submit hw7 eliza1.py
You do not need to submit the logging111.py program.