Answered step by step
Verified Expert Solution
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
: To be or not to be that is the question
: Whether tis nobler in the mind to suffer The slings
: and arrows of outrageous fortune Or to take arms against
: a sea of troubles And by opposing end them To
: 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
arrows
awry
ay
bare
be
bear
bodkin
bourn
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
whileeof input file
sets and outputs word, lineNum
now process word and lineNum here
ifword found in hash tabledo 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started