In python!
'''Remember to create dictionaries for the words and their weights
i.e.happiness_list ={"accomplish": 3, "friend": 3, ...}
'''
''' Define function sadness_score '''
''' Define function happiness_score '''
Extracted text: Learning Objectives 1. Create a function in a modular structure 2. Use a dictionary to calculate score 3. Loop over the input string and the dictionary words 4. Print analysis of the given input Instructions This lab is the same as the Extract My Emotion :) :( - Lists-tuples lab but this time you will use dictionaries instead of lists and tuples. A very known application in natural language processing is to extract information from a given text. In this lab, you will be able to extract some emotions (Sad and Happy) from a given string and calculate the score of each emotion. You will be given below the words that express sadness, anger, and happiness. For each word, you will be given weight as well, so that when you are calculating for example the score for sadness in the text (string), you can use this formula: Sadness Score Weight_1 + Weight 3 +Weight_4 +...... %3D Sadness Words Word Weight Word Weight Word Weight Word Weight abandon 2 ashamed 4 awful 4 bad hard 3 belittle 3 betray 5 crash 4 crazy 2 cry 3 disappoint 3 death 5 Happiness Words Word Weight Word Weight Word Weight Word Weight accomplish 3 friend 3 beach 4 beautiful 5 dawn 4 adorable 3 enjoy 5 celebrate 4 cheer 3 bless 4 baby 3 angel 5 LO LO
Extracted text: 1. Create the functions sadness_score, and happiness_score 2. Each function has only 1 parameter of type string: text 3. In each function, create a dictionary for the words and their weights i.e in happiness_score function you should have { "accomplish" : 3, ....} where the key is the word and the score is the value. happiness_dictionary 4. Loop over the tuples and check if the word is in the given text. If the word is found, increment the resulting score by the current score, otherwise do nothing 5. Return the final score Example Input: "This lab is driving me crazy. I want to accomplish more so I won't feel bad at the end of the day" Return from sadness_score function: 7 Return from happiness_score function: 3 Hint! • do not calculate the number of words in the text. The sentence "I am so bad" and "I am so bad bad bad" should return the same score for this lab, though in the real world it is not always so.