imdead Posted August 17, 2011 Share Posted August 17, 2011 Hey guys, i've got a slight problem with a code i've been writing. Dont worry about the horrible mess it is atm, basically i've been trying to create a clone of the website CleverBot. This is how i believe it works 1. person asks a question. 2. Bot looks at database for the question and spits out the answer if found. 3. If the answer was not found, just respond "I don't know" or something similar. Store the question in the database. 4. Spit out one of the unanswered questions from the database. Record the answer for future person Make this basic system and add a few hundred "stock" questions and answers, a few features to increase humanishness (like store multiple possible answers for each question) and a few hard-coded answers to "stumpers" like "What time is it?" and swear words. 1. User A says "Where do you live?". 2. Cleverbot says "Huh?" 3. Cleverbot asks User B, later, "Where do you live?". 4. User B responds "I live in Devon." 5. Later, User C asks Cleverbot, "Where do you live?". 6. Cleverbot responds "I live in Devon.", echoing User B. 7. User C corrects Cleverbot with "They say I live in Devon." 8. Cleverbot stores that response in its database. 9. I could say "I live in Devon.", and Cleverbot spits out the correction. Without even knowing it's making a correction. As far as it knows it's just another question with a stored answer. and this is what i've wrote so far, <?php error_reporting(0); // Establish A Connection, And Select Database $conn = mysql_connect("******","****","********"); $db = mysql_select_db("****", $conn); if (empty($_POST['question'])) //// If the question hasn't been set yet { $question = $_POST['question'] = "<br /><font color='#0000FF'>Please ask me a question...</font>"; // set with dummy value echo $question; }else{ $question = $_POST['question']; $question = ucfirst(substr_replace($question, '?', 1000, 0)); /// Make the question have the first letter uppercased, add a question mark to the end of the sentance. $sql = mysql_query("SELECT * FROM qanda WHERE question='$question'"); if(mysql_num_rows($sql) <= 0){ //// If no reply is found, add dummy reply $answer = "I don't know."; if (!empty($answer)){ $f = mysql_query("INSERT INTO qanda (id, question) VALUES ('NULL', '$question')") or die (mysql_error()); /// $s = mysql_query("UPDATE qanda SET answer='$answer' WHERE (question='$question')") or die (mysql_error()); } } echo '<br /><font color="#800080">You:</font> '.$question; while($row = mysql_fetch_array($sql)) { $answer = $row["answer"]; $reply = $row["reply"]; } print '<br /><font color="#0000FF">iThink:</font> '.$answer; if (!empty($reply)){ print '<br /><font color="#0000FF">iThink:</font> '.$reply; } } /// if question is unkown, print 'i dont know', insert question as a reply to a question. ?> <br /> <center> <form name="question" action="index.php" method="post"> <input type="text" name="question" maxlength="2048" name="question2" size="41" title="Question" value="" /> <input type="submit" value="Question me!" /> </form> </center> Keep questions simple!<br /> Don't add a '?', it will be added automatically. I'm looking for a way to go about making the bot add a unknown question to the database, as a response to the question that was asked before, This is how the database works CREATE TABLE IF NOT EXISTS `qanda` ( `id` int(11) NOT NULL AUTO_INCREMENT, `question` longtext NOT NULL, `answer` longtext NOT NULL, `reply` mediumtext NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; -- -- Dumping data for table `qanda` -- INSERT INTO `qanda` (`id`, `question`, `answer`, `reply`) VALUES (1, 'What is the date?', 'The date today is botdate();', ''), (2, 'What is your name?', 'My name is Bot.', 'What about your name?'), (3, 'Who created you?', 'I was created by, Kevin Cornish. On 15/08/11 at 01:20 AM.', ''), (4, 'How are you?', 'I''m very well thankyou.', 'What about yourself?'), (5, 'Hey.', 'Hello.', ''), (6, 'Hello.', 'Hi.', ''), (7, 'Good, thankyou.', 'You''re welcome.', ''); Quote Link to comment https://forums.phpfreaks.com/topic/245063-cleverbot-clone-help/ Share on other sites More sharing options...
QuickOldCar Posted August 17, 2011 Share Posted August 17, 2011 There's a big problem with this, word associations and the order people write the questions, is just too many variations. On top of that words have multiple meanings and also different context. I worked on making an AI for a little bit, I realized it needs to break down each word, find word patterns and their meanings, and display a few possible answers and let the user decide which one was correct or the closest match. After making myself a mock-up system I then realized I needed to store vast amounts of data to accomplish anything worth using for the public. Possibly linking to dictionary,thesaurus,encyclopedia,atlas,universities,libraries and any other public data source it might be possible. I don't think cleverbot is all that clever. I've seen better. Anyway I think you'll have better luck with answers and responses by using broken up phrases or words from their questions, then combine them together by the most popular key words for a possible answer. I believe to make a truly clever bot it needs to interpret what the user is asking in order to provide a decent response. Quote Link to comment https://forums.phpfreaks.com/topic/245063-cleverbot-clone-help/#findComment-1258769 Share on other sites More sharing options...
plznty Posted August 17, 2011 Share Posted August 17, 2011 What the guy above me said is right, you need to look for words. Just the main key points and if it finds a match it will display results. Quote Link to comment https://forums.phpfreaks.com/topic/245063-cleverbot-clone-help/#findComment-1258789 Share on other sites More sharing options...
Alex Posted August 17, 2011 Share Posted August 17, 2011 It's nowhere near as simple as you make it sound. With no background in AI you're not going to be able to make a very good clone. Quote Link to comment https://forums.phpfreaks.com/topic/245063-cleverbot-clone-help/#findComment-1258793 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.