Skip to content

Commit 687a13d

Browse files
committed
Code Cleanup, & Refactor
The code to fix issue #364 in the last push was a little incomplete, as well as ugly. That's now fixed.
1 parent bb277e3 commit 687a13d

2 files changed

Lines changed: 5 additions & 26 deletions

File tree

chatbot/core/aiml/parse_aiml.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,25 +293,22 @@ function set_wildcards($convoArr, $type)
293293
$convoArr['aiml']['topic_stars'] = array();
294294
}
295295
// Set pattern wildcards
296-
//$aiml_pattern = ($type == 'normal') ? trim($convoArr['aiml']['pattern']) : trim($convoArr['aiml']['srai_input']);
297296
$aiml_pattern = trim($convoArr['aiml']['pattern']);
298297
runDebug(__FILE__, __FUNCTION__, __LINE__, "Setting Wildcards. Pattern = '$aiml_pattern'", 2);
298+
/* debugging code
299299
$aimlArr = $convoArr['aiml'];
300300
ksort($aimlArr,SORT_NATURAL | SORT_FLAG_CASE);
301301
runDebug(__FILE__, __FUNCTION__, __LINE__, "Current AIML array =" . print_r($aimlArr, true), 2);
302-
//save_file(_LOG_PATH_ . 'convoArr.txt', print_r($convoArr, true));
302+
*/
303303
$ap = str_replace(array("*", "_"), "(.+)", $aiml_pattern);
304-
runDebug(__FILE__, __FUNCTION__, __LINE__, "comparing patterns $ap and $aiml_pattern", 2);
305304
if ($ap != $aiml_pattern)
306305
{
307306
runDebug(__FILE__, __FUNCTION__, __LINE__, "We have pattern stars to process!", 2);
308307
if (!isset ($convoArr['aiml']['user_raw'])) $convoArr['aiml']['user_raw'] = normalize_text($convoArr['aiml']['lookingfor'], false);
309-
$checkAgainst = ($type == 'normal') ? $convoArr['aiml']['user_raw'] : $convoArr['aiml']['srai_input'];
310-
runDebug(__FILE__, __FUNCTION__, __LINE__, "Checking pattern '$ap' against '$checkAgainst'.", 2);
308+
$checkAgainst = ($type == 'normal') ? $convoArr['aiml']['user_raw'] : $convoArr['aiml']['lookingfor'];
311309
if (preg_match_all("~{$ap}$~siuU", $checkAgainst, $matches))
312310
{
313311
runDebug(__FILE__, __FUNCTION__, __LINE__, print_r($matches, true), 2);
314-
//save_file(_LOG_PATH_ . 'pattern_star.matches.txt', print_r($matches, true));
315312
for ($i = 1; $i < count($matches); $i++)
316313
{
317314
$curStar = trim($matches[$i][0]);

chatbot/core/aiml/parse_aiml_as_XML.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -725,32 +725,14 @@ function parse_formal_tag($convoArr, $element, $parentName, $level)
725725
function parse_srai_tag(&$convoArr, $element, $parentName, $level)
726726
{
727727
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Parsing an SRAI tag.', 2);
728-
729728
$starArray = array('~<star[ ]?/>~i', '~<star index="\d+"[ ]?\/>~');
730729
$elementXML = $element->asXML();
731-
732-
//$srai = tag_to_string($convoArr, $element, $parentName, $level, 'element');
733730
$srai = tag_to_string($convoArr, $element, $parentName, $level, 'element');
734-
$convoArr['aiml']['srai_input'] = $srai;
735-
/*
736-
$srai_new = (strstr($elementXML, '<star') !== false) ?
737-
parse_star_tag($convoArr, $element, $parentName, $level) :
738-
//preg_replace($starArray, '*', $elementXML) :
739-
$srai;
740-
741-
$srai_new = preg_replace('~<[\/]?text>~i', '', $srai_new);
742-
$srai_new = preg_replace('~<[\/]?srai>~i', '', $srai_new);
743-
$convoArr['aiml']['srai_input'] = $srai_new;
744-
*/
745-
//file_put_contents(_LOG_PATH_ . "paax.parse_srai.srai_new.txt", print_r($srai_new, true) . "\n", FILE_APPEND);
746-
//file_put_contents(_LOG_PATH_ . "paax.parse_srai.srai.txt", print_r($srai, true) . "\n", FILE_APPEND);
731+
$convoArr['aiml']['lookingfor'] = $srai;
747732
$convoArr = set_wildcards($convoArr, 'srai');
748-
$response = run_srai($convoArr, $convoArr['aiml']['srai_input']);
749-
750-
//$response = run_srai($convoArr, $srai);
733+
$response = run_srai($convoArr, $convoArr['aiml']['lookingfor']);
751734
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Finished parsing SRAI tag', 4);
752735
$response_string = implode_recursive(' ', $response, __FILE__, __FUNCTION__, __LINE__);
753-
754736
return $response_string;
755737
}
756738

0 commit comments

Comments
 (0)