From f7f15f11306047ac35ad3a9093a32b4a9287ab81 Mon Sep 17 00:00:00 2001 From: karinashin Date: Mon, 2 May 2022 15:52:50 -0500 Subject: [PATCH] fixed NOT, ranking display --- QueryProcessor.cpp | 51 +++++++++++++++++++++++++--------------------- UserInterface.cpp | 5 +++-- main.cpp | 4 +--- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/QueryProcessor.cpp b/QueryProcessor.cpp index 57c80c7..1a2a70b 100644 --- a/QueryProcessor.cpp +++ b/QueryProcessor.cpp @@ -30,6 +30,9 @@ void QueryProcessor::parseQuery(string& q, DSAVLTree& words, DSAVLTree& words, DSAVLTree& words, DSAVLTree QueryProcessor::parseAndOr() @@ -166,7 +169,9 @@ void QueryProcessor::setUnion(vector a, DSAVLTree& tree)//OR keyword vector temp; if (tree.contains(a.at(i))){ temp = tree.find(tree.getRoot(), a.at(i)).getDocs(); +// cout << "a.at(i): " << a.at(i).getStr() << endl; queryWords.push_back(tree.find(tree.getRoot(), a.at(i))); +// cout << queryWords.at(queryWords.size()-1).getDocs().size(); } else{ cout << a.at(i).getStr() << " is not found." << endl; @@ -268,7 +273,6 @@ void QueryProcessor::addPersonOrg(vector& a)//remove any docs from fin void QueryProcessor::rankIndex() { - //TODO something with NOT operator doesn't work with ranking system cout << "Rank index" << endl; // cout << "finalIndex size " << finalIndex.size() << endl; // cout << "query words size: " << queryWords.size() << endl; @@ -281,10 +285,11 @@ void QueryProcessor::rankIndex() //get the each words frequency in the current doc and add them all together sum += queryWords.at(i).getDocFreq(finalIndex.at(queryIndex));//add total freq of each word for this doc // cout << queryWords.at(i).getDocFreq(finalIndex.at(queryIndex)) << " " << finalIndex.at(queryIndex).getPath() << endl; - } + }//doc not found freqs.push_back(sum); -// cout << "sum: " << sum << endl; + cout << "sum: " << sum << endl; } + cout << "done with for loop" << endl; //result: total frequency for each doc // cout << "Frequency" << endl; @@ -293,25 +298,25 @@ void QueryProcessor::rankIndex() //get the top 15 docs with the highest freq - for (int n = 0; n < 15; n++){ -// if (n > freqs.size() || freqs.size() == 0)//less that 15 docs in the finalIndex +// for (int n = 0; n < 15; n++){ +//// if (n > freqs.size() || freqs.size() == 0)//less that 15 docs in the finalIndex +//// break; +// int highest = freqs.at(0); +// int index = 0; +// if (n > freqs.size())//less that 15 docs in the finalIndex // break; - int highest = freqs.at(0); - int index = 0; - if (n > freqs.size())//less that 15 docs in the finalIndex - break; - for (int i = 1; i < freqs.size(); i++)//find the next highest freq - { - if (freqs.at(i) > highest){//get highest freq - highest = freqs.at(i); - index = i; - } - } - best.push_back(finalIndex.at(index));//get the corresponding doc for that freq -// cout << "next higheset frequency: " << freqs.at(index) << endl; - freqs.erase(freqs.begin() + index); - finalIndex.erase(finalIndex.begin() + index); - } +// for (int i = 1; i < freqs.size(); i++)//find the next highest freq +// { +// if (freqs.at(i) > highest){//get highest freq +// highest = freqs.at(i); +// index = i; +// } +// } +// best.push_back(finalIndex.at(index));//get the corresponding doc for that freq +//// cout << "next higheset frequency: " << freqs.at(index) << endl; +// freqs.erase(freqs.begin() + index); +// finalIndex.erase(finalIndex.begin() + index); +// } // cout << "Best 15: " << endl; // for (int i = best.size()-1; i >= 0; i--) diff --git a/UserInterface.cpp b/UserInterface.cpp index 9be212a..a6d1f9f 100644 --- a/UserInterface.cpp +++ b/UserInterface.cpp @@ -56,8 +56,9 @@ void UserInterface::run(const string& file) cin >> choice; if (choice == "0")//exit break; - else if (choice == "1" || choice == "2" || choice == "3" || choice == "4" || choice == "5" || choice == "6" || choice == "7" || choice == "8" || choice == "9" || choice == "10" || choice == "11" || choice == "12" || choice == "13" || choice == "14" || choice == "15"){ - showText(process.getFinal().at(stoi(choice) - 1)); +// else if (choice == "1" || choice == "2" || choice == "3" || choice == "4" || choice == "5" || choice == "6" || choice == "7" || choice == "8" || choice == "9" || choice == "10" || choice == "11" || choice == "12" || choice == "13" || choice == "14" || choice == "15"){ + else if (stoi(choice) > 0 && stoi(choice) <= process.getBest().size()){ + showText(process.getBest().at(stoi(choice) - 1)); cout << endl; } else diff --git a/main.cpp b/main.cpp index 03578a7..4a539d3 100644 --- a/main.cpp +++ b/main.cpp @@ -12,9 +12,7 @@ using namespace std; int main(int argc, char** argv) { - //mnt/c/users/18476/c++/searchData 2648 files - //TODO LIST: Fix ranking articles, make persistence file (figure out how to erase contents of file) - + //mnt/c/users/18476/c++/searchData UserInterface parse; parse.run(argv[1]); }