Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

RuleIf the input is/contains or is of the form:Your program will generate a response (randomly chosen - except for rule 1):
1Bye(.)

Bye .

Have a great day!

2Input contains a reference to a special topicTell me more about your (special topic), .
3(do/can/will/would) you ______________?

No , I (do/can/will/would) not .

Yes i (do/can/will/would).

4 Why __________?Why not?
5How __________?

, why do you ask?

, how would an answer to that help you?

6What __________?

What do you think ?

Why is that important ?

7I (need/think/have/want) ________Why do you (need/think/have/want) ?
8I __________ (last word is not too)I __________ too.
9(A verb from the list below)________________You verb ______________.
10_____________?

I have no clue.

Maybe.

11Input contains becauseIs that the real reason?
12everything elseThat' 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:
Bye _

Have a great day!

 

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)


In the no response: the name must be included and the pronouns must be changed correctly (1 point)


 

Rule 4: Why _____?The rule applies only if the input starts with why and is a question:

Talk to me please >Why are you doing this?

Why not?

Talk to me please>Why of course that is just like you!

That's nice!

 

This criterion is linked to a Learning OutcomeRule 5: How __________?The rule applies only if the input starts with how and is a question:

Talk to me please > how are you?

-, why do you ask?

Talk to me please> how I missed in-person classes!

That's interesting.

The response must be chosen randomly. It must include the user name.
Possible responses are: _, why do you ask?
_, how would an answer to that help you?

 

This criterion is linked to a Learning OutcomeRule 6: What _____?The rule applies only if the input starts with what and is a question:

Please talk to me > what is the meaning of life?
Why is that important _?
Talk to me please> what an amazing chatbot

Can you elaborate on that?

The response must be chosen randomly. It must include the user name. Possible responses are:


What do you think ?

Why is that important ?

 

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) ?

The correct form/verb is used (1 point)
The pronouns are changed correctly (1 point)

 

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):

Talk to me please> I am bored

I am bored too.

Talk to me please> I submitted my project

I submitted my project too.

When the last word is too, rule 12 applies:

Talk to me please> I like programming too

That's nice.

 

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
Talk to me please> Tell me a joke

You tell me a joke.

Talk to me please> give me a hint

You give me a hint.

Talk to me please> say something

You say something.

 

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.

The question is answered randomly with one of the following responses: I have no clue or Maybe

Example:
Talk to me please> is it cold outside?
I have no clue.
Talk to me please> Are you intelligent?
Maybe.

 

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?

Examples:
Talk to me please> He did not show up because he was sick.

Is that the real reason?

Talk to me please> because it is raining

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:
That's interesting,
Can you elaborate on that?, That's nice!

 

This criterion is linked to a Learning Outcomechange_person functionThe function is implemented correctly and used by the program.
It takes as arguments an arbitrary number of words, and returns a string obtained by changing the pronouns and putting the words together.
The function uses a constant dictionary to map each pronoun to its replacement.
A docstring is included.

 

chat_with functionThe function is implemented correctly and used by the program as outlined in the template.
It takes the user name as argument. The function prompts the user for input once only. If the user enters bye with or without punctuation, the function returns True (without printing anything). Otherwise, the function responds according to rules 2-12 above and returns False.

The function uses the match statement in a non-trivial way.

 

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.

Each function includes a docstring that describes the function and lists the parameter(s) and return value(s) and their expected types.

 

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.
Use formatted strings for printing.
Limit all lines to a maximum of 79 characters. For docstrings or comments, the line length should be limited to 72 characters.

 

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Illustrate the systems approach of family therapy.

Answered: 1 week ago