Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Simple chatbot in Python. No libraries or dictionaries please. Only lists/strings/tuples functions. Chatbot will take some conversational text from the user, identify the most frequent

Simple chatbot in Python. No libraries or dictionaries please. Only lists/strings/tuples functions.

Chatbot will take some conversational text from the user, identify the most frequent term(s) used and then respond with a poem that has the most frequent term contained in it.

The solution should do the following:

  1. Allow the user to enter any freeform text input for conversation. Analyze their text for the most frequent word(s).
  2. The users input should be homogenized for case-insensitivity and stripped of punctuation. The poetry data (given to you) should also be homogenized so that it is case-insensitive and stripped of punctuation. Note: Do NOT alter the data given to you; for data homogenization, be sure to make your own working copies.
  3. The starter file we gave you also contains a list of "skip words". These are words that you should ignore when processing the user input AND when comparing to the given poems. In effect, these are "articles" in English ("a", "the", etc.) that skew your word matching, but don't add (much) value to understanding the user intentions.
  4. If the most frequent word(s) are present in at least one of the poems, use that poem as the basis for your chatbots response. Select the poem that has the highest occurrence of the word the user used most frequently. If there is more than one word with the same number of occurrences, (e.g. a frequency tie), the longest word wins use the longest word (in terms of len()). There are pre-formed responses (in the RESPONSES list) in the starter code data file. Pick a random response from this list and replace the {poet} and {poem} tags with the data from the poem list given to you in that same file. NB: Youll be doing a similar interpolation like the Python f-strings you learned about, but in this case YOU will substitute the actual values for the placeholders
  5. If there are no words that match in any of the poems given, print a default message: Thats interesting. I dont quite know what to say
  6. Exit the chatbot when the user enters the "I'm finished talking to you commend": /quit
  7. Handle two special cases: me-or-you: If there are no other matching words from the user input, handle the special case of when the user speaks of themselves OR when the user talks about you (the chatbot).

Its difficult to handle a lot of variations here, so dont worry about being able to manage every open-ended discussion for the special cases. As long as your code can manage something similar to the above WITHOUT HARDCODING your solution, youll get full credit for this.

Additional Requirements! You must also provide the following:

  1. Testing hooks: Your solution must provide two functions for us to unit test: max_word(text) and find_poem(word)
    • max_word(text) takes as input parameter the user text for 1 chat Q&A (not the entire session) and returns a list of the homogenized words (strings) - stripped of any punctuation - that occurs most frequently in the user input
    • find_poem(word) takes as input parameter a word and returns the poem (a list with two elements: a string author and a string containing the actual poem) that has the highest occurrence that word.

POEMS = [["Maya Angelou", "You may write me down in history with your bitter, twisted lies; You may trod me in the very dirt but still, like dust, I'll rise"], \ ["Nikki Giovanni", \ "I was born in the Congo. I walked to the Fertile Crescent and built"\ " the Sphinx. I designed a Pyramid so tough that a star that glows"\ " every one hundred years falls into the center giving divine perfect light."\ " I am bad."], ["Langston Hughes", \ "Hold fast to dreams. For if dreams die. life is a broken-winged bird."\ " That cannot fly."], ["Ashley Odilia Armand", \ "Skin, I'm in love with the way you carry the blood that keeps me sane,"\ " and, at times, chaotic."]]

RESPONSES = ["That's interesting. As {poet} has written: '{poem}'", "I was thinking something similar! In fact, I just read {poet}'s"\ " poem about that topic. They wrote: '{poem}'", "I'm speechless. {poet} wrote about that when they said: '{poem}'", "Do you read poetry? Did you know {poet} said the same thing: '{poem}'"]

SKIP_WORDS = ["a", "to","so", "the", "and", "or", "an", "am", "in", "if", "is", "for", "i'll", "i'm", "but"] PUNCTUATION = ".?!:,"

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

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions