File/admin/botloaderfuncs.php

Description

AIML loading functions

Contains contains the functions for the actual loading of AIML.

Includes
 require_once ("dbprefs.php") (line 39)

The general preferences and database details.

Functions
addtosubs (line 155)

Write the substitution include file

Write the substitution arrays back into the subs.inc

  • global: object The $fp: opened subs.inc file, ready to write to.
  • usedby: makesubscode()
void addtosubs (string $string)
  • string $string: most likely an array or all arrays turned into a big file.
botexists (line 655)

Checks if a bot already exists.

Does a check to see if a bot with a particular name already exists. The reliance on unique names if crucial for the bot to work.

boolean botexists (string $name)
  • string $name: the name of the bot that is checked.
cleanforreplace (line 1389)

Add slashes for replacement purposes

Making a string safe to preform a replacement function on.

string cleanforreplace (string $input)
  • string $input: string to be cleaned.
cleanforsearch (line 1408)

Add slashes for database query purpose

Making a string safe to put the text in an SQL query.

string cleanforsearch (string $input)
  • string $input: string to be cleaned.
createsubfile (line 175)

Create the object for writing the substitution include file

Creates the object, which is then used by addtosubs() to write to

void createsubfile ()
deletebot (line 53)

Deletes everything about a bot.

Empties the tables, bot, patterns, templates, bots and gmcache

void deletebot (integer $bot)
  • integer $bot: The bot's ID
deletejustbot (line 93)

Deletes information about a bot in the cache and bot tables.

Used by the incremental bot loader program so it doesn't wipe out the whole bot on each aiml file load. Deletes everything in bot, bots and gmcache tables.

void deletejustbot (integer $bot)
  • integer $bot: The bot's ID.
endElement (line 827)

Used by the AIML XML parser

Looks for the end tags of 'topic' and 'category'.

  • global: string $whaton: which tag is being processed
  • global: string $pattern:
  • global: string $template:
  • global: integer $recursive: to indicate if recursion is allowed
  • global: string $topic: the topic at hand in the AIML file
  • global: string $that: the that of the category.
  • usedby: learn()
  • usedby: learnstring()
  • uses: insertmytemplate()
  • uses: insertmysentence()
void endElement (resource $parser, string $name)
  • resource $parser: SAX XML resource handler
  • string $name: name of the encountered tag.
endS (line 608)

Called by the XML parser that is parsing the startup.xml file.

  • global: string $whaton: Which start tag was processed last
  • usedby: loadstartup()
void endS (resource $parser, string $name)
  • resource $parser: SAX XML resource handler
  • string $name: name of the encountered tag.
findwordid (line 198)

Find a word in the patterns table given the word and the parent.

The AIML patterns are stored in the MySQL table in a binary tree format. This function retrieves the next word details based upon the previous' word's ID. If this word doesn't exist it returns 0, else it returns it's details.

integer findwordid (string $word, integer $parent)
  • string $word: The word that is to be searched
  • integer $parent: The ID of the parent word
findwordidstar (line 234)

Find a wildcard in the patterns table given the word and the parent.

Similar as findwordid() but this will retrieve the ID if there is a wildcard that fits.

integer findwordidstar (string $word, integer $parent)
  • string $word: The word that is to be searched, either _ or *
  • integer $parent: The ID of the parent word
flushcache (line 117)

Deletes the gmcache table.

This needs to be called whenever the patterns or templates table is updated.

void flushcache ()
getbotid (line 713)

Gets the ID of a bot given its name.

Gets the ID of a bot given its name

  • usedby: startS()
  • todo: move this function to a common include file shared by both the Loader and the Interpreter.
void getbotid (string $name)
  • string $name:

    The name of the bot

    @ return integer The bot's ID.

getbotvalue (line 683)

Gets a bot's property value.

Retrieves the value of a particular bot predicate. If the predicate isn't set, then it will return the value 'default'. This has been hardcoded

  • return: the value of the bot predicate.
  • global: integer $selectbot:
  • usedby: startElement()
string getbotvalue (string $name)
  • string $name: the name of the bot predicate to be retrieved.
handleme (line 900)

Part of the AIML XML parser.

Checks for start tags of pattern, topic, that, template and CDATA

  • global: string $whaton:
  • global: string $pattern:
  • global: string $template:
  • global: string $topic:
  • global: string $that:
  • usedby: learn()
  • usedby: learnstring()
void handleme (resource $parser, string $data)
  • resource $parser: SAX XML resource handler
  • string $data: containing what needs to be parsed, I guess.
handlemeS (line 632)

Process contents <learn> tag in startup.xml

Called by the XML parser that is parsing the startup.xml file. * -> all files in directory, or single file.

  • global: string $whaton:
  • global: array $learnfiles: contains the AIML files to learn.
  • global: integer $selectbot:
  • usedby: loadstartup()
  • uses: learnallfiles()
  • todo: When using * it should process AIML in subdirectories too. This is currently only supported by using multiple <learn> tag entries for every folder containing AIML files.
void handlemeS (resource $parser, string $data)
  • resource $parser: SAX XML resource handler
  • string $data: assuming it contains the path to the file.
insertmysentence (line 298)

Inserts the pattern into the patterns table.

inserts the pattern, that and topic as individual words in binary tree format into the patterns table

void insertmysentence (string $mybigsentence)
  • string $mybigsentence: Contains the pattern, that and topic in the following format <input>word word<that>word word<topic>word word.
insertmytemplate (line 444)

Inserts a template into the template table.

Insert the template into the template database.
This version has been adapted to also insert the pattern, that and topic into the additionally added columns

  • global: integer $selectbot:
  • global: integer $templatesinserted: The ID of the record in the patterns table that links to this table
  • global: string $pattern: The pattern, including variables like _ and *.
  • global: string $topic: the topic, including variable like _ and *
  • global: string $that: the that, including variables like _ and *
  • usedby: endElement()
  • uses: templateexists()
void insertmytemplate (integer $idused, string $template)
  • integer $idused: The ID of the record in the patterns table that links to the template table.
  • string $template: The contents inbetween <template/> tags.
insertwordpattern (line 413)

Inserts an entry into the patterns table. Returns the ID of the new row inserted.

insert a word into the patterns table, returns the id of the record so it can be used as the parent ID of the next word that's to be inserted.

integer insertwordpattern (string $qadd)
  • string $qadd: The word of the pattern to be inserted
learn (line 1135)

Learn an AIML file.

Learn a single AIML XML file. Again, the hardcoded time limit is set to 600, presumably seconds.

void learn (string $file)
  • string $file: The AIML file name.
learnallfiles (line 1073)

Learn all the files in a directory ending with ".aiml"

Read all the AIML filenames into the $learnfile Array. This array is then later on used by learn() in handlemeS()

  • global: string $rootdir: the rootdirectory
  • global: array $learnfiles: contains all the filenames that need to be loaded into the bot.
  • usedby: handlemeS()
void learnallfiles (integer $curbot)
  • integer $curbot: ID of the current bot.
learnstring (line 1103)

Learn the AIML string.

XML parse the AIML string. It seems to have a hardcoded time limit of 600, presume seconds.

void learnstring (string $xmlstring)
  • string $xmlstring: the AIML category XML string
loadaimlcategory (line 1326)

Load an AIML string that is just a category.

This is going to need to take bot as a parameter

void loadaimlcategory (string $aimlstring, integer $botid)
  • string $aimlstring: The AIML string to be loaded.
  • integer $botid: The bot's ID.
loadaimlstring (line 1298)

Load an AIML string. String must be valid XML.

This is going to need to take bot as a parameter

void loadaimlstring (string $aimlstring, integer $botid)
  • string $aimlstring: The AIML string to be loaded.
  • integer $botid: The bot's ID.
loadstartup (line 1020)

Parses startup.xml

Loads the startup.xml in the botloading process. XML parses the startup.xml file.

  • return: prints HTML
  • global: string $rootdir: the rootdirectory
  • global: array $learnfiles: Files to be learned
  • global: array $allbots: All the different bots in the startup.xml file
  • global: integer $selectbot: ID of the selected bot
  • global: boolean $areinc: ????
  • uses: endS()
  • uses: handlemeS()
  • uses: startS()
  • uses: learn()
  • see: botloader.php
  • see: botloaderinc.php
  • todo: Seperate the XML reading from the processing code. Perhaps making a seperate class for this.
void loadstartup ()
loadstartupinc (line 937)

Parses startup.xml if the bot is loaded incrementally - one file at a time.

Parses the startup.xml if the bot id loaded incrementally. One file at a time. This is very hacky and may not work properly.

  • global: string $rootdir: The root directory of the AIML files?
  • global: array $learnfiles: This array will hold the files to LEARN
  • global: boolean $areinc:
  • global: array $allbots: Contains all the botnames.
  • global: integer $selectbot: contains the selected bot ID.
  • uses: learn()
void loadstartupinc (integer $fileid)
  • integer $fileid: the ID of the file to be processed.
makesplitterphp (line 1357)

Create the array PHP code for the sentence splitters

In AIML it is custom to return a reply for every sentence the user inputs. This means the sentence input needs to be split into individual sentences. However, some people find that the semi-colon should also be added, while others think it should. The user will define the sentence splitters in startup.xml and these will then be stored in a PHP file included by the application.

  • return: PHP array code for storing the sentence splitters
  • usedby: makesubscode()
string makesplitterphp (array $splitterarray)
  • array $splitterarray: containing the sentence splitters found in startup.xml
makesrphp (line 1247)

Creates the PHP array code for subs.inc.

Subs.inc contains PHP code written during the bot load process. This function creates the array PHP code and returns the code as a string.

string makesrphp (array $inarray, string $sname)
  • array $inarray: is an array with either gender, person(2), input and splitter details
  • string $sname: which array is being processed, is also the array namein subs.inc.
makesubscode (line 1440)

Creates the subs.inc file.

Creates the subs.inc file and fills it with 5 arrays that correspond to the 4 substitution sections and sentence splitters.

  • return: Writes a file.
  • global: array $genderarray: contains the gender substitutions
  • global: array $personarray: contains the person substitutions
  • global: array $person2array: contains the person2 substitutions
  • global: array $inputarray: ?????
  • global: array $splitterarray: contains the sentence splitters
  • uses: addtosubs()
  • uses: createsubfile()
  • uses: makesplitterphp()
  • uses: makesrphp()
void makesubscode ()
setnotend (line 273)

Set an entry in the patterns table to not be flagged as the last word in its context.

Update a record in the patterns table, change isend column from 1 to 0. Given a particular word ID.

void setnotend (mixed $wordid, integer $wordid )
  • integer $wordid
ss_timing_current (line 1216)

Retrieve timer data

Get the running time the timed script

  • return: the formated running time of the timed stript.
  • global: array $ss_timing_start_times: ss_timing_start_times contains the start and finish moments of the script
  • global: array $ss_timing_stop_times: ss_timing_stop_times contains the stop moments of a script
string ss_timing_current ([string $name = 'default'])
  • string $name: default value is 'default' Makes it possibe to time more than event in one script.
ss_timing_start (line 1181)

Start a timer

Save the start time of the to be timed script

  • return: nothing
  • global: array $ss_timing_start_times: ss_timing_start_times contains the start moments of the script
void ss_timing_start ([string $name = 'default'])
  • string $name: default value is 'default' Makes it possibe to time more than event in one script.
ss_timing_stop (line 1198)

Stop a timer

Save the stop time of the to be timed script

  • return: nothing
  • global: array $ss_timing_stop_times: ss_timing_stop_times contains the stop moments of a script
void ss_timing_stop ([string $name = 'default'])
  • string $name: default value is 'default' Makes it possibe to time more than event in one script.
startElement (line 747)

Used by the AIML XML parser

Looks for the start tag used in AIML files for category, template, that, topic.

  • global: string $whaton: which tag is being processed
  • global: string $template:
  • global: string $pattern:
  • global: integer $recursive: to indicate if recursion is allowed
  • global: string $topic: the topic at hand in the AIML file
  • usedby: learn()
  • usedby: learnstring()
  • uses: getbotvalue()
  • uses: upperkeysarray()
void startElement (resource $parser, string $name, array $attrs)
  • resource $parser: SAX XML resource handler
  • string $name: name of the encountered tag.
  • array $attrs: contains the additional attribues of a tag, like value, id, find.
startS (line 517)

Called by the XML parser that is parsing the startup.xml file.

startS and endS are two functions that cooperate. startS looks for the start of an XML tag, endS for the end tag. It fills the global variabls with info to be processed further on. Inserts the bots into the bots table, inserts the bot predicates into its respective table.

  • global: integer $selectbot:
  • global: string $whaton:
  • global: array $startupwhich:
  • global: array $splitterarray: contains the splitter characters which are used to split the sentences. For example period, comma, semi-colon, exclamation mark, question mark.
  • global: array $inputarray: contains the input, split into sentences
  • global: array $genderarray: contains the gender words or phrases.
  • global: array $personarray: contains the person words or phrases
  • global: array $person2array: contains the person2 words or phrases
  • global: array $allbots: contains the names of all the bots, or their ID's
  • global: array $areinc: contains something unknown
  • uses: deletebot()
  • usedby: loadstartup()
  • uses: getbotid()
  • uses: botexists()
  • uses: upperkeysarray()
  • todo: Find out what Global $areinc does
void startS (resource $parser, string $name, array $attrs)
  • resource $parser: SAX XML resource handler
  • string $name: name of the encountered tag.
  • array $attrs: contains the additional attribues of a tag, like value, id, find.
templateexists (line 471)

Checks if a template exists for a given pattern

Does a query on the database to see if an ID is used by a template in the templates table.

boolean templateexists (integer $idused)
  • integer $idused: The ID number that corresponds to the number in the ID column, if it exists.
upperkeysarray (line 134)

Makes the keys of an array uppercase.

Makes the keys of an array uppercase.

array upperkeysarray (array $testa)
  • array $testa: The array where the keys need to be changed into uppercase.

Documentation generated on Wed, 12 Jan 2005 12:24:42 +0100 by phpDocumentor 1.3.0RC3