File/util.php

Description

Util.php, Utility functions

Contains reusable functions for Program E

Classes
Class Description
 class Response Class to hold the reponse
Includes
 require_once ("admin/subs.inc") (line 59)

subs.inc has all of the substitution values and sentence splitter values

Functions
addinputs (line 382)

Store the clients inputs into the database.

This is an array because it separates on .'s and other sentence splitters. Stores these in the dstore table of the database.

  • return: nothing
  • global: integer $uid:
  • usedby: reply()
void addinputs (array $inputsarray)
  • array $inputsarray: Contains multiple inputs (i.e. sentences) of a user
addthats (line 415)

Store the bots responses into the database

This is an array because it separates on .'s and other sentence splitters. Stores these in the thatindex table of the database.

  • return: nothing
  • global: integer $uid:
  • usedby: reply()
void addthats (array $inputsarray)
  • array $inputsarray: Contains multiple inputs (sentences) of the bot
bget (line 319)

Get a value for some variable set by the user in AIML.

In the template (<template> ... </template>) variables can be set and used during matching. after matching these variables are stored in the table dstore. This function retrieves the value of a stored variable. This type of variable is also called a 'predicate'.

  • return: Either the value of the stored predicate, or the constand default value of a predicate
  • global: integer $uid:
  • usedby: respond()
  • usedby: reply()
string bget (mixed $name)
botget (line 284)

Get information about the bot that was entered in the startup.xml

In startup.xml there are a number of bot-varables called in AIML as <bot name="foo"/> These are stored in the table 'bot' and this function retrieves (ex.) the value of bot-variable "foo".

  • return: The value of requested bot variable.
  • global: integer $uid: uid is created in talk.php as $myuniqueid then transformed in respond.php into $uid by reply()
  • global: integer $selectbot: selectbot is created in respond.php:replybotname() as $botid which in return calls reply() that turns it into $selectbot
  • usedby: handlenode()
  • see: replybotname()
  • see: reply()
  • see: talk.php
string botget (string $name)
  • string $name: The name of the bot-variable of which the value is requested.
bset (line 355)

Set the value for an AIML variable

Function to store the variable name and it's contents into the dstore table. It doens't update the table, just the first insert.

  • return: doesn't return anything
  • global: integer $uid:
  • usedby: handlenode()
void bset (string $name, string $value)
  • string $name: The name in which the value should be stored
  • string $value: The contents of the variable.
cleanup (line 88)

This function will clean up old data in the database that is not needed according to user defined settings.

Deletes entries in the database tables dstore, thatstack, thatstackindex and if set also conversationlog.

void cleanup ()
firstsecond (line 699)

Do a first to second person replacement

Replaces, for example, "with you" to "with me". he gender related words and phrases that are used can be found in subs.inc and originally in the startup.xml

  • return: The string containing where the first->second related words have been replaced.
  • global: array $firstsecondsearch:
  • global: array $firstsecondreplace:
  • global: array $aftersearch:
  • global: array $afterreplace:
  • global: integer $replacecounter:
  • usedby: handlenode()
string firstsecond (string $input)
  • string $input: The string where the first->second related words/phrases need to be replaced
firstthird (line 667)

Do a first to third person replacement

Replaces, for example, "I was" to "he or she was". he gender related words and phrases that are used can be found in subs.inc and originally in the startup.xml

  • return: The string containing where the first->third related words have been replaced.
  • global: array $firstthirdsearch: firstthirdsearch
  • global: array $firstthirdreplace: firstthirdreplace
  • global: array $aftersearch:
  • global: array $afterreplace:
  • global: array $contractsearch:
  • global: array $contractreplace:
  • global: integer $replacecounter:
  • usedby: handlenode()
string firstthird (string $input)
  • string $input: The string where the first->third related words/phrases need to be replaced
gender (line 633)

Reverse the gender of a phrase

Replaces, for example, 'he' in the string to 'she'. The gender related words and phrases that are used can be found in subs.inc and originally in the startup.xml

  • return: The string containing where the gender related words have been replaced.
  • global: array $gendersearch: gendersearch
  • global: array $genderreplace: genderreplace
  • global: array $aftersearch:
  • global: array $afterreplace:
  • global: integer $replacecounter:
  • usedby: handlenode()
string gender (string $input)
  • string $input: The string where the gender related words/phrases need to be replaced
GetChildren (line 751)

Get the child nodes of the XML tree

Retrieve the child nodes of the XML tree. This is a recursive function.

array GetChildren (array $vals, integer &$i)
  • array $vals
  • integer &$i: call-by-reference variable for, most likely, GetXMLTree()
getfdate (line 228)

get the current date formatted.

Should look like: Wed Nov 14 18:09:55 CST 2002

  • return: formated date string, Day name, Month name, day number month, time, time zone and year.
  • usedby: handlenode()
string getfdate ()
getid (line 214)

Get the ID, or IP of the user

Uses the server global REMOTE_ADDR.

  • return: IP number
  • global: REMOTE_ADDR 0: The user's remote address, i.e. LAN address.
  • usedby: handlenode()
string getid ()
getinput (line 537)

Get the previous thing the client said

Retrieve the entire previous input of the user from the dstore table.

  • return: The previous input of the user.
  • global: integer $uid:
  • usedby: handlenode()
string getinput (mixed $index)
getsize (line 245)

Gets the numer of AIML categories stored in the database

The size of the AIML knowledgebase is counted in categories. This function will count the number of categories based upon the number of records in the templates table.

integer getsize ()
getthat (line 487)

Get the previous thing the bot said

Retrieve from the thatindex table the previous output, per sentence, of what the bot said from the thatindex en thatstack table.

  • return: The requested sentence of the bot's output
  • global: integer $uid:
  • usedby: handlenode()
  • usedby: reply()
string getthat (integer $index, integer $offset)
  • integer $index: Number between 1-5, 1 representing the previous bot output and 5 the 5th last bot output.
  • integer $offset: Bot output is saved per sentence. So 1 would be last sentence, 3 would be third last sentence of that bot output.
GetXMLTree (line 797)

Get an XML tree

Create an XML tree in array form from a large string.

array GetXMLTree (string $data)
  • string $data: Large string that needs to be turned into XML data.
insertgossip (line 726)

Insert gossip into the database

Gossip is an AIML tag where the user can store bits of information from one user and then reuse is in the conversation of another user. It is the only tag that behaves this way. Stores value into the gossip table of the database.

void insertgossip (string $gossip)
  • string $gossip: The string that needs to be saved.
iscustomtag (line 922)

Check to see if a tag is a custom tag.

Program E supports additional, non AIML 1.0x specified, custom tags. This function checks to see if the encountered XML tag is indeed a custom AIML tag. If it is a custom tag, it will then the appropriate function to use in &$functicall.

  • return: true/false
  • global: array $cttags: cttags contains all the custom tags. Array is created by loadcustomtags()
  • see: loadcustomtags()
boolean iscustomtag (string $tagname, &$functocall &$functocall)
  • string $tagname: name of the tag to be checked
  • &$functocall &$functocall: call-by-reference variable used to send back the function name that needs to be called to process the tag's contents.
isdeprecated (line 143)

Check if a tag is an old style AIML tag.

If it is then return its new name and the fact that it is deprecated. This information is not send back through the return value, but by using call-by-reference variable &$ttag.

  • return: true/false; either it is a depreciated AIML tag or it is not.
boolean isdeprecated (string $tag, string &$ttag)
  • string $tag: the tag name that needs to be checked
  • string &$ttag: depreciated AIML tag name. Note, call-by-reference variable.
loadcustomtags (line 945)

Load all custom tags

Create a global accessible array with all custom tags, based upon the custom tag functions (ct_FunctionName()).

void loadcustomtags ()
logconversation (line 461)

Logs the whole input and response

Saves the input and response into the conversationlog table of the database.

  • return: nothing
  • global: integer $uid:
  • global: integer $selectbot:
  • usedby: reply()
void logconversation (string $input, mixed $response, string $reponse)
  • string $input: The user's input.
  • string $reponse: The bot's response to the user's input.
lookupbotid (line 972)

Look up the bot's ID number

From the bot's name, retrieve it's bot ID number from the bots table in the database. This funtion requires that each bot has a uniqe name to function.

  • return: The bot ID that belongs to the unique botname.
  • usedby: replybotname()
integer lookupbotid (string $botname)
  • string $botname: The bot's name.
make_seed (line 72)

Create a random number based upon the present time.

  • return: A fully random generated floating point number.
  • usedby: cleanup()
float make_seed ()
myfunc (line 194)

Substitution routine

Is used in combination with for example firstthird() gender(). The myfunc() is called from these functions from the arrays generated in subs.inc by makesrphp().

When doing substitution myfunc replaces the words to be substituted with ~~x~~ where x is an incremented integer instead of what should eventually be substituted. Then when all substitution is done another function will go through and replace the ~~x~~ with the real value.

  • return: The user's input, with ~~number~~ where the words in the substitution list should be.
  • global: integer $replacecounter: replacecounter The incremented integer number for substitution.
  • global: array $aftersearch: aftersearch Contains ~~replacecounter number~~
  • global: array $afterreplace: afterreplace Countains the input. (Anne:Have no idea how this works, yet.)
  • todo: Analyse if a straight replace will be more effective and efficient. Hard to see why this two-stage replace has any advantages. If not, then rename the function.
string myfunc (string $input)
  • string $input: The new word replacing the old word.
normalsentences (line 582)

Take the user input and do all substitutions and split it into sentences

The matching process searches a match for every sentence and in the end combines all those individual matches into one reply. This funtion splits the sentences of the user's input, replaces the words that need to be subtituted (found in startup.xml).

  • return: each individual sentence, ready for matching.
  • global: array $contractsearch: contractsearch
  • global: array $contractreplace: contractreplace
  • global: mixed $abbrevsearch: abbrevsearch not used in this function
  • global: mixed $abbrevreplace: removepunct used in this function, but code is commented out.
  • global: array $removepunct: likeperiodsearch
  • global: array $likeperiodsearch: likeperiodreplace
  • global: array $likeperiodreplace: aftersearch
  • global: array $aftersearch: afterreplace
  • global: integer $afterreplace: replacecounter
  • usedby: reply()
array normalsentences (string $input)
  • string $input: The unchanged user input.
ss_timing_current (line 864)

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
  • usedby: reply()
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 829)

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
  • usedby: reply()
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 846)

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
  • usedby: reply()
void ss_timing_stop ([string $name = 'default'])
  • string $name: default value is 'default' Makes it possibe to time more than event in one script.
upperkeysarray (line 891)

Change the case of the keys of an array to all uppercase

Array keys can be number or strings. If strings then it's a good habit to use only uppercase. This is sadly not always the case. This function makes sure that they are.

  • return: Array containing only uppercase array keys.
  • usedby: handlenode()
array upperkeysarray (array $testa)
  • array $testa: Array suspected of having mixed case array keys.
whichbots (line 996)

Which bot is selected

Returns the bit of SQL query that limits the results to the selected bot.

  • return: The bit of SQL query that limits the results to the selected bot.
  • global: string $selectbot: selectbot The currently selected bot. The bot the user is chatting to.
  • usedby: getsize()
string whichbots ()

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