Question
Given a file containing lines of text, a concordance of that file is a symbol table where the key is a word and the value
Given a file containing lines of text, a concordance of that file is a symbol table where the key is a word and the value is a list of the line numbers where that word occurs in the text file. Write a program called CompileConcordance.java that, as the name indicates, builds a concordance from a text file using these instructions as a guide:
1. Declare an object of type myalgs4.AVLTreeST to use as the concordance. I recommend using an ArrayList object for the list for each word.
2. Prompt the user for the pathname of a text file.
3. Connect StdIn to that text file using StdIn.fromFile().
4. Use a loop to read the text file line by line. See the example program. ReadTextLineByLine.java for how to do that. Inside the loop:
4a. Split each line into words using the String.split() method. You may assume that the words are separated from one another in the text by one or more spaces.
4b. In a loop, enter each of those words into concordance, updating the list of line numbers for each.
5. Use a for-each loop and the keys() method (which is present in both BSTEssential and AVLTreeST) to print, in alphabetical order, a line for each word followed by a tab and then followed by the list of line numbers.
To help, here is the expected output for the data/tinyTale.txt file:
age [2, 2]
belief [3]
best [1]
darkness [4]
despair [5]
epoch [3, 3]
foolishness [2]
hope [5]
incredulity [3]
it [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]
light [4]
of [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]
season [4, 4]
spring [5]
the [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]
times [1, 1]
was [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]
winter [5]
wisdom [2]
worst [1]
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