-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEliza.h
247 lines (187 loc) · 4.71 KB
/
Eliza.h
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
#ifndef __ELIZA__H__
#define __ELIZA__H__
//#pragma warning(disable:4786)
//#include "recorder.h"
#include "strings.h"
//#include <windows.h>
#include <sstream>
#include <fstream>
#include <stack>
//#include <ctime>
//#define PAUSE(x) Sleep(x);
typedef struct {
vstring keywords;
vstring contexts;
vstring responses;
vstring cmd;
} data;
typedef struct {
std::string verbP1;
std::string verbP2;
} transpos;
typedef struct {
std::string verbP1;
std::string verbP2;
} correction;
class Eliza {
public:
Eliza ()
: m_bQuitProgram(0), linePos(2), m_bNewData(0), m_bMemoryRecall(0),
m_bLearning(0), m_nUserRepeatCount(0), m_sUserName("USER")
{
//seed_random_generator();
//read_time_delay(time_delay);
}
~Eliza ()
{
logfile.flush();
logfile.close();
};
void load_data();
void save_data();
void respond();
void preProcessInput();
void preProcessResponse();
void memorise_input();
void get_input();
void get_input(std::string lne); //ADD BY SGW32
void start();
void print_response();
void print_database_content();
void save_unknown_sentences();
void save_log(std::string str);
bool quit() const {
return m_bQuitProgram;
}
bool learn() const {
return m_bNewData;
}
private:
void saveTopic(const vstring vList, const std::string sSymbol);
void saveComment(const std::string comment);
void saveTransposTable();
void saveCorrections();
void saveKeyWords();
bool transpose( std::string &str ) const;
void transpose_sentence( std::string &str );
void correct_sentence( std::string &str ) const;
void handle_repetition();
void handle_user_repetition();
void handle_unknown_sentence();
void handle_null_input();
void verify_context(vstring vContext);
void verify_keyword_boundary(std::string keyWord, int pos);
void print_current_data();
void add_response(vstring v);
void find_keyword();
void find_response();
void execute();
void dump_data();
void select_response();
void extract_suffix();
void clear();
bool bot_repeat() const;
bool similar_response() const;
bool null_input() const {
return m_sInput.length() == 0;
}
bool bot_is_repeating() const {
return (bot_repeat() || similar_response());
}
bool user_repeat() const {
return (m_sInput.length() > 0 && m_sInput == m_sPrevInput);
}
bool bot_understand() const {
return response_list.size() > 0;
}
bool good_context() const {
return m_bGoodContext;
}
bool wrong_boundary() const {
return m_bWrongBoundary;
}
void reset_repeat_count() {
m_nUserRepeatCount = 0;
}
void save_prev_response() {
m_sPrevResponse = m_sResponse;
}
void save_prev_input() {
m_sPrevInput = m_sInput;
}
void save_prev_responses() {
if(m_sResponse.length() > 0) {
previous_responses.push(m_sResponse);
}
}
void remind_prev_subject();
void check_quit_message() {
if(m_sResponse.find("BYE") != std::string::npos) {
m_bQuitProgram = 1;
}
}
void simulate_thinking() {
//PAUSE(700 + rand() % 3000);
}
void simulate_typist() {
//print_string(m_sResponse.c_str(), time_delay, linePos);
//linePos += 3;
}
void seed_random_generator() {
// srand((unsigned) time(NULL));
}
bool is_template(std::string str) {
return (str.find("*") != std::string::npos ||
str.find("@") != std::string::npos ||
str.find("%") != std::string::npos);
}
void findSymbol(std::string str);
void save_user_name();
bool isGoodKey(const std::string key, const std::string bkey, int pos, int bestp) const;
private:
std::stack<std::string> previous_responses;
std::vector<transpos> transpos_list;
std::vector<correction> correction_list;
std::stack<std::string> memory;
std::vector<data> database;
std::vector<double> time_delay;
std::fstream scriptfile;
std::fstream logfile;
data current_data;
Tokenizer tok;
correction current_correction;
std::string m_sInput;
std::string m_sResponse;
std::string m_sPrevInput;
std::string m_sKeyWord;
std::string m_sSuffix;
std::string m_sPrevResponse;
std::string m_sUserName;
std::string m_sCommand;
std::string m_sSymbol;
vstring nullResponse;
vstring myResponse;
vstring noKeyWord;
vstring topicChanger;
vstring subjectRecall;
vstring unknownSentences;
vstring inputRepeat;
vstring keyword_list;
vstring response_list;
vstring previous_inputs;
vstring vResponseLog;
vstring command_list;
vstring comments;
vstring signOn;
unsigned int linePos;
unsigned int m_nUserRepeatCount;
unsigned int m_nCorrectionNum;
unsigned int m_nTransPosNum;
bool m_bWrongBoundary;
bool m_bGoodContext;
bool m_bQuitProgram;
bool m_bLearning;
bool m_bNewData;
bool m_bMemoryRecall;
};
#endif