当前位置: 首页>>代码示例>>PHP>>正文


PHP runDebug函数代码示例

本文整理汇总了PHP中runDebug函数的典型用法代码示例。如果您正苦于以下问题:PHP runDebug函数的具体用法?PHP runDebug怎么用?PHP runDebug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了runDebug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: captialise

/**
 * function captialise()
 * this function captialises a string
 * @param string $text
 * @return string text
**/
function captialise($text)
{
    $otext = $text;
    $text = strtoupper($text);
    runDebug(__FILE__, __FUNCTION__, __LINE__, "In: {$otext} Out:{$text}", 4);
    return $text;
}
开发者ID:massyao,项目名称:chatbot,代码行数:13,代码来源:user_input_clean.php

示例2: normalize_text

/**
 * function normalize_text
 * Transforms text to uppercase, removes all punctuation, and strips extra whitespace
 *
 * @param (string) $text - The text to perform the transformations on
 * @return mixed|string (string) $normalized_text - The completely transformed text
 */
function normalize_text($text)
{
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Begin normalization - text = '{$text}'", 4);
    $normalized_text = preg_replace('/[[:punct:]]/uis', ' ', $text);
    $normalized_text = preg_replace('/\\s\\s+/', ' ', $normalized_text);
    $normalized_text = IS_MB_ENABLED ? mb_strtoupper($normalized_text) : strtoupper($normalized_text);
    $normalized_text = trim($normalized_text);
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Normalization complete. Text = '{$normalized_text}'", 4);
    return $normalized_text;
}
开发者ID:aaoliveira,项目名称:Program-O,代码行数:17,代码来源:misc_functions.php

示例3: make_conversation

/**
 * function make_conversation()
 * A controller function to run the instructions to make the conversation
 *
 * @link http://blog.program-o.com/?p=1209
 * @param  array $convoArr - the current state of the conversation array
 * @return array $convoArr (updated)
 */
function make_conversation($convoArr)
{
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Making conversation", 4);
    //get the user input and clean it
    $convoArr['aiml']['lookingfor'] = normalize_text($convoArr['user_say'][1]);
    //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;
}
开发者ID:aaoliveira,项目名称:Program-O,代码行数:24,代码来源:make_conversation.php

示例4: normalize_text

/**
 * function normalize_text
 * Transforms text to uppercase, removes all punctuation, and strips extra whitespace
 *
 * @param (string) $text - The text to perform the transformations on
 * @return mixed|string (string) $normalized_text - The completely transformed text
 */
function normalize_text($text)
{
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Begin normalization - text = '{$text}'", 4);
    $normalized_text = preg_replace('/(\\d+) - (\\d+)/', '$1 MINUS $2', $text);
    $normalized_text = preg_replace('/(\\d+)-(\\d+)/', '$1 MINUS $2', $normalized_text);
    $normalized_text = preg_replace('/(\\d+) \\+ (\\d+)/', '$1 PLUS $2', $normalized_text);
    $normalized_text = preg_replace('/(\\d+)\\+(\\d+)/', '$1 PLUS $2', $normalized_text);
    $normalized_text = preg_replace('/(\\d+) \\* (\\d+)/', '$1 TIMES $2', $normalized_text);
    $normalized_text = preg_replace('/(\\d+) x (\\d+)/', '$1 TIMES $2', $normalized_text);
    $normalized_text = preg_replace('/(\\d+)x(\\d+)/', '$1 TIMES $2', $normalized_text);
    $normalized_text = preg_replace('/(\\d+)\\*(\\d+)/', '$1 TIMES $2', $normalized_text);
    $normalized_text = preg_replace('/(\\d+) \\/ (\\d+)/', '$1 DIVIDEDBY $2', $normalized_text);
    $normalized_text = preg_replace('/(\\d+)\\/(\\d+)/', '$1 DIVIDEDBY $2', $normalized_text);
    $normalized_text = preg_replace('/[[:punct:]]/uis', ' ', $normalized_text);
    $normalized_text = preg_replace('/\\s\\s+/', ' ', $normalized_text);
    $normalized_text = IS_MB_ENABLED ? mb_strtoupper($normalized_text) : strtoupper($normalized_text);
    $normalized_text = trim($normalized_text);
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Normalization complete. Text = '{$normalized_text}'", 4);
    return $normalized_text;
}
开发者ID:lordmatt,项目名称:Program-O,代码行数:27,代码来源:misc_functions.php

示例5: spellcheck

function spellcheck($user_say)
{
    global $dbconn;
    $wordArr = make_wordArray($user_say);
    $limit_res = count($wordArr);
    $sqlwords = glue_words_for_sql($wordArr);
    $sql = "SELECT * FROM `{$dbn}`.`spellcheck` WHERE `missspelling` IN ({$sqlwords}) LIMIT {$limit_res}";
    $result = db_query($sql, $dbconn);
    if ($result) {
        if (db_res_count($result) > 0) {
            while ($row = db_res_array($result)) {
                $pattern = '/\\b' . $row['missspelling'] . '\\b/';
                $replacement = $row['correction'];
                if ($user_say = preg_replace($pattern, $replacement, $user_say)) {
                    runDebug(__FILE__, __FUNCTION__, __LINE__, "Replacing " . $row['missspelling'] . " with " . $row['correction'], 4);
                }
            }
        }
    }
}
开发者ID:massyao,项目名称:chatbot,代码行数:20,代码来源:user_spellcheck.php

示例6: intisaliseUser

/**
 * function intisaliseUser()
 * This function gets data such as the referer to store in the db
 * @param string $convo_id - user session
 * @return int $user_id - the newly created user id
**/
function intisaliseUser($convo_id)
{
    //db globals
    global $con, $dbn, $default_bot_id;
    $sr = "";
    $sa = "";
    $sb = "unknown browser";
    if (isset($_SERVER['REMOTE_ADDR'])) {
        $sa = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
    }
    if (isset($_SERVER['HTTP_REFERER'])) {
        $sr = mysql_real_escape_string($_SERVER['HTTP_REFERER']);
    }
    if (isset($_SERVER['HTTP_USER_AGENT'])) {
        $sb = mysql_real_escape_string($_SERVER['HTTP_USER_AGENT']);
    }
    $sql = "INSERT INTO `{$dbn}`.`users` (`id` ,`session_id`, `bot_id`, `chatlines` ,`ip` ,`referer` ,`browser` ,`date_logged_on` ,`last_update`)\n\tVALUES ( NULL , '{$convo_id}', {$default_bot_id}, '0', '{$sa}', '{$sr}', '{$sb}', CURRENT_TIMESTAMP , '0000-00-00 00:00:00')";
    mysql_query($sql, $con);
    $user_id = mysql_insert_id($con);
    runDebug(__FILE__, __FUNCTION__, __LINE__, "intisaliseUser #{$user_id} SQL: {$sql}", 3);
    return $user_id;
}
开发者ID:massyao,项目名称:chatbot,代码行数:28,代码来源:handle_user.php

示例7: foreignchar_replace

/**
 * function foreignchar_replace()
 * A function to replace foreign characters with a string substitute 
 * So that nothing is broken during parsing/interpreting
 * @param  string $whichway - 'decode' or 'encode'
 * @param  sring $text - the text to decode or encode
 * @return the en/decoded string
**/
function foreignchar_replace($whichway, $text)
{
    runDebug(__FILE__, __FUNCTION__, __LINE__, "{$whichway}", 4);
    $foreign_char_array = array('Š' => 'htmlentity_foreign_big_S_caron', 'š' => 'htmlentity_foreign_small_s_caron', 'À' => 'htmlentity_foreign_big_A_grave', 'Á' => 'htmlentity_foreign_small_a_acute', 'Â' => 'htmlentity_foreign_big_A_circ', 'Ã' => 'htmlentity_foreign_big_A_tilde', 'Ä' => 'htmlentity_foreign_big__A_uml', 'Å' => 'htmlentity_foreign_big_A_ring', 'Æ' => 'htmlentity_foreign_big_AE_lig', 'Ç' => 'htmlentity_foreign_big__C_cedil', 'È' => 'htmlentity_foreign_big_E_grave', 'É' => 'htmlentity_foreign_big_E_acute', 'Ê' => 'htmlentity_foreign_big_E_circ', 'Ë' => 'htmlentity_foreign_big_E_uml', 'Ì' => 'htmlentity_foreign_big_I_grave', 'Í' => 'htmlentity_foreign_big_I_acute', 'Î' => 'htmlentity_foreign_big_I_circ', 'Ï' => 'htmlentity_foreign_big_I_uml', 'Ñ' => 'htmlentity_foreign_big_N_tilde', 'Ò' => 'htmlentity_foreign_big_O_grave', 'Ó' => 'htmlentity_foreign_big_O_acuter', 'Ô' => 'htmlentity_foreign_big_O_circ', 'Õ' => 'htmlentity_foreign_big_O_tilde', 'Ö' => 'htmlentity_foreign_big_O_uml', 'Ø' => 'htmlentity_foreign_big_O_slash', 'Ù' => 'htmlentity_foreign_big_U_grave', 'Ú' => 'htmlentity_foreign_big_U_acute', 'Û' => 'htmlentity_foreign_big_U_circ', 'Ü' => 'htmlentity_foreign_big_U_uml', 'Ý' => 'htmlentity_foreign_big_Y_acute', 'Þ' => 'htmlentity_foreign_big_THORN', 'ß' => 'htmlentity_foreign_small_sz_lig', 'à' => 'htmlentity_foreign_small_a_grave', 'á' => 'htmlentity_foreign_small_a_acute', 'â' => 'htmlentity_foreign_small_a_circ', 'ã' => 'htmlentity_foreign_small_a_tilde', 'ä' => 'htmlentity_foreign_small_a_uml', 'å' => 'htmlentity_foreign_small_a_ring', 'æ' => 'htmlentity_foreign_small_ae_lig', 'ç' => 'htmlentity_foreign_small_c_cedil', 'è' => 'htmlentity_foreign_small_e_grave', 'é' => 'htmlentity_foreign_small_e_acute', 'ê' => 'htmlentity_foreign_small_e_circ', 'ë' => 'htmlentity_foreign_small_e_uml', 'ì' => 'htmlentity_foreign_small_i_grave', 'í' => 'htmlentity_foreign_small_i_acute', 'î' => 'htmlentity_foreign_small_i_circ', 'ï' => 'htmlentity_foreign_small_i_uml', 'ð' => 'htmlentity_foreign_small_e_th', 'ñ' => 'htmlentity_foreign_small_n_tilde', 'ò' => 'htmlentity_foreign_small_o_grave', 'ó' => 'htmlentity_foreign_small_o_acute', 'ô' => 'htmlentity_foreign_small_o_circ', 'õ' => 'htmlentity_foreign_small_o_tilde', 'ö' => 'htmlentity_foreign_small_o_uml', 'ø' => 'htmlentity_foreign_small_o_slash', 'ù' => 'htmlentity_foreign_small_u_grave', 'ú' => 'htmlentity_foreign_small_u_acute', 'û' => 'htmlentity_foreign_small_u_circ', 'ý' => 'htmlentity_foreign_small_y_acute', 'þ' => 'htmlentity_foreign_small_thorn', 'Α' => 'htmlentity_greek_capital_letter_alpha', 'Β' => 'htmlentity_greek_capital_letter_beta', 'Γ' => 'htmlentity_greek_capital_letter_gamma', 'Δ' => 'htmlentity_greek_capital_letter_delta', 'Ε' => 'htmlentity_greek_capital_letter_epsilon', 'Ζ' => 'htmlentity_greek_capital_letter_zeta', 'Η' => 'htmlentity_greek_capital_letter_eta', 'Θ' => 'htmlentity_greek_capital_letter_theta', 'Ι' => 'htmlentity_greek_capital_letter_iota', 'Κ' => 'htmlentity_greek_capital_letter_kappa', 'Λ' => 'htmlentity_greek_capital_letter_lambda', 'Μ' => 'htmlentity_greek_capital_letter_mu', 'Ν' => 'htmlentity_greek_capital_letter_nu', 'Ξ' => 'htmlentity_greek_capital_letter_xi', 'Ο' => 'htmlentity_greek_capital_letter_omicron', 'Π' => 'htmlentity_greek_capital_letter_pi', 'Ρ' => 'htmlentity_greek_capital_letter_rho', 'Σ' => 'htmlentity_greek_capital_letter_sigma', 'Τ' => 'htmlentity_greek_capital_letter_tau', 'Υ' => 'htmlentity_greek_capital_letter_upsilon', 'Φ' => 'htmlentity_greek_capital_letter_phi', 'Χ' => 'htmlentity_greek_capital_letter_chi', 'Ψ' => 'htmlentity_greek_capital_letter_psi', 'Ω' => 'htmlentity_greek_capital_letter_omega', 'α' => 'htmlentity_greek_small_letter_alpha', 'β' => 'htmlentity_greek_small_letter_beta', 'γ' => 'htmlentity_greek_small_letter_gamma', 'δ' => 'htmlentity_greek_small_letter_delta', 'ε' => 'htmlentity_greek_small_letter_epsilon', 'ζ' => 'htmlentity_greek_small_letter_zeta', 'η' => 'htmlentity_greek_small_letter_eta', 'θ' => 'htmlentity_greek_small_letter_theta', 'ι' => 'htmlentity_greek_small_letter_iota', 'κ' => 'htmlentity_greek_small_letter_kappa', 'λ' => 'htmlentity_greek_small_letter_lambda', 'μ' => 'htmlentity_greek_small_letter_mu', 'ν' => 'htmlentity_greek_small_letter_nu', 'ξ' => 'htmlentity_greek_small_letter_xi', 'ο' => 'htmlentity_greek_small_letter_omicron', 'π' => 'htmlentity_greek_small_letter_pi', 'ρ' => 'htmlentity_greek_small_letter_rho', 'ς' => 'htmlentity_greek_small_letter_final_sigma', 'σ' => 'htmlentity_greek_small_letter_sigma', 'τ' => 'htmlentity_greek_small_letter_tau', 'υ' => 'htmlentity_greek_small_letter_upsilon', 'φ' => 'htmlentity_greek_small_letter_phi', 'χ' => 'htmlentity_greek_small_letter_chi', 'ψ' => 'htmlentity_greek_small_letter_psi', 'ω' => 'htmlentity_greek_small_letter_omega', 'ϑ' => 'htmlentity_greek_small_letter_theta_symbol', 'ϒ' => 'htmlentity_greek_upsilon_with_hook_symbol', 'ϖ' => 'htmlentity_greek_pi_symbol', 'À' => 'htmlentity_capital_A_grave_accent', 'Á' => 'htmlentity_capital_A_acute_accent', 'Â' => 'htmlentity_capital_A_circumflex_accent', 'Ã' => 'htmlentity_capital_A_tilde', 'Ä' => 'htmlentity_capital_A_dieresis_or_umlaut_mark', 'Å' => 'htmlentity_capital_A_ring', 'Æ' => 'htmlentity_capital_AE_diphthong_ligature', 'Ç' => 'htmlentity_capital_C_cedilla', 'È' => 'htmlentity_capital_E_grave_accent', 'É' => 'htmlentity_capital_E_acute_accent', 'Ê' => 'htmlentity_capital_E_circumflex_accent', 'Ë' => 'htmlentity_capital_E_dieresis_or_umlaut_mark', 'Ì' => 'htmlentity_capital_I_grave_accent', 'Í' => 'htmlentity_capital_I_acute_accent', 'Î' => 'htmlentity_capital_I_circumflex_accent', 'Ï' => 'htmlentity_capital_I_dieresis_or_umlaut_mark', 'Ð' => 'htmlentity_capital_Eth_Icelandic', 'Ñ' => 'htmlentity_capital_N_tilde', 'Ò' => 'htmlentity_capital_O_grave_accent', 'Ó' => 'htmlentity_capital_O_acute_accent', 'Ô' => 'htmlentity_capital_O_circumflex_accent', 'Õ' => 'htmlentity_capital_O_tilde', 'Ö' => 'htmlentity_capital_O_dieresis_or_umlaut_mark', 'Ø' => 'htmlentity_capital_O_slash', 'Ù' => 'htmlentity_capital_U_grave_accent', 'Ú' => 'htmlentity_capital_U_acute_accent', 'Û' => 'htmlentity_capital_U_circumflex_accent', 'Ü' => 'htmlentity_capital_U_dieresis_or_umlaut_mark', 'Ý' => 'htmlentity_capital_Y_acute_accent', 'Þ' => 'htmlentity_capital_THORN_Icelandic', 'ß' => 'htmlentity_small_sharp_s_German_sz_ligature', 'à' => 'htmlentity_small_a_grave_accent', 'á' => 'htmlentity_small_a_acute_accent', 'â' => 'htmlentity_small_a_circumflex_accent', 'ã' => 'htmlentity_small_a_tilde', 'ä' => 'htmlentity_small_a_dieresis_or_umlaut_mark', 'å' => 'htmlentity_small_a_ring', 'æ' => 'htmlentity_small_ae_diphthong_ligature', 'ç' => 'htmlentity_small_c_cedilla', 'è' => 'htmlentity_small_e_grave_accent', 'é' => 'htmlentity_small_e_acute_accent', 'ê' => 'htmlentity_small_e_circumflex_accent', 'ë' => 'htmlentity_small_e_dieresis_or_umlaut_mark', 'ì' => 'htmlentity_small_i_grave_accent', 'í' => 'htmlentity_small_i_acute_accent', 'î' => 'htmlentity_small_i_circumflex_accent', 'ï' => 'htmlentity_small_i_dieresis_or_umlaut_mark', 'ð' => 'htmlentity_small_eth_Icelandic', 'ñ' => 'htmlentity_small_n_tilde', 'ò' => 'htmlentity_small_o_grave_accent', 'ó' => 'htmlentity_small_o_acute_accent', 'ô' => 'htmlentity_small_o_circumflex_accent', 'õ' => 'htmlentity_small_o_tilde', 'ö' => 'htmlentity_small_o_dieresis_or_umlaut_mark', 'ø' => 'htmlentity_small_o_slash', 'ù' => 'htmlentity_small_u_grave_accent', 'ú' => 'htmlentity_small_u_acute_accent', 'û' => 'htmlentity_small_u_circumflex_accent', 'ü' => 'htmlentity_small_u_dieresis_or_umlaut_mark', 'ý' => 'htmlentity_small_y_acute_accent', 'þ' => 'htmlentity_small_thorn_Icelandic', 'ƒ' => 'htmlentity_latin_small_f_with_hook', 'Œ' => 'htmlentity_latin_capital_ligature_oe', 'œ' => 'htmlentity_latin_small_ligature_oe', 'Š' => 'htmlentity_latin_capital_letter_s_with_caron', 'š' => 'htmlentity_latin_small_letter_s_with_caron', 'Ÿ' => 'htmlentity_latin_capital_letter_y_with_diaeresis');
    //number of replacements to check
    $total_replacements = count($foreign_char_array) - 1;
    //get the keys from the array
    $keys = array_keys($foreign_char_array);
    //get the values from the array
    $values = array_values($foreign_char_array);
    //do the replacement
    for ($i = 0; $i <= $total_replacements; $i++) {
        $k = $keys[$i];
        $v = $values[$i];
        $t = htmlentities($text, ENT_QUOTES);
        if ($whichway == "encode") {
            $t = str_replace($k, $v, $t);
        } else {
            $t = str_replace($v, $k, $t);
        }
        $text = html_entity_decode($t, ENT_QUOTES);
    }
    return $text;
}
开发者ID:massyao,项目名称:chatbot,代码行数:32,代码来源:replace_tomakesafe.php

示例8: clean_condition

/**
 * function clean_condition()
 * This function cleans an item to be used in conditional checks
 * @param  string $condition - item to be cleaned
 * @return string $condition - item after clean
**/
function clean_condition($condition)
{
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Cleaning condition - {$condition} ", 4);
    return trim($condition);
}
开发者ID:massyao,项目名称:chatbot,代码行数:11,代码来源:buildingphp_code_functions.php

示例9: check_set_format

/**
 * function check_set_format(()
 * A function to check and set the conversation return type
 * @param  array $convoArr - the current state of the conversation array
 * @return $convoArr (updated)
**/
function check_set_format($convoArr)
{
    global $default_format;
    $formatsArr = array('html', 'xml', 'json');
    //at thsi point we can overwrite the conversation format.
    if (isset($_REQUEST['format']) && trim($_REQUEST['format']) != "") {
        $format = trim($_REQUEST['format']);
    } else {
        $format = $default_format;
    }
    $convoArr['conversation']['format'] = strtolower($format);
    if (!in_array($convoArr['conversation']['format'], $formatsArr)) {
        $convoArr['debug']['intialisation_error'] = "Incompatible return type: {$format}";
        runDebug(__FILE__, __FUNCTION__, __LINE__, "ERROR - bad return type: {$format}", 1);
    } else {
        runDebug(__FILE__, __FUNCTION__, __LINE__, "Using format: {$format}", 2);
    }
    return $convoArr;
}
开发者ID:massyao,项目名称:chatbot,代码行数:25,代码来源:intialise_conversation.php

示例10: parseInput

/**
 * Function parseInput
 *
 * * @param $msg
 * @return mixed
 */
function parseInput($msg)
{
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Pre-parsing input. Setting Timestamp. msg = |{$msg}|", 4);
    $smilieArray = file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'inputEmotes.dat');
    rsort($smilieArray);
    $out = str_replace($smilieArray, 'emoteshown', $msg);
    // Edit the input to deal with multiple punctuation marks
    $emSearch = '/^\\!+/';
    // Exclamation mark search string
    $out = preg_replace($emSearch, 'emonly', $out);
    //
    $qmSearch = '/^\\?+/';
    // Question mark search string
    $out = preg_replace($qmSearch, 'qmonly', $out);
    //
    $periodSearch = '/^\\.+/';
    // Period search string
    $out = preg_replace($periodSearch, 'periodonly', $out);
    //
    runDebug(__FILE__, __FUNCTION__, __LINE__, "msg now = |{$out}|", 4);
    return $out;
    // Send back the processed image
}
开发者ID:aaoliveira,项目名称:Program-O,代码行数:29,代码来源:parseBBCode.php

示例11: find_aiml_matches

/**
 * function find_aiml_matches()
 * This function builds the sql to use to get a match from the tbl
 * @param array $convoArr - conversation array
 * @return array $convoArr
 **/
function find_aiml_matches($convoArr)
{
    global $dbConn, $dbn, $error_response, $use_parent_bot;
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Finding the aiml matches from the DB", 4);
    $i = 0;
    //TODO convert to get_it
    $bot_id = $convoArr['conversation']['bot_id'];
    $bot_parent_id = $convoArr['conversation']['bot_parent_id'];
    $default_aiml_pattern = $convoArr['conversation']['default_aiml_pattern'];
    #$lookingfor = get_convo_var($convoArr,"aiml","lookingfor");
    $convoArr['aiml']['lookingfor'] = str_replace('  ', ' ', $convoArr['aiml']['lookingfor']);
    $lookingfor = trim(strtoupper($convoArr['aiml']['lookingfor']));
    //get the first and last words of the cleaned user input
    $lastInputWord = get_last_word($lookingfor);
    $firstInputWord = get_first_word($lookingfor);
    //get the stored topic
    $storedtopic = get_topic($convoArr);
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Stored topic = '{$storedtopic}'", 4);
    //get the cleaned user input
    $lastthat = isset($convoArr['that'][1][1]) ? $convoArr['that'][1][1] : '';
    //build like patterns
    if ($lastthat != '') {
        $thatPatternSQL = " OR " . make_like_pattern($lastthat, 'thatpattern');
        $thatPatternSQL = rtrim($thatPatternSQL, ' OR');
    } else {
        $thatPattern = '';
        $thatPatternSQL = '';
    }
    //get the word count
    $word_count = wordsCount_inSentence($lookingfor);
    if ($bot_parent_id != 0 and $bot_parent_id != $bot_id) {
        $sql_bot_select = " (bot_id = '{$bot_id}' OR bot_id = '{$bot_parent_id}') ";
    } else {
        $sql_bot_select = " bot_id = '{$bot_id}' ";
    }
    if (!empty($storedtopic)) {
        $topic_select = "AND (`topic`='' OR `topic`='{$storedtopic}')";
    } else {
        $topic_select = '';
    }
    if ($word_count == 1) {
        //if there is one word do this
        $sql = "SELECT `id`, `pattern`, `thatpattern`, `topic` FROM `{$dbn}`.`aiml` WHERE\n  {$sql_bot_select} AND (\n  `pattern` = '_' OR\n  `pattern` = '*' OR\n  `pattern` = '{$lookingfor}' OR\n  `pattern` = '{$default_aiml_pattern}'\n  {$thatPatternSQL}\n  ) {$topic_select} order by `topic` desc, `pattern` asc, `thatpattern` asc,`id` asc;";
    } else {
        //otherwise do this
        $sql_add = make_like_pattern($lookingfor, 'pattern');
        $sql = "SELECT `id`, `bot_id`, `pattern`, `thatpattern`, `topic` FROM `{$dbn}`.`aiml` WHERE\n  {$sql_bot_select} AND (\n  `pattern` = '_' OR\n  `pattern` = '*' OR\n  `pattern` = '{$lookingfor}' OR {$sql_add} OR\n  `pattern` = '{$default_aiml_pattern}'\n  {$thatPatternSQL}\n  ) {$topic_select}\n  order by `topic` desc, `pattern` asc, `thatpattern` asc,`id` asc;";
    }
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Core Match AIML sql: {$sql}", 3);
    $result = db_fetchAll($sql, null, __FILE__, __FUNCTION__, __LINE__);
    $num_rows = count($result);
    if ($result && $num_rows > 0) {
        $tmp_rows = number_format($num_rows);
        runDebug(__FILE__, __FUNCTION__, __LINE__, "FOUND: ({$num_rows}) potential AIML matches", 2);
        $tmp_content = date('H:i:s') . ": SQL:\n{$sql}\nRows = {$tmp_rows}\n\n";
        //loop through results
        foreach ($result as $row) {
            $row['aiml_id'] = $row['id'];
            $row['bot_id'] = $bot_id;
            $row['score'] = 0;
            $row['track_score'] = '';
            $allrows[] = $row;
            $mu = memory_get_usage(true);
            if ($mu >= MEM_TRIGGER) {
                runDebug(__FILE__, __FUNCTION__, __LINE__, 'Current operation exceeds memory threshold. Aborting data retrieval.', 0);
                break;
            }
        }
    } else {
        runDebug(__FILE__, __FUNCTION__, __LINE__, "Error: FOUND NO AIML matches in DB", 1);
        $allrows[$i]['aiml_id'] = "-1";
        $allrows[$i]['bot_id'] = $bot_id;
        $allrows[$i]['pattern'] = "no results";
        $allrows[$i]['thatpattern'] = '';
        $allrows[$i]['topic'] = '';
    }
    return $allrows;
}
开发者ID:ramdesh,项目名称:Program-O,代码行数:84,代码来源:find_aiml.php

示例12: db_write

function db_write($sql, $params = null, $multi = false, $file = 'unknown', $function = 'unknown', $line = 'unknown')
{
    global $dbConn;
    try {
        $sth = $dbConn->prepare($sql);
        switch (true) {
            case $params === null:
                $sth->execute();
                break;
            case $multi === true:
                foreach ($params as $row) {
                    $sth->execute($row);
                }
                break;
            default:
                $sth->execute($params);
        }
        return $sth->rowCount();
    } catch (Exception $e) {
        $pdoError = print_r($dbConn->errorInfo(), true);
        $psError = print_r($sth->errorInfo(), true);
        error_log("bad SQL encountered in file {$file}, line #{$line}. SQL:\n{$sql}\nPDO Error:\n{$pdoError}\nSTH Error:\n{$psError}\nException Message:\n" . $e->getMessage() . "\n", 3, _LOG_PATH_ . 'db_write.txt');
        runDebug(__FILE__, __FUNCTION__, __LINE__, "An error was generated while writing to the database in file {$file} at line {$line}, in the function {$function} - SQL:\n{$sql}\nPDO error: {$pdoError}\nPDOStatement error: {$psError}", 0);
        return false;
    }
}
开发者ID:EricLeeS,项目名称:Program-O,代码行数:26,代码来源:PDO_functions.php

示例13: load_that

/**
 * function load_that(()
 * A function to load the previous bot responses into the convoArr['that'] array
 *
 * @link http://blog.program-o.com/?p=1283
 * @param  array $convoArr - the current state of the conversation array
 * @return array $convoArr (updated)
 */
function load_that($convoArr)
{
    runDebug(__FILE__, __FUNCTION__, __LINE__, 'Loading the THAT array.', 2);
    global $dbConn, $dbn, $remember_up_to, $bot_id;
    $remember_up_to = !empty($convoArr['conversation']['remember_up_to']) ? $convoArr['conversation']['remember_up_to'] : $remember_up_to;
    $user_id = $convoArr['conversation']['user_id'];
    $bot_id = !empty($convoArr['conversation']['bot_id']) ? $convoArr['conversation']['bot_id'] : $bot_id;
    $limit = $remember_up_to;
    $sql = "select `input`, `response` from `{$dbn}`.`conversation_log` where `user_id` = {$user_id} and `bot_id` = {$bot_id} order by `id` desc limit {$limit};";
    // desc
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Getting conversation log entries for the current user. SQL:\n{$sql}", 3);
    $result = db_fetchAll($sql, null, __FILE__, __FUNCTION__, __LINE__);
    if ($result) {
        $tmpThatRows = array();
        $tmpInputRows = array();
        $tmpThat = array();
        $tmpInput = array();
        $puncuation = array(',', '?', ';', '!');
        foreach ($result as $row) {
            $tmpThatRows[] = $row['response'];
            $tmpInputRows[] = $row['input'];
        }
        runDebug(__FILE__, __FUNCTION__, __LINE__, 'Inputs returned:' . print_r($tmpInputRows, true), 1);
        runDebug(__FILE__, __FUNCTION__, __LINE__, 'Loading previous responses into the ~THAT~ array.', 4);
        runDebug(__FILE__, __FUNCTION__, __LINE__, 'Responses returned:' . print_r($tmpThatRows, true), 1);
        $tmpThatRows = array_reverse($tmpThatRows);
        foreach ($tmpThatRows as $row) {
            $row = str_replace($puncuation, '.', $row);
            $tmpThat[] = explode('.', $row);
        }
        array_unshift($tmpThat, NULL);
        unset($tmpThat[0]);
        foreach ($tmpThat as $index => $value) {
            $value = implode_recursive(' ', $value, __FILE__, __FUNCTION__, __LINE__);
            $value = clean_that($value, __FILE__, __FUNCTION__, __LINE__);
            $convoArr = push_on_front_convoArr('that', $value, $convoArr);
        }
        runDebug(__FILE__, __FUNCTION__, __LINE__, 'Loading previous user inputs into the ~INPUT~ array.', 4);
        $tmpInputRows = array_reverse($tmpInputRows);
        foreach ($tmpInputRows as $row) {
            $row = str_replace($puncuation, '.', $row);
            $tmpInput[] = explode('.', $row);
        }
        array_unshift($tmpThat, NULL);
        unset($tmpThat[0]);
        foreach ($tmpInput as $index => $value) {
            $value = implode_recursive(' ', $value, __FILE__, __FUNCTION__, __LINE__);
            $value = clean_that($value, __FILE__, __FUNCTION__, __LINE__);
            $convoArr = push_on_front_convoArr('input', $value, $convoArr);
        }
    } else {
        runDebug(__FILE__, __FUNCTION__, __LINE__, 'Couldn\'t find any previous inputs or responses.', 4);
    }
    return $convoArr;
}
开发者ID:ramdesh,项目名称:Program-O,代码行数:63,代码来源:intialise_conversation.php

示例14: math_functions

/**
 * function math_functions()
 * This function runs the system math operations
 *
 * @param string       $operator - maths operator
 * @param int        $num_1    - the first number
 * @param int|string $num_2    - the second number
 * @internal param int $output - the result of the math operation
 *
 * @return float|int|number|string
 */
function math_functions($operator, $num_1, $num_2 = "")
{
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Running system tag math {$num_1} {$operator} {$num_2}", 4);
    $operator = IS_MB_ENABLED ? mb_strtolower($operator) : strtolower($operator);
    switch ($operator) {
        case "add":
            $output = $num_1 + $num_2;
            break;
        case "subtract":
            $output = $num_1 - $num_2;
            break;
        case "multiply":
            $output = $num_1 * $num_2;
            break;
        case "divide":
            if ($num_2 == 0) {
                $output = "You can't divide by 0!";
            } else {
                $output = $num_1 / $num_2;
            }
            break;
        case "sqrt":
            $output = sqrt($num_1);
            break;
        case "power":
            $output = pow($num_1, $num_2);
            break;
        default:
            $output = $operator . "?";
    }
    return $output;
}
开发者ID:aaoliveira,项目名称:Program-O,代码行数:43,代码来源:parse_aiml.php

示例15: tag_to_string

/**
 * Converts the contents of the AIML tag to a string.
 *
 * @param array            $convoArr
 * @param SimpleXMLElement $element
 * @param string           $parentName
 * @param int              $level
 * @param string           $type
 * @return string
 */
function tag_to_string(&$convoArr, $element, $parentName, $level, $type = 'element')
{
    runDebug(__FILE__, __FUNCTION__, __LINE__, "converting the {$parentName} tag into text.", 2);
    $response = array();
    $children = $element->children();
    if (!empty($children)) {
        foreach ($children as $child) {
            $response[] = parseTemplateRecursive($convoArr, $child, $level + 1);
        }
    } else {
        switch ($type) {
            case 'element':
                $response[] = (string) $element;
                break;
            default:
                $response[] = $convoArr['star'][1];
        }
    }
    $response_string = implode_recursive(' ', $response, __FILE__, __FUNCTION__, __LINE__);
    // do something here
    return $response_string;
}
开发者ID:aaoliveira,项目名称:Program-O,代码行数:32,代码来源:parse_aiml_as_XML.php


注:本文中的runDebug函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。