/************************************************************* Author: Dana Vrajitoru Class: C243 Data Structures Date: February 17, 2012 File: main.cc Description: A test program for the Porter transformation. It reads one word at a time from the console and outputs the transformed word until the input ends by an eof - a CTRL-D under a Linux terminal or the end of the file in case or redirection. ***************************************************************/ #include #include using namespace std; #include "porter.h" #include "HashTable.h" void ReadStoplist(HashTable &stoplist); void IndexWords(HashTable &stoplist, HashTable &indexing); void Increment(HashTable &indexing, string word); int main() { HashTable stoplist, indexing; ReadStoplist(stoplist); stoplist.statistic(); IndexWords(stoplist, indexing); cout << "Here is the indexing of your text" << endl; indexing.print(); return 0; } // Inputs the stoplist and stores it in the table. void ReadStoplist(HashTable &stoplist) { char word[KEYWORDSIZE]; ifstream fin("stopWords"); WordCounter wordc; do { fin >> word; if (!fin.eof()) { wordc.setWord(word); stoplist.insert(wordc); } } while (!fin.eof()); fin.close(); } // 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. void IndexWords(HashTable &stoplist, HashTable &indexing) { char word[KEYWORDSIZE]; WordCounter wordc; cout << "Enter words separated by spaces or new lines.\n" << "The program will output the Porter transform of the words.\n" << "End the input with Ctrl-D." << endl; while (!cin.eof()) { cin >> word; if (!cin.eof()) { to_lower_case(word); clean(word); // For the student to add: the following 2 instructions must be // executed only if the word is not in the table stoplist. strip_affixes(word); Increment(indexing, word); } } cout << endl; } // 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 insert it 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. void Increment(HashTable &indexing, string word) { // Code to be implemented by the student. }