Count the word in a document

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Topics: Functions, Files Read and write, Dictionary
Suppose you are given an input file of a document that only contains English words, spaces, commas
(always followed with one space) and periods (always followed with one space). Your task is to read
the file, count the word frequency by ignoring the letter case, output the frequently used words (i.e.,
the words occurred more than once) and the most frequently used word among all of them.
Lab Scenario: Count the word in a document
1. The program reads from an already provided input file: “document.txt”, which contains
several paragraphs separated by an empty line.
2. You will perform the file open operation. And then perform the read operation with your choice of
read functions and read the content of the file.
3. Once you are done reading, start processing the contents of the file using a dictionary where the
key would be the word in lowercase and the corresponding values would be word frequency which
will be the number of occurrences in the documents. For example: “python”: 5
4. Once you are done building your new dictionary you are going to print the new dictionary to the
standard output. The output should only contain English words occurred more than once, and should
not contain any comma, period, or space. The output content should be as follows:
5. The first column of the output file is the word in lowercase and the second column is the frequency
of the word. The very last line of the output should be the most frequently used word among all (For
the given input file, there will be only one such word). No fancy formatting is required.
6. Please don't forget to close the file unless you use ‘with’ keyword.
7. For this lab, you are expected to use dictionary, functions and file I/O operations. There should be
at least 4 user_defined functions:
main(): A sample provided in the template file
file_read() to read the content of the input file
create_dict(): creates and returns a dictionary
display() to print the output

NOTE THE OUTPUT IS DISPLAYED BELOW CODE MUST FOLLOW OUTPUT

 

Word
Frequency
python
very
2
it
2
modules
2
dynamic
and
2
3
are
3
interfaces
2
to
4
as
3
written
2
in
2
of
4
other
2
2
languages
the
3
is
3
language
3
2
programming 2
visual
2
The most frequent word : python
Transcribed Image Text:Word Frequency python very 2 it 2 modules 2 dynamic and 2 3 are 3 interfaces 2 to 4 as 3 written 2 in 2 of 4 other 2 2 languages the 3 is 3 language 3 2 programming 2 visual 2 The most frequent word : python
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY