# 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))
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:

# M-13 Assignment # Adapt This Code (Originally From Analytics Vidhya) To Do The Following: #...
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 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 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 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 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...
%%%%Python Question%%% Work from the template acrostic.py, which you can find on the ELMS page for this assignment. • In the Generator class, write an __init__() method with two parameters: self and the path to a text file containing one word per line. This method should read the words from the file, strip off leading and trailing whitespace, and store them in a dictionary where each key is a lower-case letter and each corresponding value is a list of words...
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...
I have a text file that this project needs to read from that has every possible combination of words but I am unsure how to do it. Also I'm pretty sure this program could use a program called "myArraylist" to sort through the text file but I am unsure how to implement this. I am unsure how to show the text file because it is massive, and I don't think it is possible to upload a text file to chegg....
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 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...