Microsoft Word – 周五.docx
Your task is to implement a simple chatbot in Scheme.
A chatbot is a program that can chat with a human.
Here’s a sample chat that your program will carry out:
> (chat-with ‘Rula)
hi rula
talk to me >>>how are you?
why do you ask?
talk to me >>>i am bored
i am bored too
talk to me >>>can you sing?
yes i can
talk to me >>>i like to sing too
good to know
talk to me >>>do you play the guitar?
no rula i do not play the guitar
talk to me >>>are you intelligent?
maybe
talk to me >>>what is the meaning of life?
what do you think?
talk to me >>>i think it is all about family and friends
tell me more about your friends rula
talk to me >>>they are great
that’s nice
talk to me >>>will you help me with my work?
no rula i will not help you with your work
talk to me >>>tell me a joke
you tell me a joke
talk to me >>>why are you doing this?
why not?
talk to me >>>do you understand me?
yes i do
talk to me >>>i need to go get my umbrella
why do you need to go get your umbrella?
talk to me >>>because it is raining
is that the real reason?
talk to me >>>you drive me crazy
can you elaborate on that?
talk to me >>>bye
bye rula
have a great day!
Your program will generate a response based on the following rules:
if the input is of the form: your program will generate a response (randomly chosen)
1 (do|can|will|would) you ________________?
no
yes i (do|can|will|would)
2 _____(special topics)_______ tell me more about your (special topics)…
3 why __________? why not?
4 how __________?
why do you ask?
how would an answer to that help you?
5 what __________?
what do you think?
why do you ask?
6 _____________?
i don’t know
i have no idea
i have no clue
maybe
7 ______because_______ is that the real reason?
8 i (need|think|have|want) ________ why do you (need|think|have|want) __change person_____?
9 i __________ (last word is not too) i __________ too
10 verb ________________ you verb ______________
11 everything else
good to know
that’ s nice
can you elaborate on that?
The user name will be identified when the main function is called: (chat-with ‘user-name)
The special topics in rule 2 will include the following: family, friend(s), mom, dad, brother,
sister, girlfriend, boyfriend, children, son, daughter, child, wife, husband, home, dog,
cat, pet. If more than one special topic is found in the input, your program will pick
one randomly and ask the user about it. For example, the response to:
talk to me >>>i think it is all about family and friends
can be either:
tell me more about your friends rula
or:
tell me more about your family rula
In rule 1 and rule 8, when the chatbot repeats part of the user’s input, the pronouns must be
changed as follows:
I becomes you
am becomes are
my becomes your
your becomes my
me becomes you
you becomes me
talk to me >>>will you help me with my work?
no rula i will not help you with your work
talk to me >>>i want to understand your algorithm
why do you want to understand my algorithm?
talk to me >>>i think i am done
why do you think you are done?
talk to me >>>i have to understand you
why do you have to understand me?
For rule 10, you will use a short list of verbs that includes: tell, give, say. You can add more
verbs to the list, if you like.
测试:
Rule 3: why _____?
talk to me >>>why are you doing this?
why not?
Rule 4: how ____?
talk to me >>>how are you?
The response must be chosen randomly. Possible responses are:
why do you ask?
how would an answer to that help you?
Rule 5: what ____?
talk to me >>>what is the meaning of life?
The response must be chosen randomly. Possible responses are:
what do you think?
why do you ask?
Rule 1: (do|can|will|would) you ________________?
The response must be chosen randomly. Possible responses are yes… and no… (1 point)
talk to me >>>can you sing?
yes i can
talk to me >>>do you play the guitar?
no rula i do not play the guitar
In the no response:
the name must be included (1 point)
the ‘?’ must not be included in the last word. (1 point)
The pronouns must be changed correctly in the no response (1 point) – even when the
pronoun is the last word (with the question mark) (1 point)
talk to me >>>will you help me with my work?
no rula i will not help you with your work
talk to me >>>do you understand me?
no rula i do not understand you
Rule 2: input includes reference to a special topic
The response is of the form:
tell me more about your …
If more than one special topic is found in the input, your program will pick one randomly and
ask the user about it. For example, the response to:
talk to me >>>i think it is all about family and friends
can be either:
tell me more about your friends rula
or:
tell me more about your family rula
Rule 6: any other question
Input where the last word ends with ? and that does not fall under rules 1through 5 is
answered randomly with one of the following responses:
i don’t know
i have no idea
i have no clue
maybe
Example:
talk to me >>>is it cold outside?
i don’t know
talk to me >>>are you intelligent?
maybe
Rule 7: because
when the input includes because (anywhere in the sentence), the response is:
is that the real reason?
Examples:
talk to me >>>because it is raining
is that the real reason?
talk to me >>>i did not go to class because i was sick
is that the real reason?
Rule 8: i (need|think|have|want) ________
The response must be of the form:
why do you (need|think|have|want) __change person_____?
The correct form/verb is used (2 points)
A question mark is added to the last word (no space) (1 point)
The pronouns are changed correctly (1 point)
Examples:
talk to me >>>i need to go get my umbrella
why do you need to go get your umbrella?
talk to me >>>i want to understand your algorithm
why do you want to understand my algorithm?
talk to me >>>i think i am done
why do you think you are done?
talk to me >>>i have to understand you
why do you have to understand me?
Rule 9: I ___
When the last word in the input is not too (1 point):
talk to me >>>i am bored
i am bored too
talk to me >>>i submitted my project
i submitted my project too
When the last word is too, rule 11 (1 point):
talk to me >>>i like programming too
that’s nice
Rule 10: verb _________
talk to me >>>tell me a joke
you tell me a joke
talk to me >>>give me a hint
you give me a hint
talk to me >>>say something
you say something
Rule 11: everything else
This rule has been implemented for you.
You just need to check that you did not break it and that it has the correct priority.
Examples:
talk to me >>>i like to sing too
good to know
talk to me >>>they are great
that’s nice
talk to me >>>you drive me crazy
can you elaborate on that?