added $ saved statements

master
Michael Murtaugh 6 years ago
parent d1d5eca12e
commit 371be47195

@ -0,0 +1,112 @@
Free Art License 1.3 (FAL 1.3)
Preamble
The Free Art License grants the right to freely copy, distribute, and transform creative works without infringing the authors rights.
The Free Art License recognizes and protects these rights. Their implementation has been reformulated in order to allow everyone to use creations of the human mind in a creative manner, regardless of their types and ways of expression.
While the publics access to creations of the human mind usually is restricted by the implementation of copyright law, it is favoured by the Free Art License. This license intends to allow the use of a works resources; to establish new conditions for creating in order to increase creation opportunities. The Free Art License grants the right to use a work, and acknowledges the right holders and the users rights and responsibility.
The invention and development of digital technologies, Internet and Free Software have changed creation methods: creations of the human mind can obviously be distributed, exchanged, and transformed. They allow to produce common works to which everyone can contribute to the benefit of all.
The main rationale for this Free Art License is to promote and protect these creations of the human mind according to the principles of copyleft: freedom to use, copy, distribute, transform, and prohibition of exclusive appropriation.
Definitions
« work » either means the initial work, the subsequent works or the common work as defined hereafter:
« common work » means a work composed of the initial work and all subsequent contributions to it (originals and copies). The initial author is the one who, by choosing this license, defines the conditions under which contributions are made.
« Initial work » means the work created by the initiator of the common work (as defined above), the copies of which can be modified by whoever wants to
« Subsequent works » means the contributions made by authors who participate in the evolution of the common work by exercising the rights to reproduce, distribute, and modify that are granted by the license.
« Originals » (sources or resources of the work) means all copies of either the initial work or any subsequent work mentioning a date and used by their author(s) as references for any subsequent updates, interpretations, copies or reproductions.
« Copy » means any reproduction of an original as defined by this license.
1. OBJECT
The aim of this license is to define the conditions under which one can use this work freely.
2. SCOPE
This work is subject to copyright law. Through this license its author specifies the extent to which you can copy, distribute, and modify it.
2.1 FREEDOM TO COPY (OR TO MAKE REPRODUCTIONS)
You have the right to copy this work for yourself, your friends or any other person, whatever the technique used.
2.2 FREEDOM TO DISTRIBUTE, TO PERFORM IN PUBLIC
You have the right to distribute copies of this work; whether modified or not, whatever the medium and the place, with or without any charge, provided that you:
attach this license without any modification to the copies of this work or indicate precisely where the license can be found,
specify to the recipient the names of the author(s) of the originals, including yours if you have modified the work,
specify to the recipient where to access the originals (either initial or subsequent).
The authors of the originals may, if they wish to, give you the right to distribute the originals under the same conditions as the copies.
2.3 FREEDOM TO MODIFY
You have the right to modify copies of the originals (whether initial or subsequent) provided you comply with the following conditions:
all conditions in article 2.2 above, if you distribute modified copies;
indicate that the work has been modified and, if it is possible, what kind of modifications have been made;
distribute the subsequent work under the same license or any compatible license.
The author(s) of the original work may give you the right to modify it under the same conditions as the copies.
3. RELATED RIGHTS
Activities giving rise to authors rights and related rights shall not challenge the rights granted by this license.
For example, this is the reason why performances must be subject to the same license or a compatible license. Similarly, integrating the work in a database, a compilation or an anthology shall not prevent anyone from using the work under the same conditions as those defined in this license.
4. INCORPORATION OF THE WORK
Incorporating this work into a larger work that is not subject to the Free Art License shall not challenge the rights granted by this license.
If the work can no longer be accessed apart from the larger work in which it is incorporated, then incorporation shall only be allowed under the condition that the larger work is subject either to the Free Art License or a compatible license.
5. COMPATIBILITY
A license is compatible with the Free Art License provided:
it gives the right to copy, distribute, and modify copies of the work including for commercial purposes and without any other restrictions than those required by the respect of the other compatibility criteria;
it ensures proper attribution of the work to its authors and access to previous versions of the work when possible;
it recognizes the Free Art License as compatible (reciprocity);
it requires that changes made to the work be subject to the same license or to a license which also meets these compatibility criteria.
6. YOUR INTELLECTUAL RIGHTS
This license does not aim at denying your authors rights in your contribution or any related right. By choosing to contribute to the development of this common work, you only agree to grant others the same rights with regard to your contribution as those you were granted by this license. Conferring these rights does not mean you have to give up your intellectual rights.
7. YOUR RESPONSIBILITIES
The freedom to use the work as defined by the Free Art License (right to copy, distribute, modify) implies that everyone is responsible for their own actions.
8. DURATION OF THE LICENSE
This license takes effect as of your acceptance of its terms. The act of copying, distributing, or modifying the work constitutes a tacit agreement. This license will remain in effect for as long as the copyright which is attached to the work. If you do not respect the terms of this license, you automatically lose the rights that it confers.
If the legal status or legislation to which you are subject makes it impossible for you to respect the terms of this license, you may not make use of the rights which it confers.
9. VARIOUS VERSIONS OF THE LICENSE
This license may undergo periodic modifications to incorporate improvements by its authors (instigators of the « Copyleft Attitude » movement) by way of new, numbered versions.
You will always have the choice of accepting the terms contained in the version under which the copy of the work was distributed to you, or alternatively, to use the provisions of one of the subsequent versions.
10. SUB-LICENSING
Sub-licenses are not authorized by this license. Any person wishing to make use of the rights that it confers will be directly bound to the authors of the common work.
11. LEGAL FRAMEWORK
This license is written with respect to both French law and the Berne Convention for the Protection of Literary and Artistic Works.
USER GUIDE
How to use the Free Art License?
To benefit from the Free Art License, you only need to mention the following elements on your work:
[Name of the author, title, date of the work. When applicable, names of authors of the common work and, if possible, where to find the originals].
Copyleft: This is a free work, you can copy, distribute, and modify it under the terms of the Free Art License http://artlibre.org/licence/lal/en/
Why to use the Free Art License?
1.To give the greatest number of people access to your work.
2.To allow it to be distributed freely.
3.To allow it to evolve by allowing its copy, distribution, and transformation by others.
4.So that you benefit from the resources of a work when it is under the Free Art License: to be able to copy, distribute or transform it freely.
5.But also, because the Free Art License offers a legal framework to disallow any misappropriation. It is forbidden to take hold of your work and bypass the creative process for ones exclusive possession.
When to use the Free Art License?
Any time you want to benefit and make others benefit from the right to copy, distribute and transform creative works without any exclusive appropriation, you should use the Free Art License. You can for example use it for scientific, artistic or educational projects.
What kinds of works can be subject to the Free Art License?
The Free Art License can be applied to digital as well as physical works.
You can choose to apply the Free Art License on any text, picture, sound, gesture, or whatever sort of stuff on which you have sufficient authors rights.
Historical background of this license:
It is the result of observing, using and creating digital technologies, free software, the Internet and art. It arose from the « Copyleft Attitude » meetings which took place in Paris in 2000. For the first time, these meetings brought together members of the Free Software community, artists, and members of the art world. The goal was to adapt the principles of Copyleft and free software to all sorts of creations. http://www.artlibre.org
Copyleft Attitude, 2007.
You can make reproductions and distribute this license verbatim (without any changes).

File diff suppressed because one or more lines are too long

@ -0,0 +1,788 @@
{
"quit": [],
"synon": [
"belief feel think believe wish",
"family mother mom father dad sister brother wife children child",
"desire want need",
"sad unhappy depressed sick",
"happy elated glad better",
"cannot can't",
"everyone everybody nobody noone",
"be am is are was"
],
"final": "Goodbye. Thank you for talking to me.",
"pre": [
"dont don't",
"cant can't",
"wont won't",
"recollect remember",
"dreamt dreamed",
"dreams dream",
"maybe perhaps",
"how what",
"when what",
"certainly yes",
"machine computer",
"computers computer",
"were was",
"you're you are",
"i'm i am",
"same alike"
],
"post": [
"am are",
"your my",
"me you",
"myself yourself",
"yourself myself",
"i you",
"you I",
"my your",
"i'm you are"
],
"initial": "How do you do. Please tell me your problem.",
"keywords": [
{
"weight": 0,
"rules": [
{
"decomp": "*",
"reasmb": [
"I'm not sure I understand you fully.",
"Please go on.",
"What does that suggest to you ?",
"Do you feel strongly about discussing such things ?"
]
}
],
"token": "xnone"
},
{
"weight": 0,
"rules": [
{
"decomp": "*",
"reasmb": [
"Please don't apologise.",
"Apologies are not necessary.",
"I've told you that apologies are not required."
]
}
],
"token": "sorry"
},
{
"weight": 0,
"rules": [
{
"decomp": "*",
"reasmb": [
"goto sorry"
]
}
],
"token": "apologise"
},
{
"weight": 5,
"rules": [
{
"decomp": "* i remember *",
"reasmb": [
"Do you often think of (2) ?",
"Does thinking of (2) bring anything else to mind ?",
"What else do you recollect ?",
"Why do you recollect (2) just now ?",
"What in the present situation reminds you of (2) ?",
"What is the connection between me and (2) ?"
]
},
{
"decomp": "* do you remember *",
"reasmb": [
"Did you think I would forget (2) ?",
"Why do you think I should recall (2) now ?",
"What about (2) ?",
"goto what",
"You mentioned (2) ?"
]
}
],
"token": "remember"
},
{
"weight": 3,
"rules": [
{
"decomp": "* if *",
"reasmb": [
"Do you think its likely that (2) ?",
"Do you wish that (2) ?",
"What do you know about (2) ?",
"Really, if (2) ?"
]
}
],
"token": "if"
},
{
"weight": 4,
"rules": [
{
"decomp": "* i dreamed *",
"reasmb": [
"Really, (2) ?",
"Have you ever fantasized (2) while you were awake ?",
"Have you ever dreamed (2) before ?",
"goto dream"
]
}
],
"token": "dreamed"
},
{
"weight": 3,
"rules": [
{
"decomp": "*",
"reasmb": [
"What does that dream suggest to you ?",
"Do you dream often ?",
"What persons appear in your dreams ?",
"Do you believe that dreams have something to do with your problems ?"
]
}
],
"token": "dream"
},
{
"weight": 0,
"rules": [
{
"decomp": "*",
"reasmb": [
"You don't seem quite certain.",
"Why the uncertain tone ?",
"Can't you be more positive ?",
"You aren't sure ?",
"Don't you know ?"
]
}
],
"token": "perhaps"
},
{
"weight": 15,
"rules": [
{
"decomp": "*",
"reasmb": [
"I am not interested in names.",
"I've told you before, I don't care about names -- please continue."
]
}
],
"token": "name"
},
{
"weight": 0,
"rules": [
{
"decomp": "*",
"reasmb": [
"goto xforeign",
"I told you before, I don't understand German."
]
}
],
"token": "deutsch"
},
{
"weight": 0,
"rules": [
{
"decomp": "*",
"reasmb": [
"goto xforeign",
"I told you before, I don't understand French."
]
}
],
"token": "francais"
},
{
"weight": 0,
"rules": [
{
"decomp": "*",
"reasmb": [
"goto xforeign",
"I told you before, I don't understand Italian."
]
}
],
"token": "italiano"
},
{
"weight": 0,
"rules": [
{
"decomp": "*",
"reasmb": [
"goto xforeign",
"I told you before, I don't understand Spanish."
]
}
],
"token": "espanol"
},
{
"weight": 0,
"rules": [
{
"decomp": "*",
"reasmb": [
"I speak only English."
]
}
],
"token": "xforeign"
},
{
"weight": 0,
"rules": [
{
"decomp": "*",
"reasmb": [
"How do you do. Please state your problem.",
"Hi. What seems to be your problem ?"
]
}
],
"token": "hello"
},
{
"weight": 50,
"rules": [
{
"decomp": "*",
"reasmb": [
"Do computers worry you ?",
"Why do you mention computers ?",
"What do you think machines have to do with your problem ?",
"Don't you think computers can help people ?",
"What about machines worrys you ?",
"What do you think about machines ?"
]
}
],
"token": "computer"
},
{
"weight": 0,
"rules": [
{
"decomp": "* am i *",
"reasmb": [
"Do you believe you are (2) ?",
"Would you want to be (2) ?",
"Do you wish I would tell you you are (2) ?",
"What would it mean if you were (2) ?",
"goto what"
]
},
{
"decomp": "*",
"reasmb": [
"Why do you say 'am' ?",
"I don't understand that."
]
}
],
"token": "am"
},
{
"weight": 0,
"rules": [
{
"decomp": "* are you *",
"reasmb": [
"Why are you interested in whether I am (2) or not ?",
"Would you prefer if I weren't (2) ?",
"Perhaps I am (2) in your fantasies.",
"Do you sometimes think I am (2) ?",
"goto what"
]
},
{
"decomp": "* are *",
"reasmb": [
"Did you think they might not be (2) ?",
"Would you like it if they were not (2) ?",
"What if they were not (2) ?",
"Possibly they are (2)."
]
}
],
"token": "are"
},
{
"weight": 0,
"rules": [
{
"decomp": "* your *",
"reasmb": [
"Why are you concerned over my (2) ?",
"What about your own (2) ?",
"Are you worried about someone else's (2) ?",
"Really, my (2) ?"
]
}
],
"token": "your"
},
{
"weight": 2,
"rules": [
{
"decomp": "* was i *",
"reasmb": [
"What if you were (2) ?",
"Do you think you were (2) ?",
"Were you (2) ?",
"What would it mean if you were (2) ?",
"What does (2) suggest to you ?",
"goto what"
]
},
{
"decomp": "* i was *",
"reasmb": [
"Were you really ?",
"Why do you tell me you were (2) now ?",
"Perhaps I already know you were (2)."
]
},
{
"decomp": "* was you *",
"reasmb": [
"Would you like to believe I was (2) ?",
"What suggests that I was (2) ?",
"What do you think ?",
"Perhaps I was (2).",
"What if I had been (2) ?"
]
}
],
"token": "was"
},
{
"weight": 0,
"rules": [
{
"decomp": "* i @desire *",
"reasmb": [
"What would it mean to you if you got (3) ?",
"Why do you want (3) ?",
"Suppose you got (3) soon ?",
"What if you never got (3) ?",
"What would getting (3) mean to you ?",
"What does wanting (3) have to do with this discussion ?"
]
},
{
"decomp": "* i am* @sad *",
"reasmb": [
"I am sorry to hear that you are (3).",
"Do you think that coming here will help you not to be (3) ?",
"I'm sure it's not pleasant to be (3).",
"Can you explain what made you (3) ?"
]
},
{
"decomp": "* i am* @happy *",
"reasmb": [
"How have I helped you to be (3) ?",
"Has your treatment made you (3) ?",
"What makes you (3) just now ?",
"Can you explan why you are suddenly (3) ?"
]
},
{
"decomp": "* i was *",
"reasmb": [
"goto was"
]
},
{
"decomp": "* i @belief * i *",
"reasmb": [
"Do you really think so ?",
"But you are not sure you (3).",
"Do you really doubt you (3) ?"
]
},
{
"decomp": "* i* @belief *you *",
"reasmb": [
"goto you"
]
},
{
"decomp": "* i am *",
"reasmb": [
"Is it because you are (2) that you came to me ?",
"How long have you been (2) ?",
"Do you believe it is normal to be (2) ?",
"Do you enjoy being (2) ?"
]
},
{
"decomp": "* i @cannot *",
"reasmb": [
"How do you think that you can't (3) ?",
"Have you tried ?",
"Perhaps you could (3) now.",
"Do you really want to be able to (3) ?"
]
},
{
"decomp": "* i don't *",
"reasmb": [
"Don't you really (2) ?",
"Why don't you (2) ?",
"Do you wish to be able to (2) ?",
"Does that trouble you ?"
]
},
{
"decomp": "* do i feel *",
"reasmb": [
"Tell me more about such feelings.",
"Do you often feel (2) ?",
"Do you enjoy feeling (2) ?",
"Of what does feeling (2) remind you ?"
]
},
{
"decomp": "* i * you *",
"reasmb": [
"Perhaps in your fantasies we (2) each other.",
"Do you wish to (2) me ?",
"You seem to need to (2) me.",
"Do you (2) anyone else ?"
]
},
{
"decomp": "*",
"reasmb": [
"You say (1) ?",
"Can you elaborate on that ?",
"Do you say (1) for some special reason ?",
"That's quite interesting."
]
}
],
"token": "i"
},
{
"weight": 0,
"rules": [
{
"decomp": "* you remind me of *",
"reasmb": [
"goto alike"
]
},
{
"decomp": "* you are *",
"reasmb": [
"What makes you think I am (2) ?",
"Does it please you to believe I am (2) ?",
"Do you sometimes wish you were (2) ?",
"Perhaps you would like to be (2)."
]
},
{
"decomp": "* you* me *",
"reasmb": [
"Why do you think I (2) you ?",
"You like to think I (2) you -- don't you ?",
"What makes you think I (2) you ?",
"Really, I (2) you ?",
"Do you wish to believe I (2) you ?",
"Suppose I did (2) you -- what would that mean ?",
"Does someone else believe I (2) you ?"
]
},
{
"decomp": "* you *",
"reasmb": [
"We were discussing you -- not me.",
"Oh, I (2) ?",
"You're not really talking about me -- are you ?",
"What are your feelings now ?"
]
}
],
"token": "you"
},
{
"weight": 0,
"rules": [
{
"decomp": "*",
"reasmb": [
"You seem to be quite positive.",
"You are sure.",
"I see.",
"I understand."
]
}
],
"token": "yes"
},
{
"weight": 0,
"rules": [
{
"decomp": "*",
"reasmb": [
"Are you saying no just to be negative?",
"You are being a bit negative.",
"Why not ?",
"Why 'no' ?"
]
}
],
"token": "no"
},
{
"weight": 2,
"rules": [
{
"decomp": "* my *",
"reasmb": [
"Lets discuss further why your (2).",
"Earlier you said your (2).",
"But your (2).",
"Does that have anything to do with the fact that your (2) ?"
],
"save": true
},
{
"decomp": "* my* @family *",
"reasmb": [
"Tell me more about your family.",
"Who else in your family (4) ?",
"Your (3) ?",
"What else comes to mind when you think of your (3) ?"
]
},
{
"decomp": "* my *",
"reasmb": [
"Your (2) ?",
"Why do you say your (2) ?",
"Does that suggest anything else which belongs to you ?",
"Is it important that your (2) ?"
]
}
],
"token": "my"
},
{
"weight": 0,
"rules": [
{
"decomp": "* can you *",
"reasmb": [
"You believe I can (2) don't you ?",
"goto what",
"You want me to be able to (2).",
"Perhaps you would like to be able to (2) yourself."
]
},
{
"decomp": "* can i *",
"reasmb": [
"Whether or not you can (2) depends on you more than me.",
"Do you want to be able to (2) ?",
"Perhaps you don't want to (2).",
"goto what"
]
}
],
"token": "can"
},
{
"weight": 0,
"rules": [
{
"decomp": "*",
"reasmb": [
"Why do you ask ?",
"Does that question interest you ?",
"What is it you really wanted to know ?",
"Are such questions much on your mind ?",
"What answer would please you most ?",
"What do you think ?",
"What comes to mind when you ask that ?",
"Have you asked such questions before ?",
"Have you asked anyone else ?"
]
}
],
"token": "what"
},
{
"weight": 0,
"rules": [
{
"decomp": "*",
"reasmb": [
"Is that the real reason ?",
"Don't any other reasons come to mind ?",
"Does that reason seem to explain anything else ?",
"What other reasons might there be ?"
]
}
],
"token": "because"
},
{
"weight": 0,
"rules": [
{
"decomp": "* why don't you *",
"reasmb": [
"Do you believe I don't (2) ?",
"Perhaps I will (2) in good time.",
"Should you (2) yourself ?",
"You want me to (2) ?",
"goto what"
]
},
{
"decomp": "* why can't i *",
"reasmb": [
"Do you think you should be able to (2) ?",
"Do you want to be able to (2) ?",
"Do you believe this will help you to (2) ?",
"Have you any idea why you can't (2) ?",
"goto what"
]
},
{
"decomp": "*",
"reasmb": [
"goto what"
]
}
],
"token": "why"
},
{
"weight": 2,
"rules": [
{
"decomp": "* @everyone *",
"reasmb": [
"Realy, (2) ?",
"Surely not (2).",
"Can you think of anyone in particular ?",
"Who, for example?",
"Are you thinking of a very special person ?",
"Who, may I ask ?",
"Someone special perhaps ?",
"You have a particular person in mind, don't you ?",
"Who do you think you're talking about ?"
]
}
],
"token": "everyone"
},
{
"weight": 2,
"rules": [
{
"decomp": "*",
"reasmb": [
"goto everyone"
]
}
],
"token": "everybody"
},
{
"weight": 2,
"rules": [
{
"decomp": "*",
"reasmb": [
"goto everyone"
]
}
],
"token": "nobody"
},
{
"weight": 2,
"rules": [
{
"decomp": "*",
"reasmb": [
"goto everyone"
]
}
],
"token": "noone"
},
{
"weight": 1,
"rules": [
{
"decomp": "*",
"reasmb": [
"Can you think of a specific example ?",
"When ?",
"What incident are you thinking of ?",
"Really, always ?"
]
}
],
"token": "always"
},
{
"weight": 10,
"rules": [
{
"decomp": "*",
"reasmb": [
"In what way ?",
"What resemblence do you see ?",
"What does that similarity suggest to you ?",
"What other connections do you see ?",
"What do you suppose that resemblence means ?",
"What is the connection, do you suppose ?",
"Could here really be some connection ?",
"How ?"
]
}
],
"token": "alike"
},
{
"weight": 10,
"rules": [
{
"decomp": "* @be *like *",
"reasmb": [
"goto alike"
]
}
],
"token": "like"
}
]
}

@ -1,4 +1,14 @@
/*
Michael Murtaugh
Following Charles Hayden's 1990's interpretation implemented in Java
(C) 2018 and released under the Free Art License 1.3
See LICENSE.txt and http://artlibre.org/licence/lal/en/
Use the accompanying eliza_script_to_json.py to prepare the rules in JSON format
*/
function chatbot (rules, textarea, display, debug) { function chatbot (rules, textarea, display, debug) {
var saved_statements = [];
function process_rules (rules) { function process_rules (rules) {
function looping_iterator (l) { function looping_iterator (l) {
var next = function () { var next = function () {
@ -45,6 +55,7 @@ function chatbot (rules, textarea, display, debug) {
}); });
// console.log("keywords_by_token", rules.keywords_by_token) // console.log("keywords_by_token", rules.keywords_by_token)
} }
// function trim (text) { return text.replace(/\s+$/, "").replace(/\s+/, ""); } // function trim (text) { return text.replace(/\s+$/, "").replace(/\s+/, ""); }
function trimword (text) { function trimword (text) {
return text return text
@ -56,6 +67,7 @@ function chatbot (rules, textarea, display, debug) {
return (trimword(text).split(/\s+/).map(trimword)); return (trimword(text).split(/\s+/).map(trimword));
} }
// used for both pre + post subs
function sub (tokens, subst) { function sub (tokens, subst) {
for (var i=0, l=tokens.length; i<l; i++) { for (var i=0, l=tokens.length; i<l; i++) {
var sub = subst[tokens[i].toLowerCase()]; var sub = subst[tokens[i].toLowerCase()];
@ -70,6 +82,7 @@ function chatbot (rules, textarea, display, debug) {
} }
return tokens; return tokens;
} }
function select_keywords (tokens) { function select_keywords (tokens) {
var ret = []; var ret = [];
for (var i=0, l=tokens.length; i<l; i++) { for (var i=0, l=tokens.length; i<l; i++) {
@ -88,6 +101,7 @@ function chatbot (rules, textarea, display, debug) {
} }
return ret; return ret;
} }
function compile_pattern (pattern) { function compile_pattern (pattern) {
// compile a decomposition pattern // compile a decomposition pattern
// * i @cannot * ==> i(cannot|cant|...)(.+) // * i @cannot * ==> i(cannot|cant|...)(.+)
@ -107,6 +121,7 @@ function chatbot (rules, textarea, display, debug) {
}); });
return "^"+ret+"$"; return "^"+ret+"$";
} }
function match_decomp (pattern, tokens) { function match_decomp (pattern, tokens) {
var ppat = compile_pattern(pattern); var ppat = compile_pattern(pattern);
// console.log("compile_pattern.in", pattern); // console.log("compile_pattern.in", pattern);
@ -114,11 +129,13 @@ function chatbot (rules, textarea, display, debug) {
var ppat = new RegExp(ppat, "i"); var ppat = new RegExp(ppat, "i");
return ppat.exec(tokens.join(" ")); return ppat.exec(tokens.join(" "));
} }
function do_post (txt) { function do_post (txt) {
var tokens = tokenize(txt); var tokens = tokenize(txt);
tokens = sub(tokens, rules.post); tokens = sub(tokens, rules.post);
return tokens.join(" "); return tokens.join(" ");
} }
function do_reasmb (reasmb, match, tokens) { function do_reasmb (reasmb, match, tokens) {
if (Array.isArray(match)) { if (Array.isArray(match)) {
return reasmb.replace(/\((\d+)\)/, function (m, n) { return reasmb.replace(/\((\d+)\)/, function (m, n) {
@ -130,9 +147,14 @@ function chatbot (rules, textarea, display, debug) {
return reasmb; return reasmb;
} }
} }
function apply_keywords (keywords, tokens) { function apply_keywords (keywords, tokens) {
for (var i=0, l=keywords.length; i<l; i++) { for (var i=0, l=keywords.length; i<l; i++) {
var keyword = keywords[i]; var keyword = keywords[i];
if ((keyword.token == "xnone") && (saved_statements.length > 0)) {
console.log("using saved statement");
return saved_statements.pop();
}
while (true) { while (true) {
console.log("trying keyword", keyword.token); console.log("trying keyword", keyword.token);
for (var ri=0, rl = keyword.rules.length; ri<rl; ri++) { for (var ri=0, rl = keyword.rules.length; ri<rl; ri++) {
@ -141,7 +163,11 @@ function chatbot (rules, textarea, display, debug) {
var match = match_decomp(rule.decomp, tokens); var match = match_decomp(rule.decomp, tokens);
if (match) { if (match) {
var ra = rule.reasmb(); var ra = rule.reasmb();
if (ra.indexOf("goto ") == 0) { if (rule['save']) {
var save = do_reasmb(ra, match, tokens);
console.log("save", save);
saved_statements.push(save);
} else if (ra.indexOf("goto ") == 0) {
var goto_name = ra.substr(5); var goto_name = ra.substr(5);
console.log("goto", goto_name); console.log("goto", goto_name);
keyword = rules.keywords_by_token[goto_name] keyword = rules.keywords_by_token[goto_name]
@ -154,12 +180,14 @@ function chatbot (rules, textarea, display, debug) {
} }
} }
} }
function log (msg, kls) { function log (msg, kls) {
var d = document.createElement("div"); var d = document.createElement("div");
d.setAttribute("class", kls); d.setAttribute("class", kls);
d.innerHTML = msg; d.innerHTML = msg;
display.appendChild(d); display.appendChild(d);
} }
function say (msg) { function say (msg) {
log(msg, "bot"); log(msg, "bot");
} }

@ -1,15 +1,16 @@
""" """
key: remember 5 Michael Murtaugh
decomp: * i remember * Following Charles Hayden's 1990's interpretation implemented in Java
reasmb: Do you often think of (2) ? (C) 2018 and released under the Free Art License 1.3
reasmb: Does thinking of (2) bring anything else to mind ? See LICENSE.txt and http://artlibre.org/licence/lal/en/
reasmb: What else do you recollect ?
reasmb: Why do you remember (2) just now ? For use with eliza.js
reasmb: What in the present situation reminds you of (2) ? Usage:
reasmb: What is the connection between me and (2) ?
reasmb: What else does (2) remind you of ? python3 eliza_script_to_json.py < doctor.txt > doctor.json
""" """
import sys import sys, json
output = {} output = {}
output['pre'] = pre = [] output['pre'] = pre = []
@ -44,17 +45,16 @@ for line in sys.stdin:
keys.append({"token": token.strip(), "weight": int(weight), "rules": []}) keys.append({"token": token.strip(), "weight": int(weight), "rules": []})
elif line.startswith("decomp:"): elif line.startswith("decomp:"):
_, pattern = line.split(" ", 1) _, pattern = line.split(" ", 1)
print ("decomp", pattern, file=sys.stderr) pattern = pattern.strip()
keys[-1]['rules'].append({"decomp": pattern.strip(), "reasmb": []}) if pattern.startswith("$"):
decomp = {"decomp": pattern[1:].strip(), "reasmb": [], "save": True}
else:
decomp = {"decomp": pattern, "reasmb": []}
print ("decomp", decomp, file=sys.stderr)
keys[-1]['rules'].append(decomp)
elif line.startswith("reasmb:"): elif line.startswith("reasmb:"):
_, pattern = line.split(" ", 1) _, pattern = line.split(" ", 1)
print ("reasmb", pattern, file=sys.stderr) print ("reasmb", pattern, file=sys.stderr)
keys[-1]['rules'][-1]['reasmb'].append(pattern.strip()) keys[-1]['rules'][-1]['reasmb'].append(pattern.strip())
# out = {}
# keywords = out['keywords'] = {}
# for obj in keys:
# keyname = obj.get("token")
# del obj['token']
# keywords[keyname] = obj
import json
print (json.dumps(output, indent=2)) print (json.dumps(output, indent=2))

Loading…
Cancel
Save