Question

# M-13 Assignment # Adapt This Code (Originally From Analytics Vidhya) To Do The Following: #...

# M-13 Assignment

# Adapt This Code (Originally From Analytics Vidhya) To Do The Following:

# 1. Accept a User Input for the Text to Remove Stopwords From

# 2. Print a Count of How Many Stopwords Were Removed

# 3. Display Both the Original and Filtered Sentences

# 4. Clean Up and Remove Unnecessary Code

# importing libraries

import nltk

from nltk.corpus import stopwords

from nltk.tokenize import word_tokenize

set(stopwords.words('english'))


# sample sentence

text = """He determined to drop his litigation with the monastry, and relinguish his claims to the wood-cuting and

fishery rihgts at once. He was the more ready to do this becuase the rights had become much less valuable, and he had

indeed the vaguest idea where the wood and river in question were."""

# set of stop words

stop_words = set(stopwords.words('english'))

# tokens of words

word_tokens = word_tokenize(text)

filtered_sentence = []

for w in word_tokens:

if w not in stop_words:

filtered_sentence.append(w)



print("\n\nOriginal Sentence \n\n")

print(" ".join(word_tokens))

print("\n\nFiltered Sentence \n\n")

print(" ".join(filtered_sentence))

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code has been explained in the comments itself:

Please refer to the screenshots for the indentation:

Please comment before downvoting, will resolve asap

Code :

# importing libraries
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize

# sample sentence
text = """He determined to drop his litigation with the monastry, and relinguish his claims to the wood-cuting and
fishery rihgts at once. He was the more ready to do this becuase the rights had become much less valuable, and he had
indeed the vaguest idea where the wood and river in question were."""


# set of stop words
stop_words = set(stopwords.words('english'))

# tokens of words
word_tokens = word_tokenize(text)

# total number of words in the original sentence
total_words_original = len(word_tokens)

filtered_sentence = []

for w in word_tokens:
   if w not in stop_words:
       filtered_sentence.append(w)

# total number of words in the filtered sentence
total_words_filtered = len(filtered_sentence)

total_stop_words_removed = total_words_original - total_words_filtered
print("\n\nOriginal Sentence \n\n")
print(" ".join(word_tokens))
print("\n\nFiltered Sentence \n\n")
print(" ".join(filtered_sentence))

print("\n\nNumber of stop words removed : " + str(total_stop_words_removed) + "\n\n")



Screenshots:

Code:

Output:

Add a comment
Know the answer?
Add Answer to:
# M-13 Assignment # Adapt This Code (Originally From Analytics Vidhya) To Do The Following: #...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lesson Assignment There are 13 questions regarding slicing. The first 10 are required to pass. The...

    Lesson Assignment There are 13 questions regarding slicing. The first 10 are required to pass. The last 3 are extra credit. You will place all your answers in the lesson.py tab. Select that tab and take a look at how it's done. For your answers, each function (already defined) returns a tuple: the first item is the answer using index notation (e.g. text[16:20]) the second item is the answer using slice notation (e.g. slice(16,20,None)) the numbers you use for the...

  • please write a C++ code Problem A: Word Shadow Source file: shadow.cpp f or java, or.cj...

    please write a C++ code Problem A: Word Shadow Source file: shadow.cpp f or java, or.cj Input file: shadow.in in reality, when we read an English word we normally do not read every single letter of that word but rather the word's "shadow" recalls its pronunciation and meaning from our brain. The word's shadow consists of the same number of letters that compose the actual word with first and last letters (of the word) in their original positions while the...

  • My Python file will not work below and I am not sure why, please help me...

    My Python file will not work below and I am not sure why, please help me debug! ********************************* Instructions for program: You’ll use these functions to put together a program that does the following: Gives the user sentences to type, until they type DONE and then the test is over. Counts the number of seconds from when the user begins to when the test is over. Counts and reports: The total number of words the user typed, and how many...

  • FIRST: Write code that prompts the user for the name of a text file, opens that...

    FIRST: Write code that prompts the user for the name of a text file, opens that file if it exists and reads the file one line at a time printing each line to the screen. You must implement the file read in a try/catch block rather than throwing the exception on the main method. NEXT: Modify your code so that the program takes the name of two files from the command line, opens the first file if it exists for...

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

  • How do I start this c++ code homework? Write a code in C++ for a BlackJack...

    How do I start this c++ code homework? Write a code in C++ for a BlackJack card game using the following simplified rules: Each card has a numerical value. Numbered cards are counted at their face value (two counts as 2 points, three, 3 points, and so on) An Ace count as either 1 point or 11 points (whichever suits the player best) Jack, queen and king count 10 points each The player will compete against the computer which represents...

  • This project is meant to give you experience writing linked lists and graphs. As such, you...

    This project is meant to give you experience writing linked lists and graphs. As such, you are not permitted to use arrays or any data structure library. You may, however, make use of code presented in class and posted to Blackboard. Objective Your goal for this project is to take a block of text, analyze it, and produce random sentences in the style of the original text. For example, your program, given Wizard of Oz, might produce: how quite lion...

  • Assignment Overview This programming assignment is intended to demonstrate your knowledge of the following:  Writing...

    Assignment Overview This programming assignment is intended to demonstrate your knowledge of the following:  Writing a while loop  Writing a for loop  Writing a while loop with a sentinel value Chocolate Coupons Foothill Fro-cho, LLC, gives customers a coupon every time they purchase a chocolate bar. After they earn a certain number of coupons, they qualify for a free chocolate bar, which they may use toward the purchase of a single chocolate bar. Usually, 7 is the...

  • Hi there! I need to compare two essay into 1 essay, and make it interesting and...

    Hi there! I need to compare two essay into 1 essay, and make it interesting and choose couple topics which im going to talk about in my essay FIRST ESSAY “Teaching New Worlds/New Words” bell hooks Like desire, language disrupts, refuses to be contained within boundaries. It speaks itself against our will, in words and thoughts that intrude, even violate the most private spaces of mind and body. It was in my first year of college that I read Adrienne...

  • Read “Instituionalizing our Demise: America vs Multiculturalism” by Roger Kimball on pg 268 and “Reinventing America”...

    Read “Instituionalizing our Demise: America vs Multiculturalism” by Roger Kimball on pg 268 and “Reinventing America” Call for a new national indentity” by Elizabeth Martinez on pg 275. Create a double entry notebook for each reading selection It should be atleast five observation and responses. wric 268 PART 2 essay pro. exactly how and why their authors disagree. Instead of with parties in conflict as mediators do, you will nt of view designed to appeal to both sides, mediatn posing...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT