Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Define an IndexTree such that each node has data fields to store a word, the count of occurrences of that word, and a list of

Define an IndexTree such that each node has data fields to store a word, the count of occurrences of that word, and a list of all lines that word appeared on. Use an ArrayList to store line numbers. Use an IndexTree object to store an index of all the words that are in the provided text file, then display the index by performing an inorder traversal of the tree

Please implement the tree instructor provide code

package index; import java.util.List; public class IndexNode { // The word for this entry String word; // The number of occurences for this word int occurences; // A list of line numbers for this word. List list; IndexNode left; IndexNode right; //Constructors // Complete This // return the word and the lines it appears on. // string must be one line public String toString(){ return ""; } } 
package index; public class IndexTree{ // This is your root private IndexNode root; // Make your constructor // complete the methods below // call your recursive add method public void add(String word, int lineNumber){ } //your recursive method for add // Think about how this works // When you add the word to the index, if it already exists, you want to // add it to the IndexNode that already exists // otherwise make a new indexNode private IndexNode add(IndexNode root, String word, int lineNumber){ return null; } // returns true if the word is in the index public boolean contains(String word){ return false; } // call your recursive method public void delete(String word){ } // your recursive case // remove the word and all the entries for the word private IndexNode delete(IndexNode root, String word){ return null; } // prints all the words in the index in inorder order public void printIndex(){ } public static void main(String[] args){ IndexTree index = new IndexTree(); // add all the words to the tree // print out the index // test removing a word from the index } } 

import java.io.*;

public class ReadingFromFileExample { // adapted from // https://www.caveofprogramming.com/java/java-file-reading-and-writing-files-in-java.html public static void main(String [] args) {

String fileName = "pg2240.txt"; String line = null; BufferedReader bufferedReader;

try {

bufferedReader= new BufferedReader(new FileReader(fileName));

while(bufferedReader.ready()) { line = bufferedReader.readLine();

//System.out.println(line); String[] words = line.split("\\s+"); for(String word : words){ word = word.replaceAll("[.;,?]", ""); word = word.replaceAll(",", ""); System.out.println(word); } }

bufferedReader.close(); } catch(FileNotFoundException e) { System.err.println("File not found"); } // catch any other exception catch(Exception e) { e.printStackTrace(); } } }

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_2

Step: 3

blur-text-image_3

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

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students explore these related Databases questions