/**
* Main container function in creating the bot's reply.
*
* This function is the 'manager' of all the sub-funtions that do the real processing. It creates a class
* called Response that is used throughout the application.
*
* @uses addinputs()
* @uses addthats()
* @uses bget()
* @uses cleanup()
* @uses getthat()
* @uses loadcustomtags()
* @uses logconversation()
* @uses normalsentences()
* @uses respond()
* @uses ss_timing_current()
* @uses ss_timing_start()
* @uses ss_timing_stop()
*
* @global string that                   The conversation's previous bot output
* @global string topic                  The contents of the AIML tag 'Topic'
* @global integer uid                   The session ID of the user (previously $uniqueid)
* @global integer loopcounter           Counts the number of time a particular category is used in the same match trace.
* @global array patternmatched          The pattern's that matched the
*
* @param string $userinput              The user's input.
* @param integer $uniqueid              The user's session ID.
* @param integer $bot                   The bot's ID.
*
* @return object                        A class link to 'Response'.
*/
function reply($userinput, $uniqueid, $bot)
{
    if (strstr($userinput, "There is no such a bot loaded")) {
        $myresponse->response = $userinput;
    } else {
        global $that, $topic, $uid, $loopcounter, $patternmatched, $inputmatched, $selectbot;
        cleanup();
        ss_timing_start("all");
        $patternmatched = array();
        $inputmatched = array();
        $myresponse = new Response();
        $myresponse->errors = "";
        $uid = $uniqueid;
        $selectbot = $bot;
        // Load the custom plugin tags
        loadcustomtags();
        // Get the "that" and the "topic"
        $that = getthat(1, 1);
        $topic = bget("TOPIC");
        // Normalize the input
        $allinputs = normalsentences($userinput);
        // If nothing said then use INACTIVITY special input
        if (sizeof($allinputs) == 0) {
            $allinputs[] = "INACTIVITY";
        }
        // Put all the inputs into the <input> stack.
        addinputs($allinputs);
        $finalanswer = "";
        // Build our response to all of the inputs.
        for ($x = 0; $x < sizeof($allinputs); $x++) {
            $finalanswer .= respond($allinputs[$x]);
        }
        if ($loopcounter > LOOPINGLIMIT && LOOPINGLIMIT != -1) {
            $finalanswer = LOOPINGERRORMSG;
            $myresponse->errors = "LOOPINGLIMIT";
        }
        // Put the final answers into the <that> stack.
        addthats(normalsentences($finalanswer));
        // Log the conversation
        logconversation($userinput, $finalanswer);
        $myresponse->response = $finalanswer;
        $myresponse->patternsmatched = $patternmatched;
        $myresponse->inputs = $inputmatched;
        ss_timing_stop("all");
        $myresponse->timer = ss_timing_current("all");
    }
    return $myresponse;
}
Example #2
0
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @package Loader
 */
/**
* The general preferences and database details.
*/
$ChatPath = "../";
$BotPath = "./";
include_once "{$ChatPath}config/config.lib.php";
require_once "{$BotPath}dbprefs.php";
/**
* Contains the actual functions used in this file to load the AIML files into MySQL.
*/
require_once "{$BotPath}botloaderfuncs.php";
print "<b><font size='3' color='black'>When this script is done running you should see \"<font color='red'>DONE LOADING</font>\".</b><br />\n\n<font color='green'><b>Note:</b> If the script times out it is probably because your PHP is running in safe mode. If this is the case use the file <a href=\"botloaderinc.php\">botloaderinc.php</a> to load your AIML files one by one.<br />\n\nAnother reason might be that your timeout php setting is set too low. In this case, you sould split the aiml files in smaller pieces (keep the AIML header and footer in all the splitted pieces).</font><br />\n\n<font color='red'><b>Important:</b> If you need to run/reload this file again, you must empty/truncate all the tables starting with \"bot_\" in your database, otherwise the bot will be broken.</font><br />\n<br />\n<b><font color='blue'>Process started! </font><font color='red'>Please wait...</font></b></font><br />\n";
ss_timing_start("all");
$fp = "";
$templatesinserted = 0;
$patternsinserted = 0;
$depth = array();
$whaton = "";
$pattern = "";
$topic = "";
$that = "";
$template = "";
$startupwhich = "";
$splitterarray = array();
$inputarray = array();
$genderarray = array();
$personarray = array();
$person2array = array();
Example #3
0
function ss_timing_start($name = 'default')
{
    global $ss_timing_start_times;
    $ss_timing_start_times[$name] = explode(' ', microtime());
}
function ss_timing_stop($name = 'default')
{
    global $ss_timing_stop_times;
    $ss_timing_stop_times[$name] = explode(' ', microtime());
}
function ss_timing_current($name = 'default')
{
    global $ss_timing_start_times, $ss_timing_stop_times;
    if (!isset($ss_timing_start_times[$name])) {
        return 0;
    }
    if (!isset($ss_timing_stop_times[$name])) {
        $stop_time = explode(' ', microtime());
    } else {
        $stop_time = $ss_timing_stop_times[$name];
    }
    // do the big numbers first so the small ones aren't lost
    $current = $stop_time[1] - $ss_timing_start_times[$name][1];
    $current += $stop_time[0] - $ss_timing_start_times[$name][0];
    return $current;
}
ss_timing_start();
phpinfo();
ss_timing_stop();
echo "<hr><br>\r\n      <div class=\"confirm\">The page was executed in : " . ss_timing_current() . " seconds.</div>";
include_once "http://localhost/a/plugins/themefooter.html";
Example #4
0
 * @version 0.0.8
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @package Interpreter
 * @subpackage Responder
 */
/**
* Include the guts of the program.
*/
include "respond.php";
// Read tests.txt into an array, each line a different element.
$tests = array("testatomic", "testdisplayset", "testhide", "testget", "testsetx", "testalter", "testsettopic", "test6a", "test6b", "testsimplecondition", "testsimpleconditiona", "testsimpleconditionmatch", "testconditionlist", "testconditionlistmatch", "testconditionlistdefault", "testconditionlistname", "teststar test passed", "teststar Test passed one and Test passed two and Test passed three and Test passed four", "testunderscore Test passed one and Test passed two and Test passed three and Test passed four", "testrandom", "testwordformat", "testnestedwordformat", "testsimplemultisentencethat", "testarray4multisentencethat", "testarray3multisentencethat", "testarray2multisentencethat", "testarray1multisentencethat", "testthatarray", "testbotproperties", "testconditionsetvalue", "testnestedcondition", "testnestedcondition1", "testnestedcondition2", "testsetcondition", "testversion", "testsrai", "testsr sraisucceeded", "testnestedsrai", "testthinksrai", "teststarset test passed", "testidsizedate", "testgossip", "testname", "testinput", "testinput1", "testinput2", "testinput3", "testgender he", "testthatstar", "testthatstar1", "testmultithatstar", "testmultithatstar1", "testtopicstar", "testmultitopicstar", "test35", "testoldtopic", "test36", "testextremesrai", "testperson i was", "testperson2 with you");
ss_timing_start("alll");
// For each element in the array to a curl request to talk.php.
for ($x = 0; $x < sizeof($tests); $x++) {
    // Start the session or get the existing session.
    session_start();
    $myuniqueid = session_id();
    // Timer will let us know how long it took to get our response.
    ss_timing_start("single");
    // Here is where we get the reply.
    $botresponse = reply($tests[$x], $myuniqueid, 1);
    // Stop the timer.
    ss_timing_stop("single");
    // Print the results.
    print "<B>RESPONSE: " . $botresponse->response . "<BR></b>";
    print "<BR><BR>execution time: " . ss_timing_current("single");
    print "<BR>";
}
ss_timing_stop("alll");
print "<BR><BR>all execution time: " . ss_timing_current("alll");
print "<BR>";