Exemplo n.º 1
0
/**
 * function make_conversation()
 * A controller function to run the instructions to make the conversation
 * @param  array $convoArr - the current state of the conversation array
 * @return $convoArr (updated)
**/
function make_conversation($convoArr)
{
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Making conversation", 4);
    global $offset;
    //get the user input and clean it
    //$convoArr = clean_for_aiml_match('user_say','lookingfor',$convoArr);
    $convoArr['aiml']['lookingfor'] = clean_for_aiml_match($convoArr['user_say'][$offset]);
    //find an aiml match in the db
    $convoArr = get_aiml_to_parse($convoArr);
    $convoArr = parse_matched_aiml($convoArr, 'normal');
    //parse the aiml to build a response
    //store the conversation
    $convoArr = push_on_front_convoArr('parsed_template', $convoArr['aiml']['parsed_template'], $convoArr);
    $convoArr = push_on_front_convoArr('template', $convoArr['aiml']['template'], $convoArr);
    //display conversation vars to user.
    $convoArr['conversation']['totallines']++;
    return $convoArr;
}
Exemplo n.º 2
0
/**
 * function make_learn()
 * This function builds the sql insert a learnt aiml cateogry in to the db
 * @param array $convoArr - conversation array
 * @param string $pattern - the pattern we will insert
 * @param string $template - the template to insert
**/
function make_learn($convoArr, $pattern, $template)
{
    global $con, $dbn;
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Making learn", 2);
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Pattern:  {$pattern}", 2);
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Template: {$template}", 2);
    $pattern = clean_for_aiml_match($pattern);
    $aiml = "<learn> <category> <pattern> <eval>{$pattern}</eval> </pattern> <template> <eval>{$template}</eval> </template> </category> </learn>";
    $aiml = mysql_real_escape_string($aiml);
    $pattern = mysql_real_escape_string($pattern . " ");
    $template = mysql_real_escape_string($template . " ");
    $u_id = $convoArr['conversation']['user_id'];
    $bot_id = $convoArr['conversation']['bot_id'];
    $sql = "INSERT INTO `{$dbn}`.`aiml_userdefined` \n\t\t\t\tVALUES\n\t\t\t\t(NULL, '{$aiml}','{$pattern}','{$template}','{$u_id}','{$bot_id}',NOW())";
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Make learn SQL: {$sql}", 3);
    $res = mysql_query($sql, $con);
}