Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes
com.rosalfred.core.ia.rivescript.RiveScript Class Reference
Inheritance diagram for com.rosalfred.core.ia.rivescript.RiveScript:
Inheritance graph
[legend]

List of all members.

Public Member Functions

void dumpSorted ()
void dumpTopics ()
String error ()
String getCurrentUser ()
String[] getUsers ()
String getUservar (String user, String name)
ClientManager getUservars ()
HashMap< String, String > getUservars (String user)
boolean loadDirectory (final String path, final String[] exts)
boolean loadDirectory (final String path)
boolean loadFileJava (String file)
boolean loadFileRive (final String file)
BotReply reply (String username, String message)
 RiveScript (boolean debug)
 RiveScript ()
boolean setGlobal (String name, String value)
void setHandler (String name, ObjectHandler< BotReply > handler)
boolean setPersonSubstitution (String pattern, String output)
boolean setSubstitution (String pattern, String output)
boolean setUservar (String user, String name, String value)
boolean setUservars (String user, HashMap< String, String > data)
void setUservars (ClientManager clients)
boolean setVariable (String name, String value)
void sortReplies ()
boolean stream (String code)
boolean stream (String[] code)

Static Public Attributes

static final String TYPE_JAVA = "java"
static final String TYPE_PERL = "perl"
static final String TYPE_PYTHON = "python"
static final double VERSION = 0.02

Protected Member Functions

boolean error (final String message)
List< File > getFiles (final File directory, final String type)
HashMap< String, ObjectHandler
< BotReply > > 
getHandlers ()
void say (String line)

Protected Attributes

HashMap< String, String > objects

Private Member Functions

void cry (String line)
void cry (String text, String file, int line)
String formatMessage (String message)
String[] loadFile (String file, File fh) throws IOException
boolean parse (String filename, String[] code)
String processTags (String user, Client profile, String message, String reply, ArrayList< String > vstars, ArrayList< String > vbotstars, int step)
BotReply processTags (String user, Client profile, String message, BotReply botReply, ArrayList< String > vstars, ArrayList< String > vbotstars, int step)
BotReply reply (String user, String message, boolean begin, int step)
String stringTransform (String format, String text)
void trace (IOException e)
String triggerRegexp (String user, Client profile, String trigger)

Private Attributes

HashMap< String, Vector< String > > arrays
ClientManager clients = new ClientManager()
String currentUser = null
boolean debug = false
int depth = 50
String error = ""
HashMap< String, String > globals
HashMap< String, ObjectHandler
< BotReply > > 
handlers
HashMap< String, String > person
String[] person_s
HashMap< String, String > subs
String[] subs_s
TopicManager topics = new TopicManager()
HashMap< String, String > vars

Static Private Attributes

static final String CMD_CONDITION = "*"
static final String CMD_CONTINUE = "^"
static final String CMD_DEFINE = "!"
static final String CMD_ENDLABEL = "<"
static final String CMD_LABEL = ">"
static final String CMD_PREVIOUS = "%"
static final String CMD_REDIRECT = "@"
static final String CMD_REPLY = "-"
static final String CMD_TRIGGER = "+"
static Random rand = new Random()
static final double RS_VERSION = 2.0

Detailed Description

A RiveScript interpreter written in Java.

SYNOPSIS

import com.rivescript.RiveScript;

// Create a new interpreter
RiveScript rs = new RiveScript();

// Load a directory full of replies in *.rive files
rs.loadDirectory("./replies");

// Sort replies
rs.sortReplies();

// Get a reply for the user
String reply = rs.reply("user", "Hello bot!");

Definition at line 68 of file RiveScript.java.


Constructor & Destructor Documentation

Create a new RiveScript interpreter object, specifying the debug mode.

Parameters:
debugEnable debug mode (a *lot* of stuff is printed to the terminal)

Definition at line 140 of file RiveScript.java.

Create a new RiveScript interpreter object.

Definition at line 150 of file RiveScript.java.


Member Function Documentation

void com.rosalfred.core.ia.rivescript.RiveScript.cry ( String  line) [inline, private]

Print a line of warning text to the terminal.

Parameters:
lineThe line of warning text.

Definition at line 2284 of file RiveScript.java.

void com.rosalfred.core.ia.rivescript.RiveScript.cry ( String  text,
String  file,
int  line 
) [inline, private]

Print a line of warning text including a file name and line number.

Parameters:
textThe warning text.
fileThe file name.
lineThe line number.

Definition at line 2295 of file RiveScript.java.

DEVELOPER: Dump the trigger sort buffers to the terminal.

Definition at line 2179 of file RiveScript.java.

DEVELOPER: Dump the entire topic/trigger/reply structure to the terminal.

Definition at line 2196 of file RiveScript.java.

Return the text of the last error message given.

Definition at line 161 of file RiveScript.java.

boolean com.rosalfred.core.ia.rivescript.RiveScript.error ( final String  message) [inline, protected]

Set the error message.

Parameters:
messageThe new error message to set.

Definition at line 170 of file RiveScript.java.

String com.rosalfred.core.ia.rivescript.RiveScript.formatMessage ( String  message) [inline, private]

Format the user's message to begin reply matching. Lowercases it, runs substitutions, and neutralizes what's left.

Parameters:
messageThe input message to format.

Definition at line 2157 of file RiveScript.java.

Definition at line 585 of file RiveScript.java.

List<File> com.rosalfred.core.ia.rivescript.RiveScript.getFiles ( final File  directory,
final String  type 
) [inline, protected]

Definition at line 221 of file RiveScript.java.

HashMap<String, ObjectHandler<BotReply> > com.rosalfred.core.ia.rivescript.RiveScript.getHandlers ( ) [inline, protected]

Definition at line 175 of file RiveScript.java.

Get a list of all the user IDs the bot knows about.

Definition at line 580 of file RiveScript.java.

String com.rosalfred.core.ia.rivescript.RiveScript.getUservar ( String  user,
String  name 
) [inline]

Retrieve a single variable from a user's profile.

Returns null if the user doesn't exist. Returns the string "undefined" if the variable doesn't exist.

Parameters:
userThe user ID to get data from.
nameThe name of the variable to get.

Definition at line 613 of file RiveScript.java.

Definition at line 569 of file RiveScript.java.

HashMap<String, String> com.rosalfred.core.ia.rivescript.RiveScript.getUservars ( String  user) [inline]

Retrieve a listing of all the uservars for a user as a HashMap. Returns null if the user doesn't exist.

Parameters:
userThe user ID to get the vars for.

Definition at line 595 of file RiveScript.java.

boolean com.rosalfred.core.ia.rivescript.RiveScript.loadDirectory ( final String  path,
final String[]  exts 
) [inline]

Load a directory full of RiveScript documents, specifying a custom list of valid file extensions.

Parameters:
pathThe path to the directory containing RiveScript documents.
extsA string array containing file extensions to look for.

Definition at line 190 of file RiveScript.java.

boolean com.rosalfred.core.ia.rivescript.RiveScript.loadDirectory ( final String  path) [inline]

Load a directory full of RiveScript documents (.rive files).

Parameters:
pathThe path to the directory containing RiveScript documents.

Definition at line 254 of file RiveScript.java.

String [] com.rosalfred.core.ia.rivescript.RiveScript.loadFile ( String  file,
File  fh 
) throws IOException [inline, private]
Parameters:
file
fh
Returns:
Exceptions:
IOException

Definition at line 349 of file RiveScript.java.

Load a single RiveScript document.

Parameters:
filePath to a RiveScript document.

Definition at line 301 of file RiveScript.java.

boolean com.rosalfred.core.ia.rivescript.RiveScript.loadFileRive ( final String  file) [inline]

Load a single RiveScript document.

Parameters:
filePath to a RiveScript document.

Definition at line 264 of file RiveScript.java.

boolean com.rosalfred.core.ia.rivescript.RiveScript.parse ( String  filename,
String[]  code 
) [inline, private]

Parse RiveScript code and load it into internal memory.

Parameters:
filenameA file name to associate with this code (for error reporting)
codeA string array of all the code to parse.

Definition at line 632 of file RiveScript.java.

String com.rosalfred.core.ia.rivescript.RiveScript.processTags ( String  user,
Client  profile,
String  message,
String  reply,
ArrayList< String >  vstars,
ArrayList< String >  vbotstars,
int  step 
) [inline, private]

Definition at line 1752 of file RiveScript.java.

BotReply com.rosalfred.core.ia.rivescript.RiveScript.processTags ( String  user,
Client  profile,
String  message,
BotReply  botReply,
ArrayList< String >  vstars,
ArrayList< String >  vbotstars,
int  step 
) [inline, private]

Process reply tags.

Parameters:
userThe name of the end user.
profileThe RiveScript client object holding the user's profile
messageThe message sent by the user.
replyThe bot's original reply including tags.
starsThe vector of wildcards the user's message matched.
botstarsThe vector of wildcards in any Previous.
stepThe current recursion depth limit.

Definition at line 1774 of file RiveScript.java.

BotReply com.rosalfred.core.ia.rivescript.RiveScript.reply ( String  username,
String  message 
) [inline]

Get a reply from the RiveScript interpreter.

Parameters:
usernameA unique user ID for the user chatting with the bot.
messageThe user's message to the bot.

Definition at line 1102 of file RiveScript.java.

BotReply com.rosalfred.core.ia.rivescript.RiveScript.reply ( String  user,
String  message,
boolean  begin,
int  step 
) [inline, private]

Internal method for getting a reply.

Parameters:
userThe username of the calling user.
messageThe (formatted!) message sent by the user.
beginWhether the context is that we're in the BEGIN statement or not.
stepThe recursion depth that we're at so far.

Definition at line 1156 of file RiveScript.java.

void com.rosalfred.core.ia.rivescript.RiveScript.say ( String  line) [inline, protected]

Print a line of debug text to the terminal.

Parameters:
lineThe line of text to print.

Definition at line 2273 of file RiveScript.java.

boolean com.rosalfred.core.ia.rivescript.RiveScript.setGlobal ( String  name,
String  value 
) [inline]

Set a global variable for the interpreter (equivalent to ! global). Set the value to null to delete the variable.

There are two special globals that require certain data types:

debug is boolean-like and its value must be a string value containing "true", "yes", "1", "false", "no" or "0".

depth is integer-like and its value must be a quoted integer like "50". The "depth" variable controls how many levels deep RiveScript will go when following reply redirections.

Returns true on success, false on error.

Parameters:
nameThe variable name.
valueThe variable's value.

Definition at line 430 of file RiveScript.java.

void com.rosalfred.core.ia.rivescript.RiveScript.setHandler ( String  name,
ObjectHandler< BotReply handler 
) [inline]

Add a handler for a programming language to be used with RiveScript object calls.

Parameters:
nameThe name of the programming language.
handlerAn instance of a class that implements an ObjectHandler.

Definition at line 408 of file RiveScript.java.

boolean com.rosalfred.core.ia.rivescript.RiveScript.setPersonSubstitution ( String  pattern,
String  output 
) [inline]

Set a person substitution pattern (equivalent to ! person). Person substitutions swap first- and second-person pronouns, so the bot can safely echo the user without sounding too mechanical.

A null value for the output will delete the substitution.

Parameters:
patternThe pattern to match in the message.
outputThe text to replace it with (must be lowercase, no special characters).

Definition at line 524 of file RiveScript.java.

boolean com.rosalfred.core.ia.rivescript.RiveScript.setSubstitution ( String  pattern,
String  output 
) [inline]

Set a substitution pattern (equivalent to ! sub). The user's input (and the bot's reply, in Previous) get substituted using these rules.

A null value for the output will delete the substitution.

Parameters:
patternThe pattern to match in the message.
outputThe text to replace it with (must be lowercase, no special characters).

Definition at line 503 of file RiveScript.java.

boolean com.rosalfred.core.ia.rivescript.RiveScript.setUservar ( String  user,
String  name,
String  value 
) [inline]

Set a variable for one of the bot's users. A null value will delete a variable.

Parameters:
userThe user's ID.
nameThe name of the variable to set.
valueThe value to set.

Definition at line 543 of file RiveScript.java.

boolean com.rosalfred.core.ia.rivescript.RiveScript.setUservars ( String  user,
HashMap< String, String >  data 
) [inline]

Set -all- user vars for a user. This will replace the internal hash for the user. So your hash should at least contain a key/value pair for the user's current "topic". This could be useful if you used getUservars to store their entire profile somewhere and want to restore it later.

Parameters:
userThe user's ID.
dataThe full hash of the user's data.

Definition at line 563 of file RiveScript.java.

void com.rosalfred.core.ia.rivescript.RiveScript.setUservars ( ClientManager  clients) [inline]

Definition at line 573 of file RiveScript.java.

boolean com.rosalfred.core.ia.rivescript.RiveScript.setVariable ( String  name,
String  value 
) [inline]

Set a bot variable for the interpreter (equivalent to ! var). A bot variable is data about the chatbot, like its name or favorite color.

A null value will delete the variable.

Parameters:
nameThe variable name.
valueThe variable's value.

Definition at line 483 of file RiveScript.java.

After loading replies into memory, call this method to (re)initialize internal sort buffers. This is necessary for accurate trigger matching.

Definition at line 1079 of file RiveScript.java.

boolean com.rosalfred.core.ia.rivescript.RiveScript.stream ( String  code) [inline]

Stream some RiveScript code directly into the interpreter (as a single string containing newlines in it).

Parameters:
codeA string containing all the RiveScript code.

Definition at line 379 of file RiveScript.java.

boolean com.rosalfred.core.ia.rivescript.RiveScript.stream ( String[]  code) [inline]

Stream some RiveScript code directly into the interpreter (as a string array, one line per item).

Parameters:
codeA string array containing all the lines of code.

Definition at line 393 of file RiveScript.java.

String com.rosalfred.core.ia.rivescript.RiveScript.stringTransform ( String  format,
String  text 
) [inline, private]

Reformats a string in a certain way: formal, uppercase, lowercase, sentence.

Parameters:
formatThe format you want the string in.
textThe text to format.

Definition at line 2113 of file RiveScript.java.

void com.rosalfred.core.ia.rivescript.RiveScript.trace ( IOException  e) [inline, private]

Print a stack trace to the terminal when debug mode is on.

Parameters:
eThe IOException object.

Definition at line 2304 of file RiveScript.java.

String com.rosalfred.core.ia.rivescript.RiveScript.triggerRegexp ( String  user,
Client  profile,
String  trigger 
) [inline, private]

Formats a trigger for the regular expression engine.

Parameters:
userThe user ID of the caller.
triggerThe raw trigger text.

Definition at line 1611 of file RiveScript.java.


Member Data Documentation

HashMap<String, Vector<String> > com.rosalfred.core.ia.rivescript.RiveScript.arrays [private]
Initial value:
            new HashMap<String, Vector<String>>()

Definition at line 117 of file RiveScript.java.

ClientManager com.rosalfred.core.ia.rivescript.RiveScript.clients = new ClientManager() [private]

Definition at line 102 of file RiveScript.java.

final String com.rosalfred.core.ia.rivescript.RiveScript.CMD_CONDITION = "*" [static, private]

Definition at line 94 of file RiveScript.java.

final String com.rosalfred.core.ia.rivescript.RiveScript.CMD_CONTINUE = "^" [static, private]

Definition at line 92 of file RiveScript.java.

final String com.rosalfred.core.ia.rivescript.RiveScript.CMD_DEFINE = "!" [static, private]

Definition at line 88 of file RiveScript.java.

final String com.rosalfred.core.ia.rivescript.RiveScript.CMD_ENDLABEL = "<" [static, private]

Definition at line 96 of file RiveScript.java.

final String com.rosalfred.core.ia.rivescript.RiveScript.CMD_LABEL = ">" [static, private]

Definition at line 95 of file RiveScript.java.

final String com.rosalfred.core.ia.rivescript.RiveScript.CMD_PREVIOUS = "%" [static, private]

Definition at line 90 of file RiveScript.java.

final String com.rosalfred.core.ia.rivescript.RiveScript.CMD_REDIRECT = "@" [static, private]

Definition at line 93 of file RiveScript.java.

final String com.rosalfred.core.ia.rivescript.RiveScript.CMD_REPLY = "-" [static, private]

Definition at line 91 of file RiveScript.java.

final String com.rosalfred.core.ia.rivescript.RiveScript.CMD_TRIGGER = "+" [static, private]

Definition at line 89 of file RiveScript.java.

Definition at line 129 of file RiveScript.java.

Definition at line 75 of file RiveScript.java.

Definition at line 76 of file RiveScript.java.

Definition at line 77 of file RiveScript.java.

HashMap<String, String> com.rosalfred.core.ia.rivescript.RiveScript.globals [private]
Initial value:
            new HashMap<String, String>()

Definition at line 113 of file RiveScript.java.

HashMap<String, ObjectHandler<BotReply> > com.rosalfred.core.ia.rivescript.RiveScript.handlers [private]
Initial value:
            new HashMap<String, ObjectHandler<BotReply>>()

Definition at line 105 of file RiveScript.java.

HashMap<String, String> com.rosalfred.core.ia.rivescript.RiveScript.objects [protected]
Initial value:
            new HashMap<String, String>()

Definition at line 107 of file RiveScript.java.

HashMap<String, String> com.rosalfred.core.ia.rivescript.RiveScript.person [private]
Initial value:
            new HashMap<String, String>()

Definition at line 123 of file RiveScript.java.

Initial value:
            null

Definition at line 125 of file RiveScript.java.

Random com.rosalfred.core.ia.rivescript.RiveScript.rand = new Random() [static, private]

Definition at line 78 of file RiveScript.java.

final double com.rosalfred.core.ia.rivescript.RiveScript.RS_VERSION = 2.0 [static, private]

Definition at line 87 of file RiveScript.java.

HashMap<String, String> com.rosalfred.core.ia.rivescript.RiveScript.subs [private]
Initial value:
            new HashMap<String, String>()

Definition at line 119 of file RiveScript.java.

Initial value:
            null

Definition at line 121 of file RiveScript.java.

TopicManager com.rosalfred.core.ia.rivescript.RiveScript.topics = new TopicManager() [private]

Definition at line 99 of file RiveScript.java.

Definition at line 72 of file RiveScript.java.

Definition at line 71 of file RiveScript.java.

Definition at line 70 of file RiveScript.java.

HashMap<String, String> com.rosalfred.core.ia.rivescript.RiveScript.vars [private]
Initial value:
            new HashMap<String, String>()

Definition at line 115 of file RiveScript.java.

The version of the RiveScript Java library.

Definition at line 84 of file RiveScript.java.


The documentation for this class was generated from the following file:


alfred_bot
Author(s): Mickael Gaillard , Erwan Le Huitouze
autogenerated on Tue Jun 14 2016 01:34:50