org.alicebot.server.core
Class Multiplexor

java.lang.Object
  extended by org.alicebot.server.core.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.

Historically, the functionality specified by this class was implemented in Classifier. However, Classifier evolved to include database access methods that were not desirable for all implementations. Furthermore, Classifier lost part of its original purpose as a "classifier of user inputs into categories". Hence, the Program D Classifier has been left as-is, except it has been changed into an subclass of this abstract class. There are two new subclasses called FlatFileMultiplexor and DBMultiplexor.

Starting in 4.1.5, this became an abstract class instead of an interface, and introduced the single public getResponse(java.lang.String, java.lang.String, java.lang.String, org.alicebot.server.core.responder.Responder) method, rather than allowing multiple public methods for getting responses which can result in synchronization problems. The former AbstractClassifier class was then removed.

Since:
4.1.3
Author:
Noel Bush, Richard Wallace, Jon Baer, Thomas Ringate/Pedro Colla
See Also:
FlatFileMultiplexor}, DBMultiplexor}

Field Summary
protected static java.lang.String ASTERISK
          An asterisk (used in String production)
protected static float avgResponseTime
          A counter for tracking average response time.
protected static java.lang.String EMPTY_STRING
          An empty string.
protected static java.lang.String HOST_NAME
          The host name.
protected static java.lang.String INPUT
          The name of the input special predicate.
protected static java.lang.String PREDICATE_EMPTY_DEFAULT
          The predicate empty default.
protected static java.lang.String QUOTE_MARK
          A quote mark.
protected static long responseCount
          A counter for tracking the number of responses produced.
protected static java.lang.String SECRET_KEY
          A secret key used for (weakly) authorizing authentication requests.
protected static boolean SHOW_CONSOLE
          Whether to show the console.
protected static boolean SHOW_MATCH_TRACE
          Whether to show the match trace.
protected static java.lang.String SPACE
          A space.
protected static java.lang.String STAR
          The name of the star special predicate.
protected static 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 static long totalTime
          The total response time.
protected static boolean USE_TARGETING
          Whether to use targeting.
protected static java.lang.String VALUE
          The word "value".
 
Constructor Summary
Multiplexor()
           
 
Method Summary
static void addPulse(Pulse pulse)
          Adds a Pulse to the registered list.
 float averageResponseTime()
          Returns the average response time.
abstract  boolean changePassword(java.lang.String userid, java.lang.String password, java.lang.String secretKey, 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 secretKey, java.lang.String botid)
          Checks whether a given userid and password combination is valid.
abstract  boolean createUser(java.lang.String userid, java.lang.String password, java.lang.String secretKey, java.lang.String botid)
          Creates a new user entry, given a userid and password.
static 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.
static java.lang.String getResponse(java.lang.String input, java.lang.String userid, java.lang.String botid, Responder responder)
          Returns the response to a non-internal input, using a Responder.
 void initialize()
          Initializes the Multiplexor, creating the secret key that can be used for a weak form of authentication.
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.
static void pulse()
          Emits any registered pulses.
 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

SPACE

protected static final java.lang.String SPACE
A space.

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

QUOTE_MARK

protected static final java.lang.String QUOTE_MARK
A quote mark.

See Also:
Constant Field Values

HOST_NAME

protected static final java.lang.String HOST_NAME
The host name.


SHOW_CONSOLE

protected static final boolean SHOW_CONSOLE
Whether to show the console.


SHOW_MATCH_TRACE

protected static final boolean SHOW_MATCH_TRACE
Whether to show the match trace.


USE_TARGETING

protected static final boolean USE_TARGETING
Whether to use targeting.


PREDICATE_EMPTY_DEFAULT

protected static final java.lang.String PREDICATE_EMPTY_DEFAULT
The predicate empty default.


SECRET_KEY

protected static java.lang.String SECRET_KEY
A secret key used for (weakly) authorizing authentication requests.


startTime

protected static long startTime
The time that the Multiplexor started operation.


responseCount

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


totalTime

protected static long totalTime
The total response time.


avgResponseTime

protected static float avgResponseTime
A counter for tracking average response time.

Constructor Detail

Multiplexor

public Multiplexor()
Method Detail

initialize

public void initialize()
Initializes the Multiplexor, creating the secret key that can be used for a weak form of authentication.


getResponse

public static java.lang.String getResponse(java.lang.String input,
                                           java.lang.String userid,
                                           java.lang.String botid,
                                           Responder responder)
Returns the response to a non-internal input, 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
responder - the Responder who cares about this response

getInternalResponse

public static 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.

The main differences between this and #getResponse(String,String,TemplateParser,boolean,Responder) are that 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
See Also:
#getResponse(String,String,TemplateParser,boolean,Responder)}

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

addPulse

public static void addPulse(Pulse pulse)
Adds a Pulse to the registered list.

Parameters:
pulse - the Pulse to be added

pulse

public static void pulse()
Emits any registered pulses.


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 secretKey,
                                  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
secretKey - the secret key that should authenticate this request
Returns:
whether the userid and password combination is valid

createUser

public abstract boolean createUser(java.lang.String userid,
                                   java.lang.String password,
                                   java.lang.String secretKey,
                                   java.lang.String botid)
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
secretKey - the secret key that should authenticate this request
Returns:
whether the creation was successful

changePassword

public abstract boolean changePassword(java.lang.String userid,
                                       java.lang.String password,
                                       java.lang.String secretKey,
                                       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
secretKey - the secret key that should authenticate this request
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.

Returns:
a count of known userids