/****************************************************************************** Author: Dana Vrajitoru Class: C307 I308 Updated: March 2022 File: main.java Description: A test program for hash tables. It reads one word at a time from the console until the input ends by the string "||". Words that are part of the list of stop words are discarded. For all the others, it applied the Porter transformation to extract the root, then updates the count of this root in the indexing table. After the input ends, the indexing table and some statistics are output. *******************************************************************************/ package hashTable; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Main { // Main function: create the stopList, call the function reading the // words and indexing them, and then printing out the result. public static void main(String[] args) { HashTable stopList, indexing; stopList = new HashTable(); indexing = new HashTable(); readStopList(stopList); stopList.print(); stopList.statistic(); indexWords(stopList, indexing); System.out.println("Here is the indexing of your text"); indexing.print(); // Clear out the tables before we leave stopList.clear(); indexing.clear(); } // main() // Inputs the stopList and stores it in the table. public static void readStopList(HashTable stopList) { String word; File fin = new File("stopWords.txt"); if (!fin.exists()) { System.out.println("Error reading the stop list file."); System.exit(1); } Scanner scan; try { scan = new Scanner(fin); WordCounter wordc = new WordCounter("", 1); do { word = scan.next(); if (scan.hasNext()) { wordc.setWord(word); stopList.insert(wordc); } } while (scan.hasNext()); scan.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } // readStopList() // Reads a word at a time from the console, verifies that it's not in // the stopList, and if it's not, it applies the Porter transform to // it, then it indexes it in the table indexing. public static void indexWords(HashTable stopList, HashTable indexing) { String word = ""; WordCounter wordc = new WordCounter(); System.out.println("Enter words separated by spaces or new lines."); System.out.println("The program will output the Porter transform of the words."); System.out.println("End the input with ||."); Scanner scan = new Scanner(System.in); word = scan.next(); while (!word.contains("||")) { word = word.toLowerCase(); word = Porter.clean(word); // For the student to add: the following 2 instructions must be // executed only if the word is not in the table stopList. // !!!!!!!!!!!!!! word = Porter.stripAffixes(word); increment(indexing, word); // read the word for the next loop word = scan.next(); } System.out.println(); scan.close(); } // indexWords() // It should increment the indexing of the given word in the // table. This means that if the word can't be found in the table, // then it should be inserted with a count of 1. Otherwise it should // remove the word from the table, increment the count of the object // that has been removed, then insert it back with the new number. public static void increment(HashTable indexing, String word) { // Code to be provided by the student } // increment() }