Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Penn Engineering ONLINE LEARNING The output of your function should be a list of tuples, in which the first element of the tuple is the

Penn Engineering ONLINE LEARNING The output of your function should be a list of tuples, in which the first element of the tuple is the word that was searched for (either the keyword or one of its synonyms) and the second is its total number of occurrences For instance, if the keyword was 'cat and it occurred 120 times, and its synonym was \"kitty\" and it occurred 84 times, the output should be: [cat\", 120). (\"kitty', 84) Hint: You can create a tuple variable like this: result = (\"cat\", 120) And then add it to a list using the list's 'append function. As in Parts 2 and 3, you may assume that: The Thesaurus is not empty, i.e., there is at least one Entry in the Thesaurus. The Corpus is not empty, i.e. there is at least one document (list of strings) in the Corpus Each document contains at least one string You can also assume that all words consist only of lowercase letters and that you don't have to account for punctuation. 1 2. def search(keyword) # implement the function here return #modify to return a list of tuples 4 5 6 7 9 10 input \"happy output=search(input)# invoke the method using a test input print(output) #prints the output of the function # do not remove this linel Your program will be evaluated using the inputs \"happy\" and \"sad\" for the Thesaurus and Corpus we have provided, along with other test inputs as well. Keep in mind that you can print out the Thesaurus and Corpus objects to see what is in them and to get an idea of whether your program is producing the correct output for those inputs Computational Thinking For Problem Solving Assignment 4.7 Property of Penn Engineering BI - Fit to width Penn Engineering

ONLINE LEARNING Thesaurus, which is a list of Entry objects; each Entry object has a word attribute, which is a string of characters, and an attribute called synonyms, which is a list of strings Corpus, which is a list of lists of strings For example, the Entry class and Thesaurus variable may be defined like this: 1 2. 3 class Entry: def __init__(self, input_word, input_synonyms) self word=input_word self synonyms - input_synonyms e1 = Entry(\"dog\" [\"doggie\", \"puppy) e2 - Entry(\"cat\", [\"kitty1) Thesaurus = [e1,621 9 Note that the first argument to the Entry constructor is the word in the thesaurus, and the second is the list of words that are its synonyms. All words consist only of lowercase letters. And the Corpus variable may be defined ike this: 1 2 3 doc1 = [\"this\", \"is\",\"a\", \"single\". \"document] doc2 = [\"here', 's', 'another\", \"document] Corpus = (doc 1, do 21 Each document is represented as a list of words, which are all lowercase letters, and the Corpus is a list containing those lists You can access the Thesaurus and Corpus variables in your program without having to define them, they have already been defined and initialized with words and phrases describing a person's emotions - happy, sad, angry, etc. - in the setup of this activity. For your own testing purposes, you can create your own Thesaurus and Corpus and populate them with your own data, but please do so outside the function definition, and keep in mind that the correctness of your function will be determined using the Thesaurus and Corpus that we have provided

Your search function should implement the algorithm described by the pseudocode above by using the Thesaurus to find the keyword's synonyms, and then reporting the number of occurrences of the keyword and its synonyms in all documents in the Corpus Computational Thinking For Problem Solving Assignment 4.7 Property of Penn Engineering e Penn Engineering ONLINE LEARNING Part 4: Implementing the solution in Python Summary In this final part of the course project, you will implement the solution in Python Description Throughout this course project, we have been applying computational thinking to solve the problem of counting the number of occurrences of a word and its synonyms in a corpus of text documents In Part 1, we applied the pillars of computational thinking to decompose this problem into two smaller problems, then used pattern recognition to find commonalities between the problems, used data representation and abstraction to identify the data we needed, and developed an algorithm In Part 2, we represented that algorithm using a flowchart, and in Part 3 we developed the pseudocode for that algorithm as follows: 1 2 3 All_words - Keyword For each Entry in Thesaurus If Keyword Entry Word Then For each Word in Entry Synonyms Add Word to All words Stop 5 6 7 8 9 10 11 12 13 14 15 For each Search_word in All_words Count. For each Document in Corpus For each Word in Document If Search_word Word Then Count Count + 1 Output Search_word, Count Now, to finish the computational thinking problem solving process, implement this algorithm in Python in the space below by completing the search function, As you can see the parameter to the function is the keyword\" for which to search. Your program can also access two other variables that you will need to complete the program: Computational Thinking For Problem Solving Assignment 4.7 Property of Penn Engineering

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions