Question: So, for this assignment, we will be building a simple Poetry Chatbot. You can learn more about chatbots here (Links to an external site.), but

So, for this assignment, we will be building a simple Poetry Chatbot. You can learn more about chatbots here (Links to an external site.), but generally speaking, chatbots are systems that dialogue with a user without human intervention. Our chatbot will be extremely simple (and without any artificial intelligence [AI]). We 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.

Heres a sample run to help you visualize the flow:

Your 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). Examples below

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 As a reminder, here is an example of the poem data:
      ["Ashley Odilia Armand", "Skin, I'm in love with the way you carry the blood that keeps me sane, and, at times, chaotic."]

Your functions MUST: (a) be named exactly as described above, (b) take the same number (and type) of parameters, AND (c) return the type specified in the description

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!