Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. Write a helper function named clean_text(txt) that takes a string of text txt as a parameter and returns a list containing the words in

image text in transcribedimage text in transcribedimage text in transcribed

3. Write a helper function named clean_text(txt) that takes a string of text txt as a parameter and returns a list containing the words in txt after it has been "cleaned". This function will be used when you need to process each word in a text individually, without having to worry about punctuation or special characters. Notes: - Because this is a regular function and not a method, you should define it outside of your TextModel class-e.g., before the class header. And when you call clean_text, you should just use the function name; you will not need to prepend a called object. The reason for implementing clean_text as a function rather than a method is that it doesn't need to access the internals of a TextModel object - The extent to which you clean the text is up to you. While you should at least remove common punctuation symbols (e.g., ., ,, and ?), you can decide how many other symbols you want to remove. You may also find it helpful to perform other operations on the string, such as converting all of the characters to lowercase (which you can do using the string method lower) - You may find it helpful to use the string method replace. To remind yourself of how it works, try the following in the Python Shell: >>> s = 'Mr. Smith programs >>> s = s. replace('.', '') 'Mr Smith programs Instead of using replace, you could use a loop to iteratively look at every character in the string and only keep the characters that are not punctuation. However, you should not use recursion to remove the punctuation, since for large files you will run out of memory from too many recursive method calls

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago