From 2612aab00997ced8339ed8e837f5f93fd4e4a0ec Mon Sep 17 00:00:00 2001 From: Michael Murtaugh Date: Mon, 8 Oct 2018 16:44:18 +0200 Subject: [PATCH] various changes, bugfixes with goto --- doctor.js | 2 +- doctor.json | 92 ++++++++++++++++++++++++++--------------------------- doctor.txt | 2 +- eliza.html | 31 ++++++++++++++---- eliza.js | 47 +++++++-------------------- 5 files changed, 84 insertions(+), 90 deletions(-) diff --git a/doctor.js b/doctor.js index d026522..8093822 100644 --- a/doctor.js +++ b/doctor.js @@ -1 +1 @@ -eliza({"initial": "How do you do. Please tell me your problem.", "keywords": [{"weight": 0, "token": "xnone", "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 ?"]}]}, {"weight": 0, "token": "sorry", "rules": [{"decomp": "*", "reasmb": ["Please don't apologise.", "Apologies are not necessary.", "I've told you that apologies are not required."]}]}, {"weight": 0, "token": "apologise", "rules": [{"decomp": "*", "reasmb": ["goto sorry"]}]}, {"weight": 5, "token": "remember", "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) ?"]}]}, {"weight": 3, "token": "if", "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) ?"]}]}, {"weight": 4, "token": "dreamed", "rules": [{"decomp": "* i dreamed *", "reasmb": ["Really, (2) ?", "Have you ever fantasized (2) while you were awake ?", "Have you ever dreamed (2) before ?", "goto dream"]}]}, {"weight": 3, "token": "dream", "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 ?"]}]}, {"weight": 0, "token": "perhaps", "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 ?"]}]}, {"weight": 15, "token": "name", "rules": [{"decomp": "*", "reasmb": ["I am not interested in names.", "I've told you before, I don't care about names -- please continue."]}]}, {"weight": 0, "token": "deutsch", "rules": [{"decomp": "*", "reasmb": ["goto xforeign", "I told you before, I don't understand German."]}]}, {"weight": 0, "token": "francais", "rules": [{"decomp": "*", "reasmb": ["goto xforeign", "I told you before, I don't understand French."]}]}, {"weight": 0, "token": "italiano", "rules": [{"decomp": "*", "reasmb": ["goto xforeign", "I told you before, I don't understand Italian."]}]}, {"weight": 0, "token": "espanol", "rules": [{"decomp": "*", "reasmb": ["goto xforeign", "I told you before, I don't understand Spanish."]}]}, {"weight": 0, "token": "xforeign", "rules": [{"decomp": "*", "reasmb": ["I speak only English."]}]}, {"weight": 0, "token": "hello", "rules": [{"decomp": "*", "reasmb": ["How do you do. Please state your problem.", "Hi. What seems to be your problem ?"]}]}, {"weight": 50, "token": "computer", "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 ?"]}]}, {"weight": 0, "token": "am", "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."]}]}, {"weight": 0, "token": "are", "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)."]}]}, {"weight": 0, "token": "your", "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) ?"]}]}, {"weight": 2, "token": "was", "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) ?"]}]}, {"weight": 0, "token": "i", "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."]}]}, {"weight": 0, "token": "you", "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 ?"]}]}, {"weight": 0, "token": "yes", "rules": [{"decomp": "*", "reasmb": ["You seem to be quite positive.", "You are sure.", "I see.", "I understand."]}]}, {"weight": 0, "token": "no", "rules": [{"decomp": "*", "reasmb": ["Are you saying no just to be negative?", "You are being a bit negative.", "Why not ?", "Why 'no' ?"]}]}, {"weight": 2, "token": "my", "rules": [{"save": true, "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) ?"]}, {"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) ?"]}]}, {"weight": 0, "token": "can", "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"]}]}, {"weight": 0, "token": "what", "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 ?"]}]}, {"weight": 0, "token": "because", "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 ?"]}]}, {"weight": 0, "token": "why", "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"]}]}, {"weight": 2, "token": "everyone", "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 ?"]}]}, {"weight": 2, "token": "everybody", "rules": [{"decomp": "*", "reasmb": ["goto everyone"]}]}, {"weight": 2, "token": "nobody", "rules": [{"decomp": "*", "reasmb": ["goto everyone"]}]}, {"weight": 2, "token": "noone", "rules": [{"decomp": "*", "reasmb": ["goto everyone"]}]}, {"weight": 1, "token": "always", "rules": [{"decomp": "*", "reasmb": ["Can you think of a specific example ?", "When ?", "What incident are you thinking of ?", "Really, always ?"]}]}, {"weight": 10, "token": "alike", "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 ?"]}]}, {"weight": 10, "token": "like", "rules": [{"decomp": "* @be *like *", "reasmb": ["goto alike"]}]}], "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"], "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"], "post": ["am are", "your my", "me you", "myself yourself", "yourself myself", "i you", "you I", "my your", "i'm you are"], "quit": [], "final": "Goodbye. Thank you for talking to me."}); +eliza({"final": "Goodbye. Thank you for talking to me.", "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"], "post": ["am are", "your my", "me you", "myself yourself", "yourself myself", "i you", "you I", "my your", "i'm you are"], "keywords": [{"token": "xnone", "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 ?"]}], "weight": 0}, {"token": "sorry", "rules": [{"decomp": "*", "reasmb": ["Please don't apologise.", "Apologies are not necessary.", "I've told you that apologies are not required."]}], "weight": 0}, {"token": "apologise", "rules": [{"decomp": "*", "reasmb": ["goto sorry"]}], "weight": 0}, {"token": "remember", "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) ?"]}], "weight": 5}, {"token": "if", "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) ?"]}], "weight": 3}, {"token": "dreamed", "rules": [{"decomp": "* i dreamed *", "reasmb": ["Really, (2) ?", "Have you ever fantasized (2) while you were awake ?", "Have you ever dreamed (2) before ?", "goto dream"]}], "weight": 4}, {"token": "dream", "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 ?"]}], "weight": 3}, {"token": "perhaps", "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 ?"]}], "weight": 0}, {"token": "name", "rules": [{"decomp": "*", "reasmb": ["I am not interested in names.", "I've told you before, I don't care about names -- please continue."]}], "weight": 15}, {"token": "deutsch", "rules": [{"decomp": "*", "reasmb": ["goto xforeign", "I told you before, I don't understand German."]}], "weight": 0}, {"token": "francais", "rules": [{"decomp": "*", "reasmb": ["goto xforeign", "I told you before, I don't understand French."]}], "weight": 0}, {"token": "italiano", "rules": [{"decomp": "*", "reasmb": ["goto xforeign", "I told you before, I don't understand Italian."]}], "weight": 0}, {"token": "espanol", "rules": [{"decomp": "*", "reasmb": ["goto xforeign", "I told you before, I don't understand Spanish."]}], "weight": 0}, {"token": "xforeign", "rules": [{"decomp": "*", "reasmb": ["I speak only English."]}], "weight": 0}, {"token": "hello", "rules": [{"decomp": "*", "reasmb": ["How do you do. Please state your problem.", "Hi. What seems to be your problem ?"]}], "weight": 0}, {"token": "computer", "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 ?"]}], "weight": 50}, {"token": "am", "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."]}], "weight": 0}, {"token": "are", "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)."]}], "weight": 0}, {"token": "your", "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) ?"]}], "weight": 0}, {"token": "was", "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) ?"]}], "weight": 2}, {"token": "i", "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."]}], "weight": 0}, {"token": "you", "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 ?"]}], "weight": 0}, {"token": "yes", "rules": [{"decomp": "*", "reasmb": ["You seem to be quite positive.", "You are sure.", "I see.", "I understand."]}], "weight": 0}, {"token": "no", "rules": [{"decomp": "*", "reasmb": ["Are you saying no just to be negative?", "You are being a bit negative.", "Why not ?", "Why 'no' ?"]}], "weight": 0}, {"token": "my", "rules": [{"decomp": "* my *", "reasmb": ["Does that have anything to do with the fact that your (2) ?", "Lets discuss further why your (2).", "Earlier you said your (2).", "But 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) ?"]}], "weight": 2}, {"token": "can", "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"]}], "weight": 0}, {"token": "what", "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 ?"]}], "weight": 0}, {"token": "because", "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 ?"]}], "weight": 0}, {"token": "why", "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"]}], "weight": 0}, {"token": "everyone", "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 ?"]}], "weight": 2}, {"token": "everybody", "rules": [{"decomp": "*", "reasmb": ["goto everyone"]}], "weight": 2}, {"token": "nobody", "rules": [{"decomp": "*", "reasmb": ["goto everyone"]}], "weight": 2}, {"token": "noone", "rules": [{"decomp": "*", "reasmb": ["goto everyone"]}], "weight": 2}, {"token": "always", "rules": [{"decomp": "*", "reasmb": ["Can you think of a specific example ?", "When ?", "What incident are you thinking of ?", "Really, always ?"]}], "weight": 1}, {"token": "alike", "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 ?"]}], "weight": 10}, {"token": "like", "rules": [{"decomp": "* @be *like *", "reasmb": ["goto alike"]}], "weight": 10}], "initial": "How do you do. Please tell me your problem.", "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"], "quit": []}); diff --git a/doctor.json b/doctor.json index cec25e2..da31352 100644 --- a/doctor.json +++ b/doctor.json @@ -1,45 +1,4 @@ { - "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": [ { @@ -562,13 +521,13 @@ "rules": [ { "decomp": "* my *", + "save": true, "reasmb": [ + "Does that have anything to do with the fact that your (2) ?", "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 + "But your (2)." + ] }, { "decomp": "* my* @family *", @@ -784,5 +743,46 @@ ], "token": "like" } - ] + ], + "final": "Goodbye. Thank you for talking to me.", + "post": [ + "am are", + "your my", + "me you", + "myself yourself", + "yourself myself", + "i you", + "you I", + "my your", + "i'm you are" + ], + "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" + ], + "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" + ], + "quit": [] } diff --git a/doctor.txt b/doctor.txt index ae818ce..bc6f252 100644 --- a/doctor.txt +++ b/doctor.txt @@ -261,10 +261,10 @@ key: no reasmb: Why 'no' ? key: my 2 decomp: $ * my * + reasmb: Does that have anything to do with the fact that your (2) ? reasmb: Lets discuss further why your (2). reasmb: Earlier you said your (2). reasmb: But your (2). - reasmb: Does that have anything to do with the fact that your (2) ? decomp: * my* @family * reasmb: Tell me more about your family. reasmb: Who else in your family (4) ? diff --git a/eliza.html b/eliza.html index 15203cc..471b2c0 100644 --- a/eliza.html +++ b/eliza.html @@ -52,13 +52,32 @@ diff --git a/eliza.js b/eliza.js index a19ec3c..eb7d7db 100644 --- a/eliza.js +++ b/eliza.js @@ -7,14 +7,11 @@ 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 (opts) { - var rules = opts.rules, - textarea = opts.input, - display = opts.output, - debug = opts.debug || false, - autoscroll = opts.autoscroll === undefined ? true : opts.autoscroll; +function chatbot (rules, debug) { var saved_statements = []; + function process_rules (rules) { + // transfrom / pre-process the rules function looping_iterator (l) { var next = function () { var ret = l[next.i]; @@ -48,9 +45,7 @@ function chatbot (opts) { // index keywords by name rules.keywords_by_token = {}; rules.keywords.forEach(function (x) { - // console.log("token", x.token); rules.keywords_by_token[x.token] = x; - // wrap the rules x.rules.forEach(function (r) { // ensure list if (!Array.isArray(r.reasmb)) { r.reasmb = [r.reasmb]; } @@ -58,7 +53,6 @@ function chatbot (opts) { r.reasmb = looping_iterator(r.reasmb); }); }); - // console.log("keywords_by_token", rules.keywords_by_token) } // function trim (text) { return text.replace(/\s+$/, "").replace(/\s+/, ""); } @@ -160,7 +154,9 @@ function chatbot (opts) { if (debug) { console.log("using saved statement"); } return saved_statements.shift(); } - while (true) { + var loop = true; + while (loop) { + loop = false; if (debug) { console.log("trying keyword", keyword.token); } for (var ri=0, rl = keyword.rules.length; ri