Chatbot: Many Issues

Well. After a 2-3 year break from programming (Done a bit, but no C or C++ unfortunaly), I finally wanted to start a little project.

I fell across this 'tutorial' on making a 'rather' advanced chatbot.
http://www.codeproject.com/KB/recipes/bot_tutorial.aspx

To make this relatively short, I'm using Dev-C++ as the compiler.
I don't have any trouble compiling the chatterbot 2, but when it comes to chatterbot 3, I have multiple errors and warnings.

Chatbot 2:
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
//
// Program Name: chatterbot2
// Description: this is an improved version of the previous chatterbot program "chatterbot1"
// this one will try a littlebit more to understand what the user is trying to say
//
// Author: Gonzales Cenelia
//

#pragma warning(disable: 4786)

#include <iostream>
#include <string>
#include <vector>
#include <ctime>

const int MAX_RESP = 3;

typedef std::vector<std::string> vstring;

vstring find_match(std::string input);
void copy(char *array[], vstring &v);


typedef struct {
	char *input;
	char *responses[MAX_RESP];
}record;

record KnowledgeBase[] = {
	{"WHAT IS YOUR NAME", 
	{"MY NAME IS CHATTERBOT2.",
	 "YOU CAN CALL ME CHATTERBOT2.",
	 "WHY DO YOU WANT TO KNOW MY NAME?"}
	},

	{"HI", 
	{"HI THERE!",
	 "HOW ARE YOU?",
	 "HI!"}
	},
	
	{"HOW ARE YOU",
	{"I'M DOING FINE!",
	"I'M DOING WELL AND YOU?",
	"WHY DO YOU WANT TO KNOW HOW AM I DOING?"}
	},

	{"WHO ARE YOU",
	{"I'M AN A.I PROGRAM.",
	 "I THINK THAT YOU KNOW WHO I'M.",
	 "WHY ARE YOU ASKING?"}
	},

	{"ARE YOU INTELLIGENT",
	{"YES,OFCORSE.",
	 "WHAT DO YOU THINK?",
	 "ACTUALY,I'M VERY INTELLIGENT!"}
	},

	{"ARE YOU REAL",
	{"DOES THAT QUESTION REALLY MATERS TO YOU?",
	 "WHAT DO YOU MEAN BY THAT?",
	 "I'M AS REAL AS I CAN BE."}
	}
};

size_t nKnowledgeBaseSize = sizeof(KnowledgeBase)/sizeof(KnowledgeBase[0]);


int main() {
	srand((unsigned) time(NULL));

	std::string sInput = "";
	std::string sResponse = "";

	while(1) {
		std::cout << ">";
		std::getline(std::cin, sInput);
		vstring responses = find_match(sInput);
		if(sInput == "BYE") {
			std::cout << "IT WAS NICE TALKING TO YOU USER, SEE YOU NEXTTIME!" << std::endl;  
			break;
		} 
		else if(responses.size() == 0)  {
			std::cout << "I'M NOT SURE IF I  UNDERSTAND WHAT YOU  ARE TALKING ABOUT." << std::endl;
		}
		else {
			int nSelection = rand()  % MAX_RESP;
			sResponse =   responses[nSelection]; std::cout << sResponse << std::endl; 
		} 
	} 

	return 0;
}
	
// make a  search for the  user's input 
// inside the database of the program 
vstring find_match(std::string  input) { 
	vstring result;
	for(int i = 0; i < nKnowledgeBaseSize;  ++i) {  
		if(std::string(KnowledgeBase[i].input) == input) { 
			copy(KnowledgeBase[i].responses, result); 
			return result;
		} 
	} 
	return result; 
}

void copy(char  *array[], vstring &v) { 
	for(int i = 0;  i < MAX_RESP; ++i) {
		v.push_back(array[i]);
	}
}


Chatbot 3:
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
//
// Program Name: chatterbot3
// Description: this is an improved version of the previous chatterbot program "chatterbot1"
// this one will try a littlebit more to understand what the user is trying to say and will also
// try to avoid repeating himself too much. 
//
// Author: Gonzales Cenelia
//

#pragma warning(disable: 4786)

#include <iostream>
#include <string>
#include <vector>
#include <ctime>

const int MAX_RESP = 3;
const std::string delim = "?!.;,";

typedef std::vector vstring;

vstring find_match(std::string input);
void copy(char *array[], vstring &v);
void preprocess_input(std::string &str);
void UpperCase( std::string &str );
void cleanString(std::string &str);
bool isPunc(char c);

typedef struct {
	char *input;
	char *responses[MAX_RESP];
}record;

record KnowledgeBase[] = {
	{"WHAT IS YOUR NAME", 
	{"MY NAME IS CHATTERBOT2.",
	 "YOU CAN CALL ME CHATTERBOT2.",
	 "WHY DO YOU WANT TO KNOW MY NAME?"}
	},

	{"HI", 
	{"HI THERE!",
	 "HOW ARE YOU?",
	 "HI!"}
	},
	
	{"HOW ARE YOU",
	{"I'M DOING FINE!",
	"I'M DOING WELL AND YOU?",
	"WHY DO YOU WANT TO KNOW HOW AM I DOING?"}
	},

	{"WHO ARE YOU",
	{"I'M AN A.I PROGRAM.",
	 "I THINK THAT YOU KNOW WHO I'M.",
	 "WHY ARE YOU ASKING?"}
	},

	{"ARE YOU INTELLIGENT",
	{"YES,OFCORSE.",
	 "WHAT DO YOU THINK?",
	 "ACTUALY,I'M VERY INTELLIENT!"}
	},

	{"ARE YOU REAL",
	{"DOES THAT QUESTION REALLY MATERS TO YOU?",
	 "WHAT DO YOU MEAN BY THAT?",
	 "I'M AS REAL AS I CAN BE."}
	}
};

size_t nKnowledgeBaseSize = sizeof(KnowledgeBase)/sizeof(KnowledgeBase[0]);


int main()
{
	srand((unsigned) time(NULL));

	std::string sInput = "";
	std::string sResponse = "";
	std::string sPreviousResponse = "";

	while(1) {
		std::cout << ">";
		sPreviousResponse = sResponse;
		std::getline(std::cin, sInput);
		preprocess_input(sInput);
		vstring responses = find_match(sInput);
		if(sInput == "BYE") {
			std::cout << "IT WAS NICE TALKING TO YOU USER, SEE YOU NEXT TIME!" << std::endl;
			break;
		} else if(responses.size() == 0) {
			std::cout << "I'M NOT SURE IF I UNDERSTAND WHAT YOU ARE TALKING ABOUT." << std::endl;
		} else {
			int nSelection = rand() % MAX_RESP;
			sResponse = responses[nSelection];
			// avoids repeating the same response
			if(sResponse == sPreviousResponse) {
				responses.erase(responses.begin() + nSelection);
				nSelection = rand() % responses.size();
				sResponse = responses[nSelection];
			}
			std::cout << sResponse << std::endl;
		}
	}

	return 0;
}

void preprocess_input(std::string &str) {
	cleanString(str);
	UpperCase(str);
}

// make a search for the user's input
// inside the database of the program
vstring find_match(std::string input) {
	vstring result;
	for(int i = 0; i < nKnowledgeBaseSize; ++i) {
		if(std::string(KnowledgeBase[i].input) == input) {
			copy(KnowledgeBase[i].responses, result);
			return result;
		}
	}
	return result;
}

void copy(char *array[], vstring &v) {
	for(int i = 0; i < MAX_RESP; ++i) {
		v.push_back(array[i]);
	}
}

void UpperCase( std::string &str ) {
	int len = str.length();
	for( int i = 0; i < len; i++ ) {
		if ( str[i] >= 'a' && str[i] <= 'z' ) {
			str[i] -= 'a' - 'A';
		}
	}
}

bool isPunc(char c) {
	return delim.find(c) != std::string::npos;
}

// removes punctuation and redundant
// spaces from the user's input
void cleanString( std::string &str ) {
	int len = str.length();
	std::string temp = "";

	char prevChar = 0;

	for(int i = 0; i < len; ++i) {
		if( (str[i] == ' ' && prevChar != ' ') || !isPunc(str[i]) ) {
			temp += str[i];
			prevChar = str[i];
		}	
		else if(prevChar != ' ' && isPunc(str[i])) {
			temp += ' ';
		}
	}
	str = temp;
}


Here is the compilation log:
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
Compiler: Default compiler
Building Makefile: "C:\Users\Mathias\Desktop\Nanna\Makefile.win"
Executing  make...
make.exe -f "C:\Users\Mathias\Desktop\Nanna\Makefile.win" all
g++.exe -c nanna.cpp -o nanna.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"   

nanna.cpp:20: error: expected init-declarator before "vstring"

nanna.cpp:20: error: expected `,' or `;' before "vstring"
nanna.cpp:22: error: `vstring' does not name a type

nanna.cpp:23: error: `vstring' has not been declared
nanna.cpp:23: error: ISO C++ forbids declaration of `v' with no type
nanna.cpp: In function `int main()':
nanna.cpp:88: error: `vstring' undeclared (first use this function)
nanna.cpp:88: error: (Each undeclared identifier is reported only once for each function it appears in.)
nanna.cpp:88: error: expected `;' before "responses"

nanna.cpp:92: error: `responses' undeclared (first use this function)

nanna.cpp: At global scope:
nanna.cpp:117: error: `vstring' does not name a type

nanna.cpp:128: error: `vstring' has not been declared
nanna.cpp:128: error: ISO C++ forbids declaration of `v' with no type
nanna.cpp: In function `void copy(char**, int&)':
nanna.cpp:130: error: `push_back' has not been declared
nanna.cpp:130: error: request for member of non-aggregate type before '(' token

make.exe: *** [nanna.o] Error 1

Execution terminated


Non of the V(string) commands/parametres seems to be recognized.

Any help appreciated, as well as articles on the various methods (string for example) ;)

I'll see if I can work it out in the mean time.
20
21
//typedef std::vector vstring;
typedef std::vector<std::string> vstring;
Topic archived. No new replies allowed.