Elizabot
elizabot.js v.1.1 - ELIZA JS library (N.Landsteiner 2005) Eliza is a mock Rogerian psychotherapist. Original program by Joseph Weizenbaum in MAD-SLIP for "Project MAC" at MIT. cf: Weizenbaum, Joseph "ELIZA - A Computer Program For the Study of Natural Language Communication Between Man and Machine" in: Communications of the ACM; Volume 9 , Issue 1 (January 1966): p 36-45. JavaScript implementation by Norbert Landsteiner 2005; http://www.masserk.at
synopsis:
new ElizaBot( <random-choice-disable-flag> )
ElizaBot.prototype.transform( <inputstring> )
ElizaBot.prototype.getInitial()
ElizaBot.prototype.getFinal()
ElizaBot.prototype.reset()
usage: var eliza = new ElizaBot(); var initial = eliza.getInitial(); var reply = eliza.transform(inputstring); if (eliza.quit) { // last user input was a quit phrase }
// method `transform()' returns a final phrase in case of a quit phrase
// but you can also get a final phrase with:
var final = eliza.getFinal();
// other methods: reset memory and internal state
eliza.reset();
// to set the internal memory size override property `memSize':
eliza.memSize = 100; // (default: 20)
// to reproduce the example conversation given by J. Weizenbaum
// initialize with the optional random-choice-disable flag
var originalEliza = new ElizaBot(true);
ElizaBot' is also a general chatbot engine that can be supplied with any rule set.
(for required data structures cf. "elizadata.js" and/or see the documentation.)
data is parsed and transformed for internal use at the creation time of the
first instance of the
ElizaBot' constructor.
vers 1.1: lambda functions in RegExps are currently a problem with too many browsers. changed code to work around.
- Elizabot
- ~ElizaBot
- new ElizaBot(datapath, noRandomFlag)
- ._dataParsed :
Boolean
- .reset()
- ._init()
- ._sortKeywords(a, b) ⇒
Number
- .transform(text) ⇒
String
- ._execRule(k) ⇒
String
- ._postTransform(s) ⇒
String
- ._getRuleIndexByKey(key) ⇒
Number
- ._memSave(t)
- ._memGet() ⇒
String
- .getFinal() ⇒
String
- .getInitial() ⇒
String
Elizabot~ElizaBot
Kind: inner class of Elizabot
- ~ElizaBot
- new ElizaBot(datapath, noRandomFlag)
- ._dataParsed :
Boolean
- .reset()
- ._init()
- ._sortKeywords(a, b) ⇒
Number
- .transform(text) ⇒
String
- ._execRule(k) ⇒
String
- ._postTransform(s) ⇒
String
- ._getRuleIndexByKey(key) ⇒
Number
- ._memSave(t)
- ._memGet() ⇒
String
- .getFinal() ⇒
String
- .getInitial() ⇒
String
new ElizaBot(datapath, noRandomFlag)
The logic class behind the Eliza module
Param | Type | Description |
---|---|---|
datapath | String |
The path to Elizabot's data |
noRandomFlag | boolean |
True if you don't want to be random. False if not. |
elizaBot._dataParsed : Boolean
Whether the data files have been parsed yet.
Kind: instance property of ElizaBot
elizaBot.reset()
Reset Elizabot, making her forget what she's already said.
Kind: instance method of ElizaBot
elizaBot._init()
Initialize the bot
Kind: instance method of ElizaBot
elizaBot._sortKeywords(a, b) ⇒ Number
Sort keywords by rank or original index (tiebreaker)
Kind: instance method of ElizaBot
Returns: Number
- As per sorting algorithm
Param | Type | Description |
---|---|---|
a | Object |
Keyword 1 |
b | Object |
Keyword 2 |
elizaBot.transform(text) ⇒ String
This would appear to be the main function that takes in a sentence and comes up with a reply
Kind: instance method of ElizaBot
Returns: String
- The reply from Eliza
Param | Type | Description |
---|---|---|
text | String |
The input |
elizaBot._execRule(k) ⇒ String
Execute a rule
Kind: instance method of ElizaBot
Returns: String
- The reply for that rule
Param | Type | Description |
---|---|---|
k | Number |
The rule to execute |
elizaBot._postTransform(s) ⇒ String
Clean up after transforming.
Kind: instance method of ElizaBot
Returns: String
- s but more transformy
Param | Type | Description |
---|---|---|
s | String |
I think the reply stream? |
elizaBot._getRuleIndexByKey(key) ⇒ Number
Find the index of a rule from the key. Converts from object lookup to array lookup.
Kind: instance method of ElizaBot
Returns: Number
- The index
Param | Type | Description |
---|---|---|
key | String |
the key |
elizaBot._memSave(t)
Save into memory
Kind: instance method of ElizaBot
Param | Type | Description |
---|---|---|
t | String |
The item to save |
elizaBot._memGet() ⇒ String
Get from memory
Kind: instance method of ElizaBot
Returns: String
- the item
elizaBot.getFinal() ⇒ String
Get a random signoff used when ending a conversation
Kind: instance method of ElizaBot
Returns: String
- The signoff
elizaBot.getInitial() ⇒ String
Get a greeting used when starting a conversation
Kind: instance method of ElizaBot
Returns: String
- The greeting