-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueryProcessor.cpp
94 lines (81 loc) · 2.41 KB
/
QueryProcessor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* File: QueryProcessor.cpp
* Author: carter
*
* Created on November 21, 2012, 10:06 PM
*/
#include "QueryProcessor.h"
QueryProcessor::QueryProcessor() {
}
QueryProcessor::QueryProcessor(const QueryProcessor& orig) {
}
QueryProcessor::~QueryProcessor() {
}
void QueryProcessor::parseQuery(string query, StopWords stopList) {
stringstream parseQuery(query);
string buffer;
parseQuery >> buffer;
if (buffer == "AND") {
while (buffer != "NOT" ) {
parseQuery >> buffer;
if (checkStopWords(buffer, stopList)) {
string *strptr = new string(buffer);
AND.push_back(strptr);
}
}
if (parseQuery.good()) {
parseQuery >> buffer;
while (parseQuery.good()) {
if (checkStopWords(buffer, stopList)) {
string *strptr = new string(buffer);
NOT.push_back(strptr);
}
parseQuery >> buffer;
}
}
} else if (buffer == "OR") {
while (buffer != "NOT" && parseQuery.good()) {
parseQuery >> buffer;
if (checkStopWords(buffer, stopList)) {
string *strptr = new string(buffer);
OR.push_back(strptr);
}
}
parseQuery >> buffer;
while (parseQuery) {
if (checkStopWords(buffer, stopList)) {
string *strptr = new string(buffer);
NOT.push_back(strptr);
}
parseQuery >> buffer;
}
} else {
singleWordEntry = buffer;
}
}
void QueryProcessor::printQuery() {
cout << "AND:" << endl;
for (int x = 0; x < AND.size(); x++)
cout << *AND[x] << endl;
cout << "OR:" << endl;
for (int x = 0; x < OR.size(); x++)
cout << *OR[x] << endl;
cout << "NOT:" << endl;
for (int x = 0; x < NOT.size(); x++)
cout << *NOT[x] << endl;
}
bool QueryProcessor::checkStopWords(string word, StopWords stopList) {
string word2;
for (int x = 0; x < stopList.getSize(); x++) {
cout << word << endl;
word2 = stopList.getStopWord(x);
cout << word2;
if (word == word2)
return false;
// if (word == stopList.getStopWord(x))
// return false;
// else if (x == 666)
// return true;
}
return true;
}