org.aitools.programd.bot
Class Bot

java.lang.Object
  extended by org.aitools.programd.bot.Bot

public class Bot
extends java.lang.Object

Handles all of the properties of a bot.

Since:
4.1.5
Author:
Noel Bush, Eion Robb

Field Summary
private static java.lang.String EMPTY_STRING
          An empty string.
private  java.lang.String id
          The identifier for the bot.
private  java.util.Map<java.util.regex.Pattern,java.lang.String> inputSubstitutions
          The bot's input substitution map.
private  java.util.Map<java.net.URL,java.util.Set<Nodemapper>> loadedFiles
          The files loaded for the bot.
private  java.util.Map<java.lang.String,PredicateMap> predicateCache
          Holds cached predicates, keyed by userid.
protected  java.lang.String predicateEmptyDefault
          The predicate empty default.
private  java.util.Map<java.lang.String,PredicateInfo> predicatesInfo
          The bot's predicate infos.
private  java.util.Map<java.lang.String,java.lang.String> properties
          The bot's properties.
private  java.util.List<java.lang.String> sentenceSplitters
          The bot's sentence splitter map.
private  java.lang.String servletPage
          The page to use for this bot when communicating via the servlet interface.
private  java.util.Map<java.lang.Class<? extends Processor>,java.util.LinkedHashMap<java.util.regex.Pattern,java.lang.String>> substitutionMaps
          The bot's processor-specific substitution maps.
private  java.net.URL testReportDirectory
          The directory where test reports are to be written.
private  java.util.List<java.net.URL> testSuites
          The files containing test suites.
 
Constructor Summary
Bot(java.lang.String botID, CoreSettings coreSettings)
          Creates a new Bot with the given id.
 
Method Summary
 void addInputSubstitution(java.util.regex.Pattern find, java.lang.String replace)
          Adds an input substitution.
 void addPredicateInfo(java.lang.String name, java.lang.String defaultValue, boolean returnNameWhenSet)
          Registers some information about a predicate in advance.
 void addSentenceSplitter(java.lang.String splitter)
          Adds a sentence splitter to the sentence splitters list.
 void addSubstitution(java.lang.Class<? extends Processor> processor, java.util.regex.Pattern find, java.lang.String replace)
          Adds a substitution to the indicated map.
 void addToPathMap(java.net.URL path, Nodemapper nodemapper)
          Adds a nodemapper to the path map.
 java.lang.String applyInputSubstitutions(java.lang.String input)
          Applies input substitutions to the given input
 java.lang.String getID()
          Returns the id of the bot.
 java.util.Map<java.net.URL,java.util.Set<Nodemapper>> getLoadedFilesMap()
          Returns a map of the files loaded by this bot.
 java.util.Map<java.lang.String,PredicateMap> getPredicateCache()
          Returns the predicate cache.
 java.util.Map<java.lang.String,PredicateInfo> getPredicatesInfo()
          Returns the predicates info map.
 java.util.Map<java.lang.String,java.lang.String> getProperties()
           
 java.lang.String getPropertyValue(java.lang.String name)
          Retrieves the value of a named bot property.
 java.util.List<java.lang.String> getSentenceSplitters()
           
 java.lang.String getServletPage()
           
 java.util.Map<java.util.regex.Pattern,java.lang.String> getSubstitutionMap(java.lang.Class<? extends Processor> processor)
           
 java.net.URL getTestReportDirectory()
           
 java.util.List<java.net.URL> getTestSuites()
           
 boolean hasLoaded(java.lang.String filename)
          Returns whether the bot has loaded the given file(name).
 PredicateMap predicatesFor(java.lang.String userid)
          Returns the map of predicates for a userid if it is cached, or a new map if it is not cached.
 java.util.List<java.lang.String> sentenceSplit(java.lang.String input)
          Splits the given input into sentences.
 void setProperties(java.util.HashMap<java.lang.String,java.lang.String> map)
          Sets the bot's properties.
 void setPropertyValue(java.lang.String name, java.lang.String value)
          Sets the value of a bot property.
 void setServletPage(java.lang.String page)
           
 void setTestReportDirectory(java.net.URL url)
           
 void setTestSuitePathspec(java.util.List<java.net.URL> files)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

private java.lang.String id
The identifier for the bot.


loadedFiles

private java.util.Map<java.net.URL,java.util.Set<Nodemapper>> loadedFiles
The files loaded for the bot.


properties

private java.util.Map<java.lang.String,java.lang.String> properties
The bot's properties.


predicatesInfo

private java.util.Map<java.lang.String,PredicateInfo> predicatesInfo
The bot's predicate infos.


substitutionMaps

private java.util.Map<java.lang.Class<? extends Processor>,java.util.LinkedHashMap<java.util.regex.Pattern,java.lang.String>> substitutionMaps
The bot's processor-specific substitution maps.


inputSubstitutions

private java.util.Map<java.util.regex.Pattern,java.lang.String> inputSubstitutions
The bot's input substitution map.


sentenceSplitters

private java.util.List<java.lang.String> sentenceSplitters
The bot's sentence splitter map.


predicateCache

private java.util.Map<java.lang.String,PredicateMap> predicateCache
Holds cached predicates, keyed by userid.


servletPage

private java.lang.String servletPage
The page to use for this bot when communicating via the servlet interface.


testSuites

private java.util.List<java.net.URL> testSuites
The files containing test suites.


testReportDirectory

private java.net.URL testReportDirectory
The directory where test reports are to be written.


predicateEmptyDefault

protected java.lang.String predicateEmptyDefault
The predicate empty default.


EMPTY_STRING

private static final java.lang.String EMPTY_STRING
An empty string.

See Also:
Constant Field Values
Constructor Detail

Bot

public Bot(java.lang.String botID,
           CoreSettings coreSettings)
Creates a new Bot with the given id. The bot's chat log is also set up. A default servlet page is set.

Parameters:
botID - the id to use for the new bot
coreSettings - the core settings to use
Method Detail

getID

public java.lang.String getID()
Returns the id of the bot.

Returns:
the id of the bot

getLoadedFilesMap

public java.util.Map<java.net.URL,java.util.Set<Nodemapper>> getLoadedFilesMap()
Returns a map of the files loaded by this bot.

Returns:
a map of the files loaded by this bot

hasLoaded

public boolean hasLoaded(java.lang.String filename)
Returns whether the bot has loaded the given file(name).

Parameters:
filename - the filename to check
Returns:
whether the bot has loaded the given file(name)

addToPathMap

public void addToPathMap(java.net.URL path,
                         Nodemapper nodemapper)
Adds a nodemapper to the path map.

Parameters:
path - the path
nodemapper - the mapper for the node to add

getPropertyValue

public java.lang.String getPropertyValue(java.lang.String name)
Retrieves the value of a named bot property.

Parameters:
name - the name of the bot property to get
Returns:
the value of the bot property

setPropertyValue

public void setPropertyValue(java.lang.String name,
                             java.lang.String value)
Sets the value of a bot property.

Parameters:
name - the name of the bot predicate to set
value - the value to set

getProperties

public java.util.Map<java.lang.String,java.lang.String> getProperties()
Returns:
the properties

setProperties

public void setProperties(java.util.HashMap<java.lang.String,java.lang.String> map)
Sets the bot's properties.

Parameters:
map - the properties to set.

addPredicateInfo

public void addPredicateInfo(java.lang.String name,
                             java.lang.String defaultValue,
                             boolean returnNameWhenSet)
Registers some information about a predicate in advance. Not required; just used when it is necessary to specify a default value for a predicate and/or specify its type as return-name-when-set.

Parameters:
name - the name of the predicate
defaultValue - the default value (if any) for the predicate
returnNameWhenSet - whether the predicate should return its name when set

getPredicatesInfo

public java.util.Map<java.lang.String,PredicateInfo> getPredicatesInfo()
Returns the predicates info map.

Returns:
the predicates info map

getPredicateCache

public java.util.Map<java.lang.String,PredicateMap> getPredicateCache()
Returns the predicate cache.

Returns:
the predicate cache

predicatesFor

public PredicateMap predicatesFor(java.lang.String userid)
Returns the map of predicates for a userid if it is cached, or a new map if it is not cached.

Parameters:
userid -
Returns:
the map of predicates for the given userid

addSubstitution

public void addSubstitution(java.lang.Class<? extends Processor> processor,
                            java.util.regex.Pattern find,
                            java.lang.String replace)
Adds a substitution to the indicated map. If the map does not yet exist, it is created. The find parameter is stored in uppercase, to do case-insensitive comparisons. The replace parameter is stored as is.

Parameters:
processor - the processor with which the map is associated
find - the find-string part of the substitution
replace - the replace-string part of the substitution

addInputSubstitution

public void addInputSubstitution(java.util.regex.Pattern find,
                                 java.lang.String replace)
Adds an input substitution. The find parameter is stored in uppercase, to do case-insensitive comparisons. The replace parameter is stored as is.

Parameters:
find - the find-string part of the substitution
replace - the replace-string part of the substitution

addSentenceSplitter

public void addSentenceSplitter(java.lang.String splitter)
Adds a sentence splitter to the sentence splitters list.

Parameters:
splitter - the string on which to divide sentences

getSubstitutionMap

public java.util.Map<java.util.regex.Pattern,java.lang.String> getSubstitutionMap(java.lang.Class<? extends Processor> processor)
Parameters:
processor - the processor whose substitution map is desired
Returns:
the substitution map associated with the given processor class.

getSentenceSplitters

public java.util.List<java.lang.String> getSentenceSplitters()
Returns:
the sentence splitters

sentenceSplit

public java.util.List<java.lang.String> sentenceSplit(java.lang.String input)
Splits the given input into sentences.

Parameters:
input - the input to split
Returns:
the sentences of the input

applyInputSubstitutions

public java.lang.String applyInputSubstitutions(java.lang.String input)
Applies input substitutions to the given input

Parameters:
input - the input to which to apply substitutions
Returns:
the processed input

getTestReportDirectory

public java.net.URL getTestReportDirectory()
Returns:
Returns the testReportDirectory.

setTestReportDirectory

public void setTestReportDirectory(java.net.URL url)
Parameters:
url - The testReportDirectory to set.

getTestSuites

public java.util.List<java.net.URL> getTestSuites()
Returns:
Returns the list of test suite files.

setTestSuitePathspec

public void setTestSuitePathspec(java.util.List<java.net.URL> files)
Parameters:
files - The list of test suite files to set

setServletPage

public void setServletPage(java.lang.String page)
Parameters:
page - the servlet servletPage to user

getServletPage

public java.lang.String getServletPage()
Returns:
the servlet servletPage