Documentation is available at retrieve.inc.php
- <?php
- /*
- Program E related AIML knowledgebase tools
- Copyright 2004, Anne Kootstra [anne@aiml.info]
- http://www.AIML.info
- Program E is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- Program E is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Program E; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- /**
- * Given a specific template ID retrieve the corresponding PATTERN,
- * THAT and TOPIC.
- *
- * Retrieve the Pattern, That and Topic using only the ID of the corresponding template.
- * This function has also been adapted to make it possible to substitute the template ID
- * for a parent ID and retrieve the pattern-words that came before that ID. To do this set
- * $pat to 1.
- *
- * @uses findmainnode()
- * @uses findParent()
- * @uses findPatternPart()
- *
- * @param integer $botid The bot's ID.
- * @param integer $templateID The category's ID.
- * @param boolean $pat To use a parent ID from the pattern table instead of template ID
- *
- * @returns array [pattern],[that],[topic].
- */
- function findCategoryPattern($botid, $templateID, $pat=0) {
- /**
- * @var array contains the final pattern
- */
- $final_pattern;
- // retrieve the pattern ID of the main node
- $mainNode= findmainnode($botid);
- if($pat==0) {
- // retrieve the corresponding parentID i.e. next word's patternID.
- $pattern_parent = findParent($templateID);
- }elseif($pat==1){
- $pattern_parent = $templateID;
- }
- // storage for this category's pattern, that and topic
- $final_pattern = array();
- $final_word_index = 0;
- // loop ends when the path from the leaf node (template reference)
- // to the main node (i.e. <input>) is completely walked.
- while($mainNode <= $pattern_parent) {
- // collect the current word, and next word's pattern ID
- $pattern_details = findPatternPart($pattern_parent);
- // save current word into a seperate array element
- $final_pattern[$final_word_index] = $pattern_details['word'];
- $final_word_index++;
- // set up for processing next word.
- $pattern_parent = $pattern_details['parent'];
- }
- // the tree is walked backwards, so the category's pattern
- // is also stored into the array backwards, This reverses is.
- $final_pattern_reverse = array_reverse($final_pattern);
- // process each individual word and put them into one of
- // [pattern], [that] or [topic] array elements.
- while (list($key, $val) = each($final_pattern_reverse)) {
- if($val == "<input>"){
- $cat_section = "pattern";
- }elseif($val == "<that>"){
- $cat_section = "that";
- }elseif($val == "<topic>") {
- $cat_section = "topic";
- }
- if(!($val=="<input>" || $val=="<that>" || $val=="<topic>")) {
- $final_category[$cat_section] .= $val." ";
- }
- }
- // return the completed three piece array.
- return $final_category;
- }
- /**
- * Get the word and the parent ID using the known pattern ID.
- *
- * Because the word tree is traveled backwards, from leaf-node (i.e. the
- * template reference) to the trunk (i.e. the <input> node), there needs to
- * be a reference to the previous word, this is the parent ID in the parent
- * column. Both the word (including the * and _) and the parent ID are returned.
- *
- * @param string $patternID The pattern word ID.
- *
- * @return array 'parent', 'id and 'word'.
- *
- */
- function findPatternPart($patternID){
- /*
- The ordera column in the pattern table is used to identify
- the order of the 'word' in the matching process. An underscore
- has the order value of 1, a word (atomic match) of 2 and the
- * has a value of 3. This fact is used to recreate those values.
- */
- $query = "select ifnull(if(word='<input>','AIML ROOT',word),if(ordera='1','_','*')) as word, parent, id from patterns where id = ".$patternID."";
- //debugger($query,2);
- $selectcode = mysql_query($query);
- if ($selectcode){
- if(!mysql_numrows($selectcode)){
- return "";
- }
- else{
- while ($q = mysql_fetch_array($selectcode)){
- $pattern['word'] = $q[0];
- $pattern['parent'] = $q[1];
- $pattern['id'] = $q[2];
- return $pattern;
- }
- }
- }
- return "";
- }
- ?>
Documentation generated on Tue, 11 Jan 2005 18:41:10 +0100 by phpDocumentor 1.3.0RC3