Organized, thoughtful, / but I feel I must fail you. / Your handwriting sucks.
3
   
Award
Favorite
Favorited
Unfavorite
Download
"var elizaInitials = [
"How do you do. Please tell me your problem.",
// additions (not original)
"Please tell me what's been bothering you.",
"Is something troubling you ?"
];
var elizaFinals = [
"Goodbye. It was nice talking to you.",
// additions (not original)
"Goodbye. This was really a nice talk.",
"Goodbye. I'm looking forward to our next session.",
"This was a good session, wasn't it -- but time is over now. Goodbye.",
"Maybe we could discuss this moreover in our next session ? Goodbye."
];
var elizaQuits = [
"HUIOHFODhjF" //przecież rozmowa się nie kończy xD
/*"bye",
"goodbye",
"done",
"exit",
"quit"*/
];
var elizaPres = [
"dont", "don't",
"cant", "can't",
"wont", "won't",
"recollect", "remember",
"recall", "remember",
"dreamt", "dreamed",
"dreams", "dream",
"maybe", "perhaps",
"certainly", "yes",
"machine", "computer",
"machines", "computer",
"computers", "computer",
"were", "was",
"you're", "you are",
"i'm", "i am",
"same", "alike",
"identical", "alike",
"equivalent", "alike"
];
var elizaPosts = [
"am", "are",
"your", "my",
"me", "you",
"myself", "yourself",
"yourself", "myself",
"i", "you",
"you", "I",
"my", "your",
"i'm", "you are"
];
var elizaSynons = {
"be": ["am", "is", "are", "was"],
"belief": ["feel", "think", "believe", "wish"],
"cannot": ["can't"],
"desire": ["want", "need"],
"everyone": ["everybody", "nobody", "noone"],
"family": ["mother", "mom", "father", "dad", "sister", "brother", "wife", "children", "child"],
"happy": ["elated", "glad", "better"],
"sad": ["unhappy", "depressed", "sick"]
};
// regexp/replacement pairs to be performed as final cleanings
// here: cleanings for multiple bots talking to each other
var elizaPostTransforms = [
/ old old/g, " old",
/\bthey were( not)? me\b/g, "it was$1 me",
/\bthey are( not)? me\b/g, "it is$1 me",
/Are they( always)? me\b/, "it is$1 me",
/\bthat your( own)? (\w+)( now)? \?/, "that you have your$1 $2 ?",
/\bI to have (\w+)/, "I have $1",
/Earlier you said your( own)? (\w+)( now)?\./, "Earlier you talked about your $2."
];
function ElizaBot(noRandomFlag) {
this.noRandom= (noRandomFlag)? true:false;
this.capitalizeFirstLetter=true;
this.debug=false;
this.memSize=20;
this.version="1.1 (original)";
if (!this._dataParsed) this._init();
this.reset();
}
module.exports = ElizaBot;
ElizaBot.prototype.reset = function() {
this.quit=false;
this.mem=[];
this.lastchoice=[];
for (var k=0; k<elizaKeywords.length; k++) {
this.lastchoice[k]=[];
var rules=elizaKeywords[k][2];
for (var i=0; i<rules.length; i++) this.lastchoice[k]=-1;
}
}
ElizaBot.prototype._dataParsed = false;
ElizaBot.prototype._init = function() {
// install ref to object
//ElizaBot.prototype.global=self;
//var m=ElizaBot.prototype.global;
// parse data and convert it from canonical form to internal use
// prodoce synonym list
var synPatterns={};
if ((elizaSynons) && (typeof elizaSynons == 'object')) {
for (var i in elizaSynons) synPatterns='('+i+'|'+elizaSynons.join('|')+')';
}
// check for keywords or install empty structure to prevent any errors
if ((!elizaKeywords) || (typeof elizaKeywords.length == 'undefined')) {
elizaKeywords=[['###',0,[['###',[]]]]];
}
// 1st convert rules to regexps
// expand synonyms and insert asterisk expressions for backtracking
var sre=/@(\S+)/;
var are=/(\S)\s*\*\s*(\S)/;
var are1=/^\s*\*\s*(\S)/;
var are2=/(\S)\s*\*\s*$/;
var are3=/^\s*\*\s*$/;
var wsre=/\s+/g;
for (var k=0; k<elizaKeywords.length; k++) {
var rules=elizaKeywords[k][2];
elizaKeywords[k][3]=k; // save original index for sorting
for (var i=0; i<rules.length; i++) {
var r=rules;
// check mem flag and store it as decomp's element 2
if (r[0].charAt(0)=='$') {
var ofs=1;
while (r[0].charAt[ofs]==' ') ofs++;
r[0]=r[0].substring(ofs);
r[2]=true;
}
else {
r[2]=false;
}
// expand synonyms (v.1.1: work around lambda function)
var m=sre.exec(r[0]);
while (m) {
var sp=(synPatterns[m[1]])? synPatterns[m[1]]:m[1];
r[0]=r[0].substring(0,m.index)+sp+r[0].substring(m.index+m[0].length);
m=sre.exec(r[0]);
}
// expand asterisk expressions (v.1.1: work around lambda function)
if (are3.test(r[0])) {
r[0]='\\s*(.*)\\s*';
}
else {
m=are.exec(r[0]);
if (m) {
var lp='';
var rp=r[0];
while (m) {
lp+=rp.substring(0,m.index+1);
if (m[1]!=')') lp+='\\b';
lp+='\\s*(.*)\\s*';
if ((m[2]!='(') && (m[2]!='\\')) lp+='\\b';
lp+=m[2];
rp=rp.substring(m.index+m[0].length);
m=are.exec(rp);
}
r[0]=lp+rp;
}
m=are1.exec(r[0]);
if (m) {
var lp='\\s*(.*)\\s*';
if ((m[1]!=')') && (m[1]!='\\')) lp+='\\b';
r[0]=lp+r[0].substring(m.index-1+m[0].length);
}
m=are2.exec(r[0]);
if (m) {
var lp=r[0].substring(0,m.index+1);
if (m[1]!='(') lp+='\\b';
r[0]=lp+'\\s*(.*)\\s*';
}
}
// expand white space
r[0]=r[0].replace(wsre, '\\s+');
wsre.lastIndex=0;
}
}
// now sort keywords by rank (highest first)
elizaKeywords.sort(this._sortKeywords);
// and compose regexps and refs for pres and posts
ElizaBot.prototype.pres={};
ElizaBot.prototype.posts={};
if ((elizaPres) && (elizaPres.length)) {
var a=new Array();
for (var i=0; i<elizaPres.length; i+=2) {
a.push(elizaPres);
ElizaBot.prototype.pres[elizaPres[i]]=elizaPres[i+1];
}
ElizaBot.prototype.preExp = new RegExp('\\b('+a.join('|')+')\\b');
}
else {
// default (should not match)
ElizaBot.prototype.preExp = /####/;
ElizaBot.prototype.pres['####']='####';
}
if ((elizaPosts) && (elizaPosts.length)) {
var a=new Array();
for (var i=0; i<elizaPosts.length; i+=2) {
a.push(elizaPosts);
ElizaBot.prototype.posts[elizaPosts[i]]=elizaPosts[i+1];
}
ElizaBot.prototype.postExp = new RegExp('\\b('+a.join('|')+')\\b');
}
else {
// default (should not match)
ElizaBot.prototype.postExp = /####/;
ElizaBot.prototype.posts['####']='####';
}
// check for elizaQuits and install default if missing
if ((!elizaQuits) || (typeof elizaQuits.length == 'undefined')) {
elizaQuits=[];
}
// done
ElizaBot.prototype._dataParsed=true;
}
"
1 Comments
Krystic 4 Jul, 2021 @ 5:34am 
:steamthumbsup: