Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a command line application Problem2.java that indexes the words contained in a text file. Your program should go through the input file line by
Write a command line application Problem2.java that indexes the words contained in a text file. Your program should go through the input file line by line. For each line, it extracts each word, and insert that word, along with it's line number into an AVL tree. Each element of the AVL tree should contain a unique word and a linked list of line numbers where that word occurs. note that you must include the UnderFLowException class, which is available here). Modify this file directly and add the following functionality: o Make sure the elements in the AvlTree are pairs of a word and a linked lists storing line numbers. The relative order of elements in the data structure should depend on the word only o Write the method public void indexWord(String word, int line) that adds an occurrence of the word word in line line. If a word already exists in the AVL Tree, simply add the new line number to the existing node. If a word appears on the same line twice, it should only have one entry in the list for that line. o Write the method public List getLinesForWord String word) that looks up a word and returns a list of lines in which it occurs. o Write the method public void printIndexO the prints out each unique word that is stored in the Avl tree along with a list of line numbers in which that word appears. Finally, the main method in Problem2. java should create an instance of your AvlTree and uses it to indexes the words contained in a text file (provided to the program as a command line argument). Ignore case in the input text (insert everything as lower case), and ignore all punctuation. When indexing has finished, the program should call the printIndex method to display a list of unique words in the text file and the line numbers in which that word occurs. UnderFlowException class *Exception class for access in empty containers such as stacks, queues, and priority queues. * Cauthor Mark Allen Weiss public class UnderflowException extends RuntimeException Write a command line application Problem2.java that indexes the words contained in a text file. Your program should go through the input file line by line. For each line, it extracts each word, and insert that word, along with it's line number into an AVL tree. Each element of the AVL tree should contain a unique word and a linked list of line numbers where that word occurs. note that you must include the UnderFLowException class, which is available here). Modify this file directly and add the following functionality: o Make sure the elements in the AvlTree are pairs of a word and a linked lists storing line numbers. The relative order of elements in the data structure should depend on the word only o Write the method public void indexWord(String word, int line) that adds an occurrence of the word word in line line. If a word already exists in the AVL Tree, simply add the new line number to the existing node. If a word appears on the same line twice, it should only have one entry in the list for that line. o Write the method public List getLinesForWord String word) that looks up a word and returns a list of lines in which it occurs. o Write the method public void printIndexO the prints out each unique word that is stored in the Avl tree along with a list of line numbers in which that word appears. Finally, the main method in Problem2. java should create an instance of your AvlTree and uses it to indexes the words contained in a text file (provided to the program as a command line argument). Ignore case in the input text (insert everything as lower case), and ignore all punctuation. When indexing has finished, the program should call the printIndex method to display a list of unique words in the text file and the line numbers in which that word occurs. UnderFlowException class *Exception class for access in empty containers such as stacks, queues, and priority queues. * Cauthor Mark Allen Weiss public class UnderflowException extends RuntimeException
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