Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a concordance from a text file Your program will read a file of text and produce a concordance from it . For example, output

Create a concordance from a text file
Your program will read a file of text and produce a concordance from it. For example, output of the program for Hamlets famous soliloquy by Shakespeare will be:
the file, each line preceded by a line number
1: To be or not to be that is the question
2: Whether tis nobler in the mind to suffer The slings
3: and arrows of outrageous fortune Or to take arms against
4: a sea of troubles And by opposing end them To
5: die to sleep No more and by a sleep to
...
followed by a concordance, which shows each important word in alphabetical order, with a count of the number of occurrences, and line numbers:
Word Count Line numbers
...
arms 13
arrows 13
awry 126
ay 19
bare 117
be 31,8
bear 313,18,21
bodkin 117
bourn 120
...
NOTE: 'be' must occur several times on the same line do not repeat a line number
Review my bst and circular linked list example programs
You will use my bst and circular linked list example classes, largely unchanged. So download, read, run and understand these example programs first:
my Full BST from Implementation of binary trees
my Circular list from Finish linked lists
The binary search tree
Build a binary search tree of the important words read from the file:
All of the file reading and word processing is given to you
a word is defined as consecutive alphabetic characters
spaces, newlines and punctuation characters are used only to mark work boundaries, are not included in the tree
any uppercase letters are converted to lowercase
all of the file reading and word processing is given to you
The WordCount class
The WordCount class represents all the information for a word in the concordance. So WordCount will be the information stored in the generic bst.
You must write this class. Three instance variables, then appropriate methods:
public class WordCount implements Comparable
{
protected String word;
protected int count;
protected CircularList lineNums;
...
lineNums here will be a reference to a circular linked list of integers, used to store line numbers of occurrence:
use a circular linked list because, with just a single reference its easy to add at rear, print from the front in order
again, do not add a new item to the list if the word occurs again on the same line.
Use hashing to omit common words
We will use hashing to omit common, uninteresting words. Hashing will be covered next week, will be added to the lab then. Ignore for now, make the program work for every word.
main() is given to you
main() does all the file input and output for you, setting the word and linenum to be processed. main() in pseudocode will be something like:
main
{
build then output hash table //do later
while(!eof input file){
sets and outputs word, lineNum
//now process word and lineNum here
if(!word found in hash table){//do later
if (word is found in bst)
update in bst
else
insert into bst
}
}
output bst
}
Many classes are given to you
Download and unzip the Tree lab project from Canvas, Implementation of binary trees module, Example programs. Open the project in BlueJ and see that the bst and circular linked list classes are given to you.
Build and run the program, see that it outputs the data file, but does nothing else. Read Tester::main(), see that it provides words and line numbers for you. You must write your code that uses the bst to process these, where the comment says //now process word and lineNum here.

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

Describe Hartleys seven varieties of pleasure.

Answered: 1 week ago