Hi guys,

I'm in the process of learning PHP. I know the dribs and drabs and can kind of understand code when I read it, but I'm not to the point of being able to write an advanced script from scratch. I've been interested in chatbots and the concept AI for a long time and would love to develop a PHP/MySQL chat bot as a learning project for myself. I'd really appreciate some input as to how/where I should start and what potential limitations will be based on what I want to do:

1. I want to develop a simple back-end for myself, where I can manually input phrases and responses into the database. The Personality Forge UI comes to mind - where you have a form, input the phrase, and add 1 or more potential responses for the bot to display.

2. A "mood" can also be set for each response (an integer value, the lower the more grumpy the bot, the higher the happier) and a mood value can also be placed on each phrase a bot hears. The bot's mood is recalculated with each phrase it hears and it is more likely to display certain responses depending on its mood value. I want the bot's mood to be calculated globally - so if three people are talking to it at the same time, all three impact its global mood *to an extent*. However, it still recognizes all three people as different entities and can feel happier about talking to one IP address and grumpier with another.

3. I want people to be able to teach the bot. For example, teach it words. If the bot doesn't recognize something it might say "What is 'courageous'?". The user may say "Courageous is an adjective. It means brave", and the bot will store it as an adjective that's a synonym of brave. The bot would "screen" the word courageous in other conversations (for example, when someone else comes along to talk to it, it might say "Is corageous an adjective?" User gives a positive response. Then the bot may say "And it means brave, right?" User gives a positive response. If it's a negative response, the bot may ask it what courageous means to adjust its definition and continue the process.

4. I'd like to be able to manually create libraries (as well as automatically - for example the word "Courageous", once learned, would go into the Adjective library). Say create a library of postive adjectives and negative adjectives. Then in response phrases or when feeding input phrases into the bot's library I can say "This city is [postivie adjective here]". I'd also like to be able to use wildcards. Say insert "What does * taste like" and have the bot output a response no matter what the * is. This means that I'd also need to set an importance value for different input phrases. For example, if someone says "What do *green apples* taste like" - do I want the bot to deliver a response for the word apple or apples or green, or do I want it to deliver responses for the phrase with the wildcard? It will depend on the phrase and word, so I need to be able to define this on a phrase-by-phrase basis.

5. In terms of UI, I'd love to make it look like a live chat, but I don't mind doing page refreshes after each phrase if there's an issue with the former.

Is this at all possible with PHP and MySQL or am I getting in too deep here? I don't mind spending time on this - I just need to know that it's actually a realistic goal.

Creating a chat bot is a pretty challenging project. It might be a very long and frustrating project for someone who doesn't already have pretty good PHP and MySQL knowledge and preferably some knowledge / experience with artificial intelligence. It is possible in PHP and MySQL and the good news is that it has already been done! There are some open source systems out there that you can download and try. They may not do everything that you want, but it will give you a start with something that already works. You can learn by examining what was already done and when you're ready for it, try making some changes and additions. Once you examine one of these systems, you might decide that you're not ready to tackle something that large / complex but you'll already have something that works anyway.

Have a look at my previous post where I provided a couple of references. You can probably find more with a search.
http://www.daniweb.com/forums/thread269327.html

I know it's a old thread but I think I could help other that may search for the same thing.

I always had interest in this kind of projet since a few years now.

here my advice:

First: do not try to teach the bot adjective or verb, since there's no use for this the bot will never understand this concep in language, use this only if you want to make a bot teach people language.

Second: Bot always use ramdom response, trying to teach the bot an entire language make no sense because there's too much exception and the bot will make error and it will be pretty slow to know all the word. and people that will talk with him have chance to make mistake when they write and the bot may not understand the sentence.

I have a bot that I made in C# using Acces database with table, I have 2 table one with a field that contain sentence that may match the user input and another field that contain
response fkid of the other table the field content look like this "23,12,45,67,23", some may say that it's not the correct technic to proceed with making the table and I know that, I made it that way because I can retreive the field with a .split method and parse it faster. I could use another table only for this but the sql statement would be more complex and slow to deal with.

the first table contain sentence match, when the user type a new sentence that may not appear in this field then I add it. if it's exist then I get the response of the other field and I .split it in C# and I do a random of all fkid in the array, then the bot respond this way. to add more response in the field I made a command, the bot always remember the last sentence and if the user type : reponse: ok I'm here the bot will add this response to the other table and I retreive the last PK and add it to my response field.

I have also another table that deal with badword so before searching for a sentence I clean it first, so a work like : [cos => because] will be replace to be more accurate. this table work not only with word but small sentence 2-3 word so I make sure the sentence is clear, I also replace all special char like ".,,,?,!" etc double space etc.

I also had a function that determin the subjet of the sentence, this is important because the bot will always follow the conversation topic.

I have a lot more thing that I did but I think that point you to the right direction.

I made this bot for online technical support that help user for a particuliar topic.

the next step is , I want the bot surf the net to get information and knowelge.

it's a big work, the important thing is to invent new method, remember that computer will be
always have limit and there's no intelligence at all, the only thing that could be possible is emulate intelligence, complex program could archive this.

I hope it help you, sorry english is not my first language.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.