Question
The Chatbot Please right the program in python, a simple chatbot. Here's a sample chat that your program will carry out. User input is
The Chatbot
Please right the program in python, a simple chatbot.
Here's a sample chat that your program will carry out. User input is shown in red.
Hello. What is your name please? Rula
Talk to me please> How are you?
Rula, why do you ask?
Talk to me please> I am bored.
I am bored too.
Talk to me please> can you sing?
Yes I can.
Talk to me please> I like to sing too.
That's interesting.
Talk to me please> Do you play the guitar?
No Rula, I do not play the guitar.
Talk to me please> Are you intelligent?
Maybe.
Talk to me please> Will artificial intelligence take over the world?
I have no clue.
Talk to me please> What is the meaning if life?
What do you think Rula?
Talk to me please> I think it is all about family and friends.
Tell me more about your friends, Rula.
Talk to me please> They are great!
That's nice!
Talk to me please> What an amazing chatbot.
Can you elaborate on that?
Talk to me please> Will you help me with my work?
No Rula, I will not help you with your work.
Talk to me please> Tell me a joke
You tell me a joke.
Talk to me please> Why are you doing this?
Why not?
Talk to me please> Do you understand me?
Yes I do.
Talk to me please> Why is my dog barking?
Tell me more about your dog, Rula.
Talk to me please> I need to go get my umbrella.
Why do you need to go get your umbrella?
Talk to me please> Because it is raining.
Is that the real reason?
Talk to me please> You drive me crazy!
Can you elaborate on that?
Talk to me please> Bye!!!
Bye Rula.
Have a great day!
The Rules
Your program will be case-insensitive and will generate a response based on the following rules in descending priority order:
Rule | If the input is/contains or is of the form: | Your program will generate a response (randomly chosen - except for rule 1): |
---|---|---|
1 | Bye(.) | Bye Have a great day! |
2 | Input contains a reference to a special topic | Tell me more about your (special topic), |
3 | (do/can/will/would) you ______________? | No Yes i (do/can/will/would). |
4 | Why __________? | Why not? |
5 | How __________? | |
6 | What __________? | What do you think Why is that important |
7 | I (need/think/have/want) ________ | Why do you (need/think/have/want) |
8 | I __________ (last word is not too) | I __________ too. |
9 | (A verb from the list below)________________ | You verb ______________. |
10 | _____________? | I have no clue. Maybe. |
11 | Input contains because | Is that the real reason? |
12 | everything else | That' s interesting. That' s nice! Can you elaborate on that? |
- The program will first prompt the user for their name. The program will terminate after the response to the bye input.
- The special topics in rule 2 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 please> 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 rules 3 and rule 7, 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
Here are some examples:
Talk to me please> Will you help me with my work?
No Rula, I will not help you with your work.
Talk to me please> I want to understand your algorithm.
Why do you want to understand my algorithm?
Talk to me please> I think I am done.
Why do you think you are done?
Talk to me please> I have to understand you.
Why do you have to understand me?
- For rule 9, you will use a short list of verbs that includes: tell, give, say. You can add more verbs to the list, if you like.
Additional Requirementschange_person function:
As part of the program, implement and use a function change_person that takes as arguments an arbitrary number of words, and returns a string obtained by changing the pronouns and putting the words together.
Hint: use a dictionary to map each pronoun to its replacement.
Here is how to test this function from the console, independently of the rest of the program:
>>> from chat import change_person
>>> change_person('i', 'want', 'to', 'understand', 'your', 'algorithm')
'you want to understand my algorithm' <- return value
>>> change_person('help', 'me', 'with', 'my', 'work')
'help you with your work'
>>> change_person('i', 'am', 'ready')
'you are ready'
chat_with function:
As part of the program, implement and use a function chat_with that takes the user name as argument. The function prompts the user for input once only. If the user enters Bye (lower, upper or mixed case) with or without a period, the function returns True (without printing anything). Otherwise, the function responds according to rules 2-12 above and returns False.
The function must use the match statement in a non-trivial way.
Constants:
Use a constant for the special topics (what data structure works best here?) and another constant for mapping the pronouns.
Sets and Set Intersection:
Use sets and set intersection to implement rule 2. To pick a (pseudo) random element of a set, we can use the pop method.
Here's an example:
colors = {'red', 'blue', 'yellow'}
pseudo_random_element = colors.pop()
Printing:
Use formatted strings for all print statements containing variables.
How do I get started?
Download the starter file chat.py Download chat.py.
Copy the file to your CS 122 project in PyCharm.
Fill in the block comments and the module docstring.
Fill in the code following the outline provided.
Make sure you test your program. Add more tests to make sure your code is robust.
To submit your assignment, upload your modified program chat.py.
Please read and follow the grading rubric for specific implementation requirements.
This criterion is linked to a Learning OutcomeStarting and ending the chatThe program will first prompt the user for their name. When the user enters bye the program will terminate after printing the response:
|
This criterion is linked to a Learning OutcomeRule 2: input includes reference to a special topicThe 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.
|
Rule 3: (Do/can/will/would) you ______________?The response must be chosen randomly. Possible responses are yes... and no... (1 point)
|
Rule 4: Why _____?The rule applies only if the input starts with why and is a question:
|
This criterion is linked to a Learning OutcomeRule 5: How __________?The rule applies only if the input starts with how and is a question:
|
This criterion is linked to a Learning OutcomeRule 6: What _____?The rule applies only if the input starts with what and is a question:
|
This criterion is linked to a Learning OutcomeRule 7: I (need/think/have/want) ________The response must be of the form: Why do you (need/think/have/want)
|
This criterion is linked to a Learning OutcomeRule 8: I __________ (last word is not too)The rule applies only when the last word in the input is not too (1 point):
|
This criterion is linked to a Learning OutcomeRule 9: A verb (tell, give, say)________________The rule applies only when the first word is one of the verbs: tell, give, say
|
This criterion is linked to a Learning OutcomeRule 10: A ny other questionApplies when the input ends with ? and does not fall under any of the previous rules.
|
This criterion is linked to a Learning OutcomeRule 11: becauseWhen the input includes because (anywhere in the sentence), the response is: Is that the real reason?
|
Rule 12: everything elseWhen the input does not follow under any of the previous rules, the response is chosen randomly from:
|
This criterion is linked to a Learning Outcomechange_person functionThe function is implemented correctly and used by the program.
|
chat_with functionThe function is implemented correctly and used by the program as outlined in the template.
|
This criterion is linked to a Learning OutcomeModule and Function DoctringsInclude a module docstring that describes your program to a user. Your docstring will be available through the help function. The docstring must have a one-line overview and a more detailed description separated by a blank line.
|
Pythonic StyleUse pythonic idioms as seen in the lectures (built-in functions wherever possibles, boolean interpretation to check for empty sequence, for loops...) Use pythonic identifier names.
|
This criterion is linked to a Learning OutcomeSets and set intersectionUse sets and set intersection for rule 2.
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started