Click here to Skip to main content
15,886,806 members
Articles / Web Development / HTML

Chatbot Tutorial

Rate me:
Please Sign up or sign in to vote.
4.85/5 (88 votes)
24 Apr 2019CPOL27 min read 734.4K   217   178  
Tutorial on making an artificial intelligence chatbot
#ifndef __STRING_H__
#define __STRING_H__

#pragma warning(disable: 4786)
#pragma warning(disable: 4503)
#include <string>
#include <vector>

const int MAX_INP = 5;
const int MAX_RESP = 7;

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


bool isPunc( char c );
void cleanString( std::string &str );
void UpperCase( std::string &str );
void trimLeft(std::string &str, std::string delim);
void trimRight( std::string &str, std::string delim );
void trimLR(std::string &str, std::string characters);
void copy( char *array[], vstring &v, size_t array_size );
size_t replace( std::string &str, std::string substr1, std::string substr2 );
void tokenize(const std::string str, vstring &v);

template<typename T>
void shuffle( T &array, size_t size ) 
{
	for( int i = 0; i < size; ++i ) 
	{
		int index = rand() % size;
		std::swap(array[i], array[index]);
	}
}

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Help desk / Support Gexel Telecom
Canada Canada
I have been programming in C and C++ for more than four years, the first time that i had learn programming was in 1999 in college. However it was only by the year 2000 when i have buy my first computer that i had truly started to do some more interesting things in programming. As a programmer,my main interest is A.I programming. So i'm really captivated by all that is related to N.L.U (Natural Language Understanding), N.L.P (Natural Language Processing), Artificial Neural Networks etc. Currently i'm learning to program in Prolog and Lisp. Also,i'm really fascinated with the original chatterbot program named: Eliza,that program was wrote by Joseph Weizenbaum. Everytime i run this program,it makes me really think that A.I could be solve one day. A lot of interesting stuff has been accomplish in the domain of Artificial Intelligence in the past years. A very good example of those accomplishments is: Logic Programming,which makes it possible to manipulate logic statements and also to make some inferences about those statements. A classical example would be: given the fact that "Every man is mortal" and that Socrates is a man,than logically we can deduce that Socrates is mortal. Such simple logical statements can be wrote in Prolog by using just a few lines of code:

prolog code sample:

mortal(X):- man(X). % rule
man(socrates). % declaring a fact

the preceding prolog rule can be read: for every variable X,if X is a man than X is mortal. these last Prolog code sample can be easily extented by adding more facts or rules,example:
mortal(X):- man(X). % rule
mortal(X):- woman(X). % rule
man(socrates). % fact 1
man(adam). % fact 2
woman(eve). % fact 3

for more, check: https://cenelia7.wixsite.com/programming
ai-programming.blogspot.com

Comments and Discussions