Skip to content

Commit

Permalink
fixed NOT, ranking display
Browse files Browse the repository at this point in the history
  • Loading branch information
karinashin committed May 2, 2022
1 parent 45f3f59 commit f7f15f1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
51 changes: 28 additions & 23 deletions QueryProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ void QueryProcessor::parseQuery(string& q, DSAVLTree<Word>& words, DSAVLTree<Wor
}
else{
setUnion(parseAndOr(), words);
// for (int i = 0; i < queryWords.size(); i++){
// cout << queryWords.at(i).getStr() << endl;
// }
}
}
else if (curr.getStr() == "not"){
Expand All @@ -48,7 +51,7 @@ void QueryProcessor::parseQuery(string& q, DSAVLTree<Word>& words, DSAVLTree<Wor

if (words.contains(word1)){
complement(words.find(words.getRoot(), word1).getDocs());
queryWords.push_back(words.find(words.getRoot(), word1));//for ranking
// queryWords.push_back(words.find(words.getRoot(), word1));//won't have any frequency in docs since its "NOT"
}
else
cout << word1.getStr() << " is not found." << endl;
Expand Down Expand Up @@ -88,7 +91,7 @@ void QueryProcessor::parseQuery(string& q, DSAVLTree<Word>& words, DSAVLTree<Wor
space = query.find(" ");//to check if youve reached the end of the query
}

rankIndex();//TODO
rankIndex();
}

vector<Word> QueryProcessor::parseAndOr()
Expand Down Expand Up @@ -166,7 +169,9 @@ void QueryProcessor::setUnion(vector<Word> a, DSAVLTree<Word>& tree)//OR keyword
vector<Document> 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;
Expand Down Expand Up @@ -268,7 +273,6 @@ void QueryProcessor::addPersonOrg(vector<Document>& 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;
Expand All @@ -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;
Expand All @@ -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--)
Expand Down
5 changes: 3 additions & 2 deletions UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

0 comments on commit f7f15f1

Please sign in to comment.