-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrapped.cpp
More file actions
267 lines (224 loc) · 4.81 KB
/
Trapped.cpp
File metadata and controls
267 lines (224 loc) · 4.81 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#include "stdafx.h"
#include "Trapped.h"
#include <fstream>
Trapped::Trapped()
{
std::ifstream t;
t.open("language/verbs.txt");
while (t) {
std::string line;
std::getline(t, line);
verbs.push_front(line);
}
t.close();
t.open("language/nouns.txt");
while (t) {
std::string line;
std::getline(t, line);
nouns.push_front(line);
}
t.close();
t.open("language/adjectives.txt");
while (t) {
std::string line;
std::getline(t, line);
adjectives.push_front(line);
}
t.close();
t.open("language/goodwords.txt");
while (t) {
std::string line;
std::getline(t, line);
goodwords.push_front(line);
}
t.close();
t.open("language/badwords.txt");
while (t) {
std::string line;
std::getline(t, line);
badwords.push_front(line);
}
t.close();
t.open("language/prepositions.txt");
while (t) {
std::string line;
std::getline(t, line);
prepositions.push_front(line);
}
t.close();
t.open("language/possible_syntax.txt");
std::list<word_class>* c = new std::list<word_class>();
while (t) {
std::string line;
std::getline(t, line);
if (line != "")
{
if (line == "noun")
{
c->push_back(NOUN);
}
else if (line == "verb")
{
c->push_back(VERB);
}
else if (line == "adjective")
{
c->push_back(ADJECTIVE);
}
else if (line == "goodword")
{
c->push_back(GOODWORD);
}
else if (line == "preposition")
{
c->push_back(PREPOSITION);
}
else if (line == "badword")
{
c->push_back(BADWORD);
}
}
else
{
possible_syntax.push_back(c);
c = new std::list<word_class>();
}
}
t.close();
}
void Trapped::Draw()
{
}
void Trapped::PreUpdate()
{
}
void Trapped::PostUpdate()
{
}
void Trapped::RecieveString(const char * got)
{
interaction* i = new interaction();
std::string recieved = got;
std::list<wordtype*> syntaxis;
std::string word;
int length = recieved.length();
for (int i = 0; i <= length; ++i)
{
if (recieved[i] == 32 || i==length)
{
Analyze_segment(word.c_str());
wordtype* t = new wordtype();
t->word = word;
Getwordtype(word.c_str(),t);
syntaxis.push_back(t);
word.clear();
}
else
{
word += recieved[i];
}
}
Analyze_syntaxis(syntaxis);
past_interactions.push_back(i);
}
void Trapped::Analyze_segment(const char * str)
{
std::string word = str;
}
void Trapped::Analyze_syntaxis(std::list<wordtype*>& words)
{
//words is the array of worlds by type(if a noun can be a noun or a verb is taken into consideration)
//if its a salutation it'll be discarded therefore hi, hey, hello and what's up... are done
//if its anything else we check for patterns to see if the sentence makes sense, if it does we guess the meaning and keep moving
// this iterates all the supported syntaxes
for (std::list<std::list<word_class>*>::iterator it_h = possible_syntax.begin(); it_h != possible_syntax.end(); ++it_h)
{
//this iterates each syntaxes words
int max_score = words.size();
int score = 0;
std::list<wordtype*>::iterator it = words.begin();
for (std::list<word_class>::iterator it_l = (*it_h)->begin(); it_l != (*it_h)->end() && it != words.end(); ++it_l, ++it)
{
if ((*it)->isclass(*it_l))//are they supported??
{
//if he falls here all the time we win
score++;
}
}
if (score == max_score)
{
//SUPPORTED SYNTAX
printf_s("IT_WORKS");
break;
}
}
}
void Trapped::Getwordtype(const char * word, wordtype* tofill)
{
if (isverb(word))
{
tofill->classesitis.push_back(VERB);
}
if (isnoun(word))
{
tofill->classesitis.push_back(NOUN);
}
if (isgoodword(word))
{
tofill->classesitis.push_back(GOODWORD);
}
if (isbadword(word))
{
tofill->classesitis.push_back(BADWORD);
}
if (ispreposition(word))
{
tofill->classesitis.push_back(PREPOSITION);
}
if (isadjective(word))
{
tofill->classesitis.push_back(ADJECTIVE);
}
}
bool Trapped::isverb(const char * word)
{
if (std::find(std::begin(verbs), std::end(verbs), word) != std::end(verbs))
return true;
else
return false;
}
bool Trapped::isnoun(const char * word)
{
if (std::find(std::begin(nouns), std::end(nouns), word) != std::end(nouns))
return true;
else
return false;
}
bool Trapped::isgoodword(const char * word)
{
if (std::find(std::begin(goodwords), std::end(goodwords), word) != std::end(goodwords))
return true;
else
return false;
}
bool Trapped::isbadword(const char * word)
{
if (std::find(std::begin(badwords), std::end(badwords), word) != std::end(badwords))
return true;
else
return false;
}
bool Trapped::isadjective(const char * word)
{
if (std::find(std::begin(adjectives), std::end(adjectives), word) != std::end(adjectives))
return true;
else
return false;
}
bool Trapped::ispreposition(const char * word)
{
if (std::find(std::begin(prepositions), std::end(prepositions), word) != std::end(prepositions))
return true;
else
return false;
}