Skip to content

Commit 2dfcd92

Browse files
committed
Bug Fix
Found and corrected a bug that prevented certain AIML tags (notably, the <star> tag) from being parsed at times. Special thanks to Xtciann for helping me to isolate and correct this bug.
1 parent 25f3560 commit 2dfcd92

File tree

3 files changed

+11
-24
lines changed

3 files changed

+11
-24
lines changed

chatbot/core/aiml/find_aiml.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,18 @@ function unset_all_bad_pattern_matches($allrows, $lookingfor, $current_thatpatte
143143
}
144144
else
145145
{
146-
$that_match = "$aiml_thatpattern == ''";
146+
$that_match = ($aiml_thatpattern == '');
147147
$tmp_rows[$i]['track_score'] .= "c";
148148
}
149149
if ($aiml_topic != '')
150150
{
151-
$topic_match = "$aiml_topic == $current_topic";
151+
$topic_match = ($aiml_topic == $current_topic);
152152
$tmp_rows[$i]['track_score'] .= "d";
153153
}
154154
else
155155
{
156-
$topic_match = "$aiml_topic == ''";
157-
$tmp_rows[$i]['track_score'] .= "e";
156+
$topic_match = ($aiml_topic == '');
157+
$tmp_rows[$i]['track_score'] .= "xe";
158158
}
159159
//try to match the returned aiml pattern with the user input (lookingfor) and with the that's and topic's
160160
preg_match($aiml_pattern_matchme, $lookingfor, $matches);
@@ -177,25 +177,11 @@ function unset_all_bad_pattern_matches($allrows, $lookingfor, $current_thatpatte
177177
}
178178
else
179179
{
180+
if (!isset($tmp_rows[$i]['pattern'])) unset($tmp_rows[$i]);
180181
continue;
181-
/*
182-
$tmp_rows[$i] = array(
183-
'aiml_id' => -1,
184-
'bot_id' => -1,
185-
'pattern' => '',
186-
'thatpattern' => '',
187-
'topic' => '',
188-
'score' => 0,
189-
'track_score' => ''
190-
);
191-
*/
192182
}
193-
//echo "<br/>--------------";
194183
}
195184
}
196-
// echo "<pre>";
197-
// print_r($tmp_rows);
198-
// echo "</pre>";
199185
runDebug(__FILE__, __FUNCTION__, __LINE__, "Found '$i' relevant rows", 2);
200186
runDebug(__FILE__, __FUNCTION__, __LINE__, print_r($tmp_rows,true), 4);
201187
return $tmp_rows;
@@ -775,10 +761,7 @@ function find_aiml_matches($convoArr)
775761
else
776762
{
777763
$thatPattern = '';
778-
//$lastThatPattern = '';
779-
//$firstThatPattern = '';
780764
$thatPatternSQL = '';
781-
//$storedthatpattern ='';
782765
}
783766
//get the word count
784767
$word_count = wordsCount_inSentence($lookingfor);
@@ -833,6 +816,8 @@ function find_aiml_matches($convoArr)
833816
$allrows[$i]['pattern'] = $row['pattern'];
834817
$allrows[$i]['thatpattern'] = $row['thatpattern'];
835818
$allrows[$i]['topic'] = $row['topic'];
819+
$allrows[$i]['score'] = 0;
820+
$allrows[$i]['track_score'] = '';
836821
$i++;
837822
$mu = memory_get_usage(true);
838823
if ($mu >= MEM_TRIGGER)

chatbot/core/aiml/parse_aiml_as_XML.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,10 @@ function tag_to_string($convoArr, $element, $parentName, $level, $type = 'elemen
774774
$children = $element->children();
775775
if (!empty ($children))
776776
{
777-
$response = parseTemplateRecursive($convoArr, $children, $level + 1);
777+
foreach ($children as $child)
778+
{
779+
$response[] = parseTemplateRecursive($convoArr, $child, $level + 1);
780+
}
778781
}
779782
else
780783
{

chatbot/core/user/handle_user.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ function load_new_client_defaults($convoArr)
2424
runDebug( __FILE__, __FUNCTION__, __LINE__, 'Loading client defaults', 2);
2525
$convoArr['client_properties']['name'] = $unknown_user;
2626
$convoArr['client_properties']['id'] = session_id();
27-
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Conversation element = ' . print_r($convoArr['conversation'], true), 4);
2827
return $convoArr;
2928
}
3029

0 commit comments

Comments
 (0)