org.aitools.programd.multiplexor
Class Multiplexor

java.lang.Object
  extended by org.aitools.programd.multiplexor.Multiplexor
Direct Known Subclasses:
DBMultiplexor, FlatFileMultiplexor

public abstract class Multiplexor
extends java.lang.Object

"To multiplex" means "to select one from many inputs". A Multiplexor multiplexes the clients of a bot and keeps track of all their predicate values.

The following metaphor was supplied by Richard Wallace: The Multiplexor controls a short "carnival ride" for each user. The Multiplexor puts the client in his/her seat, hands him/her an id card, and closes the door. The client gets one "turn of the crank". He/she enters his/her id, multiline query, and then receives the reply. The door opens, the Multiplexor ushers him/her out, and seats the next client.

Since:
4.1.3
Author:
Noel Bush, Richard Wallace, Jon Baer, Thomas Ringate/Pedro Colla

Field Summary
protected static java.lang.String ASTERISK
          An asterisk (used in String production)
protected  float avgResponseTime
          A counter for tracking average response time.
protected  Bots bots
          The Bots object that belongs to the Core.
protected  Core core
          The Core that owns this Multiplexor.
protected static java.lang.String EMPTY_STRING
          An empty string.
protected  Graphmaster graphmaster
          The Graphmaster in use by the Core.
protected static java.lang.String INPUT
          The name of the input special predicate.
protected static org.apache.log4j.Logger logger
          The general log where we will record some events.
protected static org.apache.log4j.Logger matchLogger
          The log where match info will be recorded.
protected  java.lang.String predicateEmptyDefault
          The predicate empty default.
protected  PredicateMaster predicateMaster
          The PredicateMaster in use by the Core.
protected  long responseCount
          A counter for tracking the number of responses produced.
protected static java.lang.String STAR
          The name of the star special predicate.
protected  long startTime
          The time that the Multiplexor started operation.
protected static java.lang.String THAT
          The name of the that special predicate.
protected static java.lang.String TOPIC
          The name of the topic special predicate.
protected  long totalTime
          The total response time.
protected static java.lang.String VALUE
          The word "value".
 
Constructor Summary
Multiplexor(Core owner)
          Constructs the Multiplexor, using some values taken from the Core object's settings.
 
Method Summary
 void attach(PredicateMaster predicateMasterToAttach)
          Attaches the given PredicateMaster to this Multiplexor.
 float averageResponseTime()
          Returns the average response time.
abstract  void createUser(java.lang.String userid, java.lang.String password, java.lang.String botid)
          Creates a new user entry, given a userid and password.
 java.lang.String getInternalResponse(java.lang.String input, java.lang.String userid, java.lang.String botid, TemplateParser parser)
           Produces a response to an "internal" input sentence -- i.e., an input that has been produced by a srai.
private  java.lang.String getMatchResult(java.lang.String input, java.lang.String that, java.lang.String topic, java.lang.String userid, java.lang.String botid, TemplateParser parser)
          Gets the match result from the Graphmaster.
private  java.util.List<java.lang.String> getReplies(java.util.List<java.lang.String> sentenceList, java.lang.String userid, java.lang.String botid)
          Gets the list of replies to some input sentences.
private  java.lang.String getReply(java.lang.String input, java.lang.String that, java.lang.String topic, java.lang.String userid, java.lang.String botid)
          Gets a reply to an input.
 java.lang.String getResponse(java.lang.String input, java.lang.String userid, java.lang.String botid)
          Returns the response to a non-internal input, without using a Responder.
abstract  boolean changePassword(java.lang.String userid, java.lang.String password, java.lang.String botid)
          Changes the password associated with a userid.
abstract  boolean checkUser(java.lang.String userid, java.lang.String password, java.lang.String botid)
          Checks whether a given userid and password combination is valid.
abstract  void initialize()
          Can do whatever initialization is needed for the particular multiplexor.
abstract  java.lang.String loadPredicate(java.lang.String name, java.lang.String userid, java.lang.String botid)
          Loads a predicate into memory for a given userid.
private  void logResponse(java.lang.String input, java.lang.String response, java.lang.String userid, java.lang.String botid)
          Logs a response to the chat log.
 float queriesPerHour()
          Returns the number of queries per hour.
abstract  void savePredicate(java.lang.String name, java.lang.String value, java.lang.String userid, java.lang.String botid)
          Saves a predicate for a given userid.
abstract  int useridCount(java.lang.String botid)
          Returns a count of known userids.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

THAT

protected static final java.lang.String THAT
The name of the that special predicate.

See Also:
Constant Field Values

TOPIC

protected static final java.lang.String TOPIC
The name of the topic special predicate.

See Also:
Constant Field Values

INPUT

protected static final java.lang.String INPUT
The name of the input special predicate.

See Also:
Constant Field Values

STAR

protected static final java.lang.String STAR
The name of the star special predicate.

See Also:
Constant Field Values

EMPTY_STRING

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

See Also:
Constant Field Values

VALUE

protected static final java.lang.String VALUE
The word "value".

See Also:
Constant Field Values

ASTERISK

protected static final java.lang.String ASTERISK
An asterisk (used in String production)

See Also:
Constant Field Values

predicateEmptyDefault

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


core

protected Core core
The Core that owns this Multiplexor.


graphmaster

protected Graphmaster graphmaster
The Graphmaster in use by the Core.


predicateMaster

protected PredicateMaster predicateMaster
The PredicateMaster in use by the Core.


bots

protected Bots bots
The Bots object that belongs to the Core.


logger

protected static final org.apache.log4j.Logger logger
The general log where we will record some events.


matchLogger

protected static final org.apache.log4j.Logger matchLogger
The log where match info will be recorded.


startTime

protected long startTime
The time that the Multiplexor started operation.


responseCount

protected long responseCount
A counter for tracking the number of responses produced.


totalTime

protected long totalTime
The total response time.


avgResponseTime

protected float avgResponseTime
A counter for tracking average response time.

Constructor Detail

Multiplexor

public Multiplexor(Core owner)
Constructs the Multiplexor, using some values taken from the Core object's settings. Note that the predicateMaster is not initialized -- it must be attach(org.aitools.programd.multiplexor.PredicateMaster)ed subsequently.

Parameters:
owner - the Core that owns this Multiplexor
Method Detail

attach

public void attach(PredicateMaster predicateMasterToAttach)
Attaches the given PredicateMaster to this Multiplexor.

Parameters:
predicateMasterToAttach -

initialize

public abstract void initialize()
Can do whatever initialization is needed for the particular multiplexor.


getResponse

public java.lang.String getResponse(java.lang.String input,
                                    java.lang.String userid,
                                    java.lang.String botid)
Returns the response to a non-internal input, without using a Responder.

Parameters:
input - the "non-internal" (possibly multi-sentence, non-substituted) input
userid - the userid for whom the response will be generated
botid - the botid from which to get the response
Returns:
the response

getInternalResponse

public java.lang.String getInternalResponse(java.lang.String input,
                                            java.lang.String userid,
                                            java.lang.String botid,
                                            TemplateParser parser)

Produces a response to an "internal" input sentence -- i.e., an input that has been produced by a srai.

This method takes an already-existing TemplateParser, doesn't take a Responder, and assumes that the inputs have already been normalized.

Parameters:
input - the input sentence
userid - the userid requesting the response
botid - the botid from which to get the response
parser - the parser object to update when generating the response
Returns:
the response

getReplies

private java.util.List<java.lang.String> getReplies(java.util.List<java.lang.String> sentenceList,
                                                    java.lang.String userid,
                                                    java.lang.String botid)
Gets the list of replies to some input sentences. Assumes that the sentences have already had all necessary pre-processing and substitutions performed.

Parameters:
sentenceList - the input sentences
userid - the userid requesting the replies
botid -
Returns:
the list of replies to the input sentences

getReply

private java.lang.String getReply(java.lang.String input,
                                  java.lang.String that,
                                  java.lang.String topic,
                                  java.lang.String userid,
                                  java.lang.String botid)
Gets a reply to an input. Assumes that the input has already had all necessary substitutions and pre-processing performed, and that the input is a single sentence.

Parameters:
input - the input sentence
that - the input that value
topic - the input topic value
userid - the userid requesting the reply
botid -
Returns:
the reply to the input sentence

getMatchResult

private java.lang.String getMatchResult(java.lang.String input,
                                        java.lang.String that,
                                        java.lang.String topic,
                                        java.lang.String userid,
                                        java.lang.String botid,
                                        TemplateParser parser)
Gets the match result from the Graphmaster.

Parameters:
input - the input to match
that - the current that value
topic - the current topic value
userid - the userid for whom to perform the match
botid - the botid for whom to perform the match
parser - the parser to use
Returns:
the match result

logResponse

private void logResponse(java.lang.String input,
                         java.lang.String response,
                         java.lang.String userid,
                         java.lang.String botid)
Logs a response to the chat log.

Parameters:
input - the input that produced the response
response - the response
userid - the userid for whom the response was produced
botid - the botid that produced the response

averageResponseTime

public float averageResponseTime()
Returns the average response time.

Returns:
the average response time

queriesPerHour

public float queriesPerHour()
Returns the number of queries per hour.

Returns:
the number of queries per hour

savePredicate

public abstract void savePredicate(java.lang.String name,
                                   java.lang.String value,
                                   java.lang.String userid,
                                   java.lang.String botid)
Saves a predicate for a given userid. This only applies to Multiplexors that provide long-term storage (others may just do nothing).

Parameters:
name - predicate name
value - predicate value
userid - user identifier
botid -
Since:
4.1.4

loadPredicate

public abstract java.lang.String loadPredicate(java.lang.String name,
                                               java.lang.String userid,
                                               java.lang.String botid)
                                        throws NoSuchPredicateException
Loads a predicate into memory for a given userid. This only applies to Multiplexors that provide long-term storage (others may just do nothing).

Parameters:
name - predicate name
userid - user identifier
botid -
Returns:
the predicate value
Throws:
NoSuchPredicateException - if there is no predicate with this name
Since:
4.1.4

checkUser

public abstract boolean checkUser(java.lang.String userid,
                                  java.lang.String password,
                                  java.lang.String botid)
Checks whether a given userid and password combination is valid. Multiplexors for which this makes no sense should just return true.

Parameters:
userid - the userid to check
botid -
password - the password to check
Returns:
whether the userid and password combination is valid

createUser

public abstract void createUser(java.lang.String userid,
                                java.lang.String password,
                                java.lang.String botid)
                         throws DuplicateUserIDError
Creates a new user entry, given a userid and password. Multiplexors for which this makes no sense should just return true.

Parameters:
userid - the userid to use
botid -
password - the password to assign
Throws:
DuplicateUserIDError - if the given userid was already found in the system

changePassword

public abstract boolean changePassword(java.lang.String userid,
                                       java.lang.String password,
                                       java.lang.String botid)
Changes the password associated with a userid. Multiplexors for which this makes no sense should just return true.

Parameters:
userid - the userid
botid -
password - the new password
Returns:
whether the change was successful

useridCount

public abstract int useridCount(java.lang.String botid)
Returns a count of known userids. This may be defined differently for different multiplexors.

Parameters:
botid - the botid for which we want a count of known userids
Returns:
a count of known userids