1. In as few lines as possible, in JAVASCRIPT with Node.js, code a term frequency program that is similar to how it is done efficiently by this Python version below: #!/usr/bin/env python import heapq, re, sys words = re.findall("[a-z]{2,}", open(sys.argv[1]).read().lower()) for w in heapq.nlargest (25, set(words) - set(open(../stop_words.txt").read().split(",")), words.count): print(w, '-', words.count(w)) IT MUST: take the input files on command line (e.g., node [this javascript file name here] pride-and-prejudice.txt) and output to a text file after filtering the stop words. The input file txt is called pride-and-prejudice.txt and the stop words input file is called stop_words.txt. The output must be made to a file NOT command line output, called output.txt and include ONLY the top 25 results and frequency count (after removing stop words obviously). The stop words looks like this: a,able, about, across, after all, almost, also, am, among, an,and,any,are, as, at, be, because, been, but, by, can, cannot,cou 1d, dear,did, do, do Ensure to stick to these file names in the code solution. 2. In part 2, Using Python, implement a recursive solution to the term frequency problem where parsing words from the stream of characters is recursive. Much like the JSON parse function, the parse function should take a character-level file reader, a list of words (initially empty), and the list of stop words, and should return a list of the non-stop words. The function should iterate to get the characters of one single word, and then recurse to get the rest of the words. You can do the rest of the program (counting words, printing them) in non-recursive style. Make sure to include the command line instructions for this second Python version as well. Also make sure the Output.txt includes the filtered words AND the frequency count.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
1. In as few lines as possible, in JAVASCRIPT with Node.js, code a term frequency program that is similar to how it is
done efficiently by this Python version below:
#!/usr/bin/env python
import heapq, re, sys
words = re.findall("[a-z]{2,}", open(sys.argv[1]).read().lower())
for w in heapq.nlargest(25, set(words) - set(open("../stop_words.txt").read().split(",")), words.count):
print(w, '-', words.count(w))
IT MUST: take the input files on command line (e.g., node [this javascript file name here] pride-and-prejudice.txt) and
output to a text file after filtering the stop words. The input file txt is called pride-and-prejudice.txt and the stop words
input file is called stop_words.txt. The output must be made to a file NOT command line output, called output.txt and
include ONLY the top 25 results and frequency count (after removing stop words obviously).
The stop words looks like this:
a,able, about, across, after, all, almost, also, am, among, an, and, any, are,as,at, be, because, been, but, by, can, cannot, cou
1d, dear, did, do, do
Ensure to stick to these file names in the code solution.
2. In part 2, Using Python, implement a recursive solution to the term frequency problem where parsing words
from the stream of characters is recursive. Much like the JSON parse function, the parse function should take a
character-level file reader, a list of words (initially empty), and the list of stop words, and should return a list of the
non-stop words. The function should iterate to get the characters of one single word, and then recurse to get the rest
of the words. You can do the rest of the program (counting words, printing them) in non-recursive style.
Make sure to include the command line instructions for this second Python version as well. Also make sure the
Output.txt includes the filtered words AND the frequency count.
Transcribed Image Text:1. In as few lines as possible, in JAVASCRIPT with Node.js, code a term frequency program that is similar to how it is done efficiently by this Python version below: #!/usr/bin/env python import heapq, re, sys words = re.findall("[a-z]{2,}", open(sys.argv[1]).read().lower()) for w in heapq.nlargest(25, set(words) - set(open("../stop_words.txt").read().split(",")), words.count): print(w, '-', words.count(w)) IT MUST: take the input files on command line (e.g., node [this javascript file name here] pride-and-prejudice.txt) and output to a text file after filtering the stop words. The input file txt is called pride-and-prejudice.txt and the stop words input file is called stop_words.txt. The output must be made to a file NOT command line output, called output.txt and include ONLY the top 25 results and frequency count (after removing stop words obviously). The stop words looks like this: a,able, about, across, after, all, almost, also, am, among, an, and, any, are,as,at, be, because, been, but, by, can, cannot, cou 1d, dear, did, do, do Ensure to stick to these file names in the code solution. 2. In part 2, Using Python, implement a recursive solution to the term frequency problem where parsing words from the stream of characters is recursive. Much like the JSON parse function, the parse function should take a character-level file reader, a list of words (initially empty), and the list of stop words, and should return a list of the non-stop words. The function should iterate to get the characters of one single word, and then recurse to get the rest of the words. You can do the rest of the program (counting words, printing them) in non-recursive style. Make sure to include the command line instructions for this second Python version as well. Also make sure the Output.txt includes the filtered words AND the frequency count.
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

for the python solutionI'm getting the following error: "RecursionError: maximum recursion depth exceeded while calling a Python object" Please revise the code to avoid this issue when running it. If it makes a difference the counting of words and printing them do not require recursive style for this solution, just the parsing words from the stream of characters needs to be recursive.

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

the first solution makes sense but for the python one, I'm getting the following error. please help. RecursionError: maximum recursion depth exceeded while calling a Python object (base)

 

Please help me and provide a workout around to this error.

 

You can do the rest of the program (counting words, printing them) in non-recursive style. if that helps

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education