/** * function get_aiml_to_parse() * This function controls all the process to match the aiml in the db to the user input * @param array $convoArr - conversation array * @return array $convoArr **/ function get_aiml_to_parse($convoArr) { runDebug(__FILE__, __FUNCTION__, __LINE__, "Running all functions to get the correct aiml from the DB", 4); $lookingfor = $convoArr['aiml']['lookingfor']; $current_thatpattern = isset($convoArr['that'][1][1]) ? $convoArr['that'][1][1] : ''; $current_topic = get_topic($convoArr); $aiml_pattern = $convoArr['conversation']['default_aiml_pattern']; $bot_parent_id = $convoArr['conversation']['bot_parent_id']; $raw_that = isset($convoArr['that']) ? print_r($convoArr['that'], true) : ''; //check if match in user defined aiml $allrows = find_userdefined_aiml($convoArr); //if there is no match in the user defined aiml table if (!isset($allrows) || count($allrows) <= 0) { //look for a match in the normal aiml tbl $allrows = find_aiml_matches($convoArr); //unset all irrelvant matches $allrows = unset_all_bad_pattern_matches($convoArr, $allrows, $lookingfor); //score the relevant matches $allrows = score_matches($convoArr, $allrows, $lookingfor); //get the highest $allrows = get_highest_scoring_row($convoArr, $allrows, $lookingfor); //READY FOR v2.5 do not uncomment will not work //check if this is an unknown input and place in the unknown_inputs table if true //check_and_add_unknown_inputs($allrows,$convoArr); } //Now we have the results put into the conversation array $convoArr['aiml']['pattern'] = $allrows['pattern']; $convoArr['aiml']['thatpattern'] = $allrows['thatpattern']; $convoArr['aiml']['template'] = $allrows['template']; $convoArr['aiml']['html_template'] = ''; $convoArr['aiml']['topic'] = $allrows['topic']; $convoArr['aiml']['score'] = $allrows['score']; $convoArr['aiml']['aiml_id'] = $allrows['aiml_id']; //return runDebug(__FILE__, __FUNCTION__, __LINE__, "Will be parsing id:" . $allrows['aiml_id'] . " (" . $allrows['pattern'] . ")", 4); return $convoArr; }
/** * function get_aiml_to_parse() * This function controls all the process to match the aiml in the db to the user input * @param array $convoArr - conversation array * @return array $convoArr **/ function get_aiml_to_parse($convoArr) { global $offset; runDebug(__FILE__, __FUNCTION__, __LINE__, "Running all functions to get the correct aiml from the DB", 4); $lookingfor = get_convo_var($convoArr, "aiml", "lookingfor"); $current_thatpattern = get_convo_var($convoArr, 'that', '', 1, 1); $current_topic = get_convo_var($convoArr, 'topic'); $default_aiml_pattern = get_convo_var($convoArr, 'conversation', 'default_aiml_pattern'); $bot_parent_id = get_convo_var($convoArr, 'conversation', 'bot_parent_id'); $sendConvoArr = $convoArr; //check if match in user defined aiml $allrows = find_userdefined_aiml($convoArr); //if there is no match in the user defined aiml tbl if (!isset($allrows) || count($allrows) <= 0) { //look for a match in the normal aiml tbl $allrows = find_aiml_matches($convoArr); //unset all irrelvant matches $allrows = unset_all_bad_pattern_matches($allrows, $lookingfor, $current_thatpattern, $current_topic, $default_aiml_pattern); //score the relevant matches $allrows = score_matches($bot_parent_id, $allrows, $lookingfor, $current_thatpattern, $current_topic, $default_aiml_pattern); //get the highest $allrows = get_highest_score_rows($allrows, $lookingfor); } //Now we have the results put into the conversation array $convoArr['aiml']['pattern'] = $allrows['pattern']; $convoArr['aiml']['thatpattern'] = $allrows['thatpattern']; $convoArr['aiml']['template'] = $allrows['template']; $convoArr['aiml']['html_template'] = htmlentities($allrows['template']); $convoArr['aiml']['topic'] = $allrows['topic']; $convoArr['aiml']['score'] = $allrows['score']; $convoArr['aiml']['aiml_to_php'] = $allrows['aiml_to_php']; $convoArr['aiml']['aiml_id'] = $allrows['aiml_id']; //return runDebug(__FILE__, __FUNCTION__, __LINE__, "Will be parsing id:" . $allrows['aiml_id'] . " (" . $allrows['pattern'] . ")", 4); return $convoArr; }