*** empty log message ***
[bpt/emacs.git] / lisp / play / doctor.el
CommitLineData
55535639 1;;; doctor.el --- psychological help for frustrated users
c0274f38 2
f2e3589a 3;; Copyright (C) 1985, 1987, 1994, 1996, 2000, 2001, 2002, 2003, 2004,
d7a0267c 4;; 2005, 2006, 2007 Free Software Foundation, Inc.
9750e079 5
e5167999 6;; Maintainer: FSF
e5167999
ER
7;; Keywords: games
8
6679505f
JB
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
e5167999 13;; the Free Software Foundation; either version 2, or (at your option)
6679505f
JB
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
b578f267 22;; along with GNU Emacs; see the file COPYING. If not, write to the
3a35cf56
LK
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
6679505f 25
e41b2db1
ER
26;;; Commentary:
27
28;; The single entry point `doctor', simulates a Rogerian analyst using
29;; phrase-production techniques similar to the classic ELIZA demonstration
30;; of pseudo-AI.
31
da4e5ca9 32;; This file was for a while censored by the Communications Decency Act.
46cfd45b
RS
33;; Some of its features were removed. The law was promoted as a ban
34;; on pornography, but it bans far more than that. The doctor program
f470d537 35;; did not contain pornography, but part of it was prohibited
46cfd45b
RS
36;; nonetheless.
37
da4e5ca9
RS
38;; The Supreme Court overturned the Communications Decency Act, but
39;; Congress is sure to look for some other way to try to end free speech.
46cfd45b 40;; For information on US government censorship of the Internet, and
da4e5ca9 41;; what you can do to protect freedom of the press, see the web
46cfd45b 42;; site http://www.vtw.org/
988dff5e
RS
43;; See also the file etc/CENSORSHIP in the Emacs distribution
44;; for a discussion of why and how this file was censored, and the
45;; political implications of the issue.
46cfd45b 46
e5167999 47;;; Code:
6679505f 48
0ff22356
SM
49(defvar **mad**) (defvar *debug*) (defvar *print-space*)
50(defvar *print-upcase*) (defvar abuselst) (defvar abusewords)
51(defvar account) (defvar afraidof) (defvar arerelated)
52(defvar areyou) (defvar bak) (defvar beclst)
53(defvar bother) (defvar bye) (defvar canyou)
54(defvar chatlst) (defvar continue) (defvar deathlst)
55(defvar describe) (defvar drnk) (defvar drugs)
56(defvar eliza-flag) (defvar elizalst) (defvar famlst)
57(defvar feared) (defvar fears) (defvar feelings-about)
58(defvar foullst) (defvar found) (defvar hello)
59(defvar history) (defvar howareyoulst) (defvar howdyflag)
60(defvar huhlst) (defvar ibelieve) (defvar improve)
61(defvar inter) (defvar isee) (defvar isrelated)
62(defvar lincount) (defvar longhuhlst) (defvar lover)
63(defvar machlst) (defvar mathlst) (defvar maybe)
64(defvar moods) (defvar neglst) (defvar obj)
65(defvar object) (defvar owner) (defvar please)
66(defvar problems) (defvar qlist) (defvar random-adjective)
67(defvar relation) (defvar remlst) (defvar repetitive-shortness)
68(defvar replist) (defvar rms-flag) (defvar schoollst)
69(defvar sent) (defvar sexlst) (defvar shortbeclst)
70(defvar shortlst) (defvar something) (defvar sportslst)
71(defvar stallmanlst) (defvar states) (defvar subj)
72(defvar suicide-flag) (defvar sure) (defvar things)
73(defvar thlst) (defvar toklst) (defvar typos)
74(defvar verb) (defvar want) (defvar whatwhen)
75(defvar whereoutp) (defvar whysay) (defvar whywant)
76(defvar zippy-flag) (defvar zippylst)
6f08431c 77
a3e58c1a 78(defun doc// (x) x)
6679505f 79
a3e58c1a 80(defmacro doc$ (what)
6679505f
JB
81 "quoted arg form of doctor-$"
82 (list 'doctor-$ (list 'quote what)))
83
84(defun doctor-$ (what)
85 "Return the car of a list, rotating the list each time"
86 (let* ((vv (symbol-value what))
87 (first (car vv))
88 (ww (append (cdr vv) (list first))))
89 (set what ww)
90 first))
91\f
9d6f699a 92(defvar doctor-mode-map
0ff22356
SM
93 (let ((map (make-sparse-keymap)))
94 (define-key map "\n" 'doctor-read-print)
95 (define-key map "\r" 'doctor-ret-or-read)
96 map))
97
2aa8e74a 98(define-derived-mode doctor-mode text-mode "Doctor"
6679505f
JB
99 "Major mode for running the Doctor (Eliza) program.
100Like Text mode with Auto Fill mode
101except that RET when point is after a newline, or LFD at any time,
102reads the sentence before point, and prints the Doctor's answer."
6679505f 103 (make-doctor-variables)
6679505f
JB
104 (turn-on-auto-fill)
105 (doctor-type '(i am the psychotherapist \.
a3e58c1a 106 (doc$ please) (doc$ describe) your (doc$ problems) \.
6679505f
JB
107 each time you are finished talking, type \R\E\T twice \.))
108 (insert "\n"))
109
110(defun make-doctor-variables ()
6679505f
JB
111 (make-local-variable 'typos)
112 (setq typos
113 (mapcar (function (lambda (x)
454473ea
JPW
114 (put (car x) 'doctor-correction (cadr x))
115 (put (cadr x) 'doctor-expansion (car (cddr x)))
6679505f
JB
116 (car x)))
117 '((theyll they\'ll (they will))
118 (theyre they\'re (they are))
119 (hes he\'s (he is))
120 (he7s he\'s (he is))
121 (im i\'m (you are))
122 (i7m i\'m (you are))
123 (isa is\ a (is a))
124 (thier their (their))
125 (dont don\'t (do not))
126 (don7t don\'t (do not))
127 (you7re you\'re (i am))
128 (you7ve you\'ve (i have))
129 (you7ll you\'ll (i will)))))
130 (make-local-variable 'found)
131 (setq found nil)
132 (make-local-variable 'owner)
133 (setq owner nil)
134 (make-local-variable 'history)
135 (setq history nil)
136 (make-local-variable '*debug*)
137 (setq *debug* nil)
138 (make-local-variable 'inter)
139 (setq inter
140 '((well\,)
141 (hmmm \.\.\.\ so\,)
142 (so)
143 (\.\.\.and)
144 (then)))
145 (make-local-variable 'continue)
146 (setq continue
147 '((continue)
148 (proceed)
149 (go on)
150 (keep going) ))
151 (make-local-variable 'relation)
152 (setq relation
153 '((your relationship with)
154 (something you remember about)
155 (your feelings toward)
156 (some experiences you have had with)
157 (how you feel about)))
158 (make-local-variable 'fears)
a3e58c1a
JPW
159 (setq fears '( ((doc$ whysay) you are (doc$ afraidof) (doc// feared) \?)
160 (you seem terrified by (doc// feared) \.)
161 (when did you first feel (doc$ afraidof) (doc// feared) \?) ))
6679505f
JB
162 (make-local-variable 'sure)
163 (setq sure '((sure)(positive)(certain)(absolutely sure)))
164 (make-local-variable 'afraidof)
165 (setq afraidof '( (afraid of) (frightened by) (scared of) ))
166 (make-local-variable 'areyou)
167 (setq areyou '( (are you)(have you been)(have you been) ))
168 (make-local-variable 'isrelated)
169 (setq isrelated '( (has something to do with)(is related to)
170 (could be the reason for) (is caused by)(is because of)))
171 (make-local-variable 'arerelated)
172 (setq arerelated '((have something to do with)(are related to)
173 (could have caused)(could be the reason for) (are caused by)
174 (are because of)))
175 (make-local-variable 'moods)
a3e58c1a
JPW
176 (setq moods '( ((doc$ areyou)(doc// found) often \?)
177 (what causes you to be (doc// found) \?)
178 ((doc$ whysay) you are (doc// found) \?) ))
6679505f
JB
179 (make-local-variable 'maybe)
180 (setq maybe
181 '((maybe)
182 (perhaps)
183 (possibly)))
184 (make-local-variable 'whatwhen)
185 (setq whatwhen
186 '((what happened when)
187 (what would happen if)))
188 (make-local-variable 'hello)
189 (setq hello
190 '((how do you do \?) (hello \.) (howdy!) (hello \.) (hi \.) (hi there \.)))
191 (make-local-variable 'drnk)
192 (setq drnk
a3e58c1a 193 '((do you drink a lot of (doc// found) \?)
6679505f 194 (do you get drunk often \?)
a1506d29 195 ((doc$ describe) your drinking habits \.) ))
6679505f 196 (make-local-variable 'drugs)
a3e58c1a
JPW
197 (setq drugs '( (do you use (doc// found) often \?)((doc$ areyou)
198 addicted to (doc// found) \?)(do you realize that drugs can
199 be very harmful \?)((doc$ maybe) you should try to quit using (doc// found)
6679505f
JB
200 \.)))
201 (make-local-variable 'whywant)
a3e58c1a 202 (setq whywant '( ((doc$ whysay) (doc// subj) might (doc$ want) (doc// obj) \?)
6679505f 203 (how does it feel to want \?)
a3e58c1a
JPW
204 (why should (doc// subj) get (doc// obj) \?)
205 (when did (doc// subj) first (doc$ want) (doc// obj) \?)
206 ((doc$ areyou) obsessed with (doc// obj) \?)
207 (why should i give (doc// obj) to (doc// subj) \?)
208 (have you ever gotten (doc// obj) \?) ))
6679505f
JB
209 (make-local-variable 'canyou)
210 (setq canyou '((of course i can \.)
211 (why should i \?)
212 (what makes you think i would even want to \?)
213 (i am the doctor\, i can do anything i damn please \.)
214 (not really\, it\'s not up to me \.)
215 (depends\, how important is it \?)
216 (i could\, but i don\'t think it would be a wise thing to do \.)
217 (can you \?)
218 (maybe i can\, maybe i can\'t \.\.\.)
219 (i don\'t think i should do that \.)))
220 (make-local-variable 'want)
221 (setq want '( (want) (desire) (wish) (want) (hope) ))
222 (make-local-variable 'shortlst)
223 (setq shortlst
224 '((can you elaborate on that \?)
a3e58c1a 225 ((doc$ please) continue \.)
6679505f
JB
226 (go on\, don\'t be afraid \.)
227 (i need a little more detail please \.)
a3e58c1a 228 (you\'re being a bit brief\, (doc$ please) go into detail \.)
130b416e 229 (can you be more explicit \?)
6679505f 230 (and \?)
a3e58c1a 231 ((doc$ please) go into more detail \?)
6679505f
JB
232 (you aren\'t being very talkative today\!)
233 (is that all there is to it \?)
234 (why must you respond so briefly \?)))
235
236 (make-local-variable 'famlst)
237 (setq famlst
a3e58c1a
JPW
238 '((tell me (doc$ something) about (doc// owner) family \.)
239 (you seem to dwell on (doc// owner) family \.)
240 ((doc$ areyou) hung up on (doc// owner) family \?)))
6679505f
JB
241 (make-local-variable 'huhlst)
242 (setq huhlst
a3e58c1a
JPW
243 '(((doc$ whysay)(doc// sent) \?)
244 (is it because of (doc$ things) that you say (doc// sent) \?) ))
6679505f
JB
245 (make-local-variable 'longhuhlst)
246 (setq longhuhlst
a3e58c1a 247 '(((doc$ whysay) that \?)
6679505f 248 (i don\'t understand \.)
a3e58c1a
JPW
249 ((doc$ thlst))
250 ((doc$ areyou) (doc$ afraidof) that \?)))
b8797e1f 251 (make-local-variable 'feelings-about)
6679505f
JB
252 (setq feelings-about
253 '((feelings about)
0f668406 254 (apprehensions toward)
6679505f
JB
255 (thoughts on)
256 (emotions toward)))
b8797e1f 257 (make-local-variable 'random-adjective)
6679505f
JB
258 (setq random-adjective
259 '((vivid)
260 (emotionally stimulating)
261 (exciting)
262 (boring)
263 (interesting)
264 (recent)
265 (random) ;How can we omit this?
266 (unusual)
267 (shocking)
268 (embarrassing)))
269 (make-local-variable 'whysay)
270 (setq whysay
271 '((why do you say)
272 (what makes you believe)
273 (are you sure that)
274 (do you really think)
275 (what makes you think) ))
276 (make-local-variable 'isee)
277 (setq isee
278 '((i see \.\.\.)
279 (yes\,)
280 (i understand \.)
281 (oh \.) ))
282 (make-local-variable 'please)
a1506d29 283 (setq please
6679505f
JB
284 '((please\,)
285 (i would appreciate it if you would)
286 (perhaps you could)
287 (please\,)
288 (would you please)
289 (why don\'t you)
290 (could you)))
291 (make-local-variable 'bye)
292 (setq bye
293 '((my secretary will send you a bill \.)
294 (bye bye \.)
295 (see ya \.)
296 (ok\, talk to you some other time \.)
297 (talk to you later \.)
298 (ok\, have fun \.)
299 (ciao \.)))
300 (make-local-variable 'something)
301 (setq something
302 '((something)
303 (more)
304 (how you feel)))
305 (make-local-variable 'things)
a1506d29 306 (setq things
6679505f
JB
307 '(;(your interests in computers) ;; let's make this less computer oriented
308 ;(the machines you use)
309 (your plans)
310 ;(your use of computers)
311 (your life)
312 ;(other machines you use)
313 (the people you hang around with)
314 ;(computers you like)
315 (problems at school)
316 (any hobbies you have)
317 ;(other computers you use)
318 (your sex life)
319 (hangups you have)
320 (your inhibitions)
321 (some problems in your childhood)
322 ;(knowledge of computers)
323 (some problems at home)))
324 (make-local-variable 'describe)
325 (setq describe
326 '((describe)
327 (tell me about)
328 (talk about)
329 (discuss)
330 (tell me more about)
331 (elaborate on)))
332 (make-local-variable 'ibelieve)
a1506d29 333 (setq ibelieve
6679505f
JB
334 '((i believe) (i think) (i have a feeling) (it seems to me that)
335 (it looks like)))
336 (make-local-variable 'problems)
337 (setq problems '( (problems)
338 (inhibitions)
339 (hangups)
340 (difficulties)
341 (anxieties)
342 (frustrations) ))
343 (make-local-variable 'bother)
344 (setq bother
345 '((does it bother you that)
346 (are you annoyed that)
347 (did you ever regret)
348 (are you sorry)
349 (are you satisfied with the fact that)))
350 (make-local-variable 'machlst)
a1506d29 351 (setq machlst
a3e58c1a
JPW
352 '((you have your mind on (doc// found) \, it seems \.)
353 (you think too much about (doc// found) \.)
354 (you should try taking your mind off of (doc// found)\.)
6679505f
JB
355 (are you a computer hacker \?)))
356 (make-local-variable 'qlist)
357 (setq qlist
358 '((what do you think \?)
359 (i\'ll ask the questions\, if you don\'t mind!)
360 (i could ask the same thing myself \.)
a3e58c1a 361 ((doc$ please) allow me to do the questioning \.)
6679505f 362 (i have asked myself that question many times \.)
a3e58c1a 363 ((doc$ please) try to answer that question yourself \.)))
6679505f
JB
364 (make-local-variable 'foullst)
365 (setq foullst
a3e58c1a
JPW
366 '(((doc$ please) watch your tongue!)
367 ((doc$ please) avoid such unwholesome thoughts \.)
368 ((doc$ please) get your mind out of the gutter \.)
6679505f
JB
369 (such lewdness is not appreciated \.)))
370 (make-local-variable 'deathlst)
371 (setq deathlst
372 '((this is not a healthy way of thinking \.)
a3e58c1a 373 ((doc$ bother) you\, too\, may die someday \?)
eb8c3be9 374 (i am worried by your obsession with this topic!)
6679505f
JB
375 (did you watch a lot of crime and violence on television as a child \?))
376 )
377 (make-local-variable 'sexlst)
a1506d29 378 (setq sexlst
a3e58c1a
JPW
379 '(((doc$ areyou) (doc$ afraidof) sex \?)
380 ((doc$ describe)(doc$ something) about your sexual history \.)
381 ((doc$ please)(doc$ describe) your sex life \.\.\.)
382 ((doc$ describe) your (doc$ feelings-about) your sexual partner \.)
383 ((doc$ describe) your most (doc$ random-adjective) sexual experience \.)
384 ((doc$ areyou) satisfied with (doc// lover) \.\.\. \?)))
6679505f
JB
385 (make-local-variable 'neglst)
386 (setq neglst
387 '((why not \?)
a3e58c1a 388 ((doc$ bother) i ask that \?)
6679505f
JB
389 (why not \?)
390 (why not \?)
391 (how come \?)
a3e58c1a 392 ((doc$ bother) i ask that \?)))
6679505f
JB
393 (make-local-variable 'beclst)
394 (setq beclst '(
a3e58c1a
JPW
395 (is it because (doc// sent) that you came to me \?)
396 ((doc$ bother)(doc// sent) \?)
397 (when did you first know that (doc// sent) \?)
398 (is the fact that (doc// sent) the real reason \?)
399 (does the fact that (doc// sent) explain anything else \?)
400 ((doc$ areyou)(doc$ sure)(doc// sent) \? ) ))
6679505f
JB
401 (make-local-variable 'shortbeclst)
402 (setq shortbeclst '(
a3e58c1a 403 ((doc$ bother) i ask you that \?)
6679505f 404 (that\'s not much of an answer!)
a3e58c1a 405 ((doc$ inter) why won\'t you talk about it \?)
6679505f 406 (speak up!)
a3e58c1a
JPW
407 ((doc$ areyou) (doc$ afraidof) talking about it \?)
408 (don\'t be (doc$ afraidof) elaborating \.)
409 ((doc$ please) go into more detail \.)))
6679505f
JB
410 (make-local-variable 'thlst)
411 (setq thlst '(
a3e58c1a
JPW
412 ((doc$ maybe)(doc$ things)(doc$ arerelated) this \.)
413 (is it because of (doc$ things) that you are going through all this \?)
414 (how do you reconcile (doc$ things) \? )
415 ((doc$ maybe) this (doc$ isrelated)(doc$ things) \?) ))
6679505f 416 (make-local-variable 'remlst)
a3e58c1a
JPW
417 (setq remlst '( (earlier you said (doc$ history) \?)
418 (you mentioned that (doc$ history) \?)
419 ((doc$ whysay)(doc$ history) \? ) ))
6679505f
JB
420 (make-local-variable 'toklst)
421 (setq toklst
422 '((is this how you relax \?)
423 (how long have you been smoking grass \?)
a3e58c1a 424 ((doc$ areyou) (doc$ afraidof) of being drawn to using harder stuff \?)))
6679505f
JB
425 (make-local-variable 'states)
426 (setq states
a3e58c1a
JPW
427 '((do you get (doc// found) often \?)
428 (do you enjoy being (doc// found) \?)
429 (what makes you (doc// found) \?)
430 (how often (doc$ areyou)(doc// found) \?)
431 (when were you last (doc// found) \?)))
6679505f 432 (make-local-variable 'replist)
a1506d29 433 (setq replist
6679505f
JB
434 '((i . (you))
435 (my . (your))
436 (me . (you))
437 (you . (me))
438 (your . (my))
439 (mine . (yours))
440 (yours . (mine))
441 (our . (your))
442 (ours . (yours))
443 (we . (you))
444 (dunno . (do not know))
445;; (yes . ())
446 (no\, . ())
447 (yes\, . ())
448 (ya . (i))
449 (aint . (am not))
450 (wanna . (want to))
451 (gimme . (give me))
452 (gotta . (have to))
453 (gonna . (going to))
454 (never . (not ever))
455 (doesn\'t . (does not))
456 (don\'t . (do not))
457 (aren\'t . (are not))
458 (isn\'t . (is not))
459 (won\'t . (will not))
460 (can\'t . (cannot))
461 (haven\'t . (have not))
462 (i\'m . (you are))
463 (ourselves . (yourselves))
464 (myself . (yourself))
465 (yourself . (myself))
466 (you\'re . (i am))
467 (you\'ve . (i have))
468 (i\'ve . (you have))
469 (i\'ll . (you will))
470 (you\'ll . (i shall))
471 (i\'d . (you would))
472 (you\'d . (i would))
473 (here . (there))
474 (please . ())
475 (eh\, . ())
476 (eh . ())
477 (oh\, . ())
478 (oh . ())
479 (shouldn\'t . (should not))
480 (wouldn\'t . (would not))
481 (won\'t . (will not))
482 (hasn\'t . (has not))))
483 (make-local-variable 'stallmanlst)
484 (setq stallmanlst '(
a3e58c1a
JPW
485 ((doc$ describe) your (doc$ feelings-about) him \.)
486 ((doc$ areyou) a friend of Stallman \?)
487 ((doc$ bother) Stallman is (doc$ random-adjective) \?)
488 ((doc$ ibelieve) you are (doc$ afraidof) him \.)))
6679505f
JB
489 (make-local-variable 'schoollst)
490 (setq schoollst '(
a3e58c1a
JPW
491 ((doc$ describe) your (doc// found) \.)
492 ((doc$ bother) your grades could (doc$ improve) \?)
493 ((doc$ areyou) (doc$ afraidof) (doc// found) \?)
494 ((doc$ maybe) this (doc$ isrelated) to your attitude \.)
495 ((doc$ areyou) absent often \?)
496 ((doc$ maybe) you should study (doc$ something) \.)))
6679505f
JB
497 (make-local-variable 'improve)
498 (setq improve '((improve) (be better) (be improved) (be higher)))
499 (make-local-variable 'elizalst)
500 (setq elizalst '(
a3e58c1a
JPW
501 ((doc$ areyou) (doc$ sure) \?)
502 ((doc$ ibelieve) you have (doc$ problems) with (doc// found) \.)
503 ((doc$ whysay) (doc// sent) \?)))
6679505f
JB
504 (make-local-variable 'sportslst)
505 (setq sportslst '(
a3e58c1a
JPW
506 (tell me (doc$ something) about (doc// found) \.)
507 ((doc$ describe) (doc$ relation) (doc// found) \.)
508 (do you find (doc// found) (doc$ random-adjective) \?)))
6679505f
JB
509 (make-local-variable 'mathlst)
510 (setq mathlst '(
a3e58c1a
JPW
511 ((doc$ describe) (doc$ something) about math \.)
512 ((doc$ maybe) your (doc$ problems) (doc$ arerelated) (doc// found) \.)
513 (i don\'t know much (doc// found) \, but (doc$ continue)
6679505f
JB
514 anyway \.)))
515 (make-local-variable 'zippylst)
516 (setq zippylst '(
a3e58c1a
JPW
517 ((doc$ areyou) Zippy \?)
518 ((doc$ ibelieve) you have some serious (doc$ problems) \.)
519 ((doc$ bother) you are a pinhead \?)))
6679505f
JB
520 (make-local-variable 'chatlst)
521 (setq chatlst '(
a3e58c1a
JPW
522 ((doc$ maybe) we could chat \.)
523 ((doc$ please) (doc$ describe) (doc$ something) about chat mode \.)
524 ((doc$ bother) our discussion is so (doc$ random-adjective) \?)))
6679505f
JB
525 (make-local-variable 'abuselst)
526 (setq abuselst '(
a3e58c1a
JPW
527 ((doc$ please) try to be less abusive \.)
528 ((doc$ describe) why you call me (doc// found) \.)
6679505f
JB
529 (i\'ve had enough of you!)))
530 (make-local-variable 'abusewords)
531 (setq abusewords '(boring bozo clown clumsy cretin dumb dummy
532 fool foolish gnerd gnurd idiot jerk
533 lose loser louse lousy luse luser
534 moron nerd nurd oaf oafish reek
535 stink stupid tool toolish twit))
536 (make-local-variable 'howareyoulst)
537 (setq howareyoulst '((how are you) (hows it going) (hows it going eh)
538 (how\'s it going) (how\'s it going eh) (how goes it)
539 (whats up) (whats new) (what\'s up) (what\'s new)
540 (howre you) (how\'re you) (how\'s everything)
541 (how is everything) (how do you do)
542 (how\'s it hanging) (que pasa)
543 (how are you doing) (what do you say)))
544 (make-local-variable 'whereoutp)
545 (setq whereoutp '( huh remem rthing ) )
546 (make-local-variable 'subj)
547 (setq subj nil)
548 (make-local-variable 'verb)
549 (setq verb nil)
550 (make-local-variable 'obj)
551 (setq obj nil)
552 (make-local-variable 'feared)
553 (setq feared nil)
6679505f
JB
554 (make-local-variable 'repetitive-shortness)
555 (setq repetitive-shortness '(0 . 0))
556 (make-local-variable '**mad**)
557 (setq **mad** nil)
558 (make-local-variable 'rms-flag)
559 (setq rms-flag nil)
560 (make-local-variable 'eliza-flag)
561 (setq eliza-flag nil)
562 (make-local-variable 'zippy-flag)
563 (setq zippy-flag nil)
f535f6b2
RS
564 (make-local-variable 'suicide-flag)
565 (setq suicide-flag nil)
6679505f
JB
566 (make-local-variable 'lover)
567 (setq lover '(your partner))
568 (make-local-variable 'bak)
569 (setq bak nil)
570 (make-local-variable 'lincount)
571 (setq lincount 0)
572 (make-local-variable '*print-upcase*)
573 (setq *print-upcase* nil)
574 (make-local-variable '*print-space*)
575 (setq *print-space* nil)
576 (make-local-variable 'howdyflag)
577 (setq howdyflag nil)
578 (make-local-variable 'object)
579 (setq object nil))
580\f
581;; Define equivalence classes of words that get treated alike.
582
583(defun doctor-meaning (x) (get x 'doctor-meaning))
584
585(defmacro doctor-put-meaning (symb val)
586 "Store the base meaning of a word on the property list."
587 (list 'put (list 'quote symb) ''doctor-meaning val))
588
589(doctor-put-meaning howdy 'howdy)
590(doctor-put-meaning hi 'howdy)
591(doctor-put-meaning greetings 'howdy)
592(doctor-put-meaning hello 'howdy)
593(doctor-put-meaning tops20 'mach)
594(doctor-put-meaning tops-20 'mach)
595(doctor-put-meaning tops 'mach)
596(doctor-put-meaning pdp11 'mach)
597(doctor-put-meaning computer 'mach)
598(doctor-put-meaning unix 'mach)
599(doctor-put-meaning machine 'mach)
600(doctor-put-meaning computers 'mach)
601(doctor-put-meaning machines 'mach)
602(doctor-put-meaning pdp11s 'mach)
603(doctor-put-meaning foo 'mach)
604(doctor-put-meaning foobar 'mach)
605(doctor-put-meaning multics 'mach)
606(doctor-put-meaning macsyma 'mach)
607(doctor-put-meaning teletype 'mach)
608(doctor-put-meaning la36 'mach)
609(doctor-put-meaning vt52 'mach)
610(doctor-put-meaning zork 'mach)
611(doctor-put-meaning trek 'mach)
612(doctor-put-meaning startrek 'mach)
613(doctor-put-meaning advent 'mach)
614(doctor-put-meaning pdp 'mach)
615(doctor-put-meaning dec 'mach)
616(doctor-put-meaning commodore 'mach)
617(doctor-put-meaning vic 'mach)
618(doctor-put-meaning bbs 'mach)
619(doctor-put-meaning modem 'mach)
620(doctor-put-meaning baud 'mach)
621(doctor-put-meaning macintosh 'mach)
622(doctor-put-meaning vax 'mach)
623(doctor-put-meaning vms 'mach)
624(doctor-put-meaning ibm 'mach)
625(doctor-put-meaning pc 'mach)
626(doctor-put-meaning bitching 'foul)
da4e5ca9 627(doctor-put-meaning shit 'foul)
6679505f
JB
628(doctor-put-meaning bastard 'foul)
629(doctor-put-meaning damn 'foul)
630(doctor-put-meaning damned 'foul)
631(doctor-put-meaning hell 'foul)
632(doctor-put-meaning suck 'foul)
633(doctor-put-meaning sucking 'foul)
634(doctor-put-meaning sux 'foul)
635(doctor-put-meaning ass 'foul)
636(doctor-put-meaning whore 'foul)
637(doctor-put-meaning bitch 'foul)
638(doctor-put-meaning asshole 'foul)
639(doctor-put-meaning shrink 'foul)
640(doctor-put-meaning pot 'toke)
641(doctor-put-meaning grass 'toke)
642(doctor-put-meaning weed 'toke)
643(doctor-put-meaning marijuana 'toke)
644(doctor-put-meaning acapulco 'toke)
645(doctor-put-meaning columbian 'toke)
646(doctor-put-meaning tokin 'toke)
647(doctor-put-meaning joint 'toke)
648(doctor-put-meaning toke 'toke)
649(doctor-put-meaning toking 'toke)
650(doctor-put-meaning tokin\' 'toke)
651(doctor-put-meaning toked 'toke)
652(doctor-put-meaning roach 'toke)
653(doctor-put-meaning pills 'drug)
654(doctor-put-meaning dope 'drug)
655(doctor-put-meaning acid 'drug)
656(doctor-put-meaning lsd 'drug)
657(doctor-put-meaning speed 'drug)
658(doctor-put-meaning heroin 'drug)
659(doctor-put-meaning hash 'drug)
660(doctor-put-meaning cocaine 'drug)
661(doctor-put-meaning uppers 'drug)
662(doctor-put-meaning downers 'drug)
663(doctor-put-meaning loves 'loves)
664(doctor-put-meaning love 'love)
665(doctor-put-meaning loved 'love)
666(doctor-put-meaning hates 'hates)
667(doctor-put-meaning dislikes 'hates)
668(doctor-put-meaning hate 'hate)
669(doctor-put-meaning hated 'hate)
670(doctor-put-meaning dislike 'hate)
671(doctor-put-meaning stoned 'state)
672(doctor-put-meaning drunk 'state)
673(doctor-put-meaning drunken 'state)
674(doctor-put-meaning high 'state)
675(doctor-put-meaning horny 'state)
676(doctor-put-meaning blasted 'state)
677(doctor-put-meaning happy 'state)
678(doctor-put-meaning paranoid 'state)
679(doctor-put-meaning wish 'desire)
680(doctor-put-meaning wishes 'desire)
681(doctor-put-meaning want 'desire)
682(doctor-put-meaning desire 'desire)
683(doctor-put-meaning like 'desire)
684(doctor-put-meaning hope 'desire)
685(doctor-put-meaning hopes 'desire)
686(doctor-put-meaning desires 'desire)
687(doctor-put-meaning wants 'desire)
688(doctor-put-meaning desires 'desire)
689(doctor-put-meaning likes 'desire)
690(doctor-put-meaning needs 'desire)
691(doctor-put-meaning need 'desire)
692(doctor-put-meaning frustrated 'mood)
693(doctor-put-meaning depressed 'mood)
694(doctor-put-meaning annoyed 'mood)
695(doctor-put-meaning upset 'mood)
696(doctor-put-meaning unhappy 'mood)
697(doctor-put-meaning excited 'mood)
698(doctor-put-meaning worried 'mood)
699(doctor-put-meaning lonely 'mood)
700(doctor-put-meaning angry 'mood)
701(doctor-put-meaning mad 'mood)
da4e5ca9 702(doctor-put-meaning pissed 'mood)
6679505f
JB
703(doctor-put-meaning jealous 'mood)
704(doctor-put-meaning afraid 'fear)
705(doctor-put-meaning terrified 'fear)
706(doctor-put-meaning fear 'fear)
707(doctor-put-meaning scared 'fear)
708(doctor-put-meaning frightened 'fear)
709(doctor-put-meaning virginity 'sexnoun)
710(doctor-put-meaning virgins 'sexnoun)
711(doctor-put-meaning virgin 'sexnoun)
712(doctor-put-meaning cock 'sexnoun)
713(doctor-put-meaning cocks 'sexnoun)
714(doctor-put-meaning dick 'sexnoun)
715(doctor-put-meaning dicks 'sexnoun)
da4e5ca9
RS
716(doctor-put-meaning cunt 'sexnoun)
717(doctor-put-meaning cunts 'sexnoun)
6679505f
JB
718(doctor-put-meaning prostitute 'sexnoun)
719(doctor-put-meaning condom 'sexnoun)
720(doctor-put-meaning sex 'sexnoun)
721(doctor-put-meaning rapes 'sexnoun)
722(doctor-put-meaning wife 'family)
723(doctor-put-meaning family 'family)
724(doctor-put-meaning brothers 'family)
725(doctor-put-meaning sisters 'family)
726(doctor-put-meaning parent 'family)
727(doctor-put-meaning parents 'family)
728(doctor-put-meaning brother 'family)
729(doctor-put-meaning sister 'family)
730(doctor-put-meaning father 'family)
731(doctor-put-meaning mother 'family)
732(doctor-put-meaning husband 'family)
733(doctor-put-meaning siblings 'family)
734(doctor-put-meaning grandmother 'family)
735(doctor-put-meaning grandfather 'family)
736(doctor-put-meaning maternal 'family)
737(doctor-put-meaning paternal 'family)
738(doctor-put-meaning stab 'death)
739(doctor-put-meaning murder 'death)
740(doctor-put-meaning murders 'death)
741(doctor-put-meaning suicide 'death)
742(doctor-put-meaning suicides 'death)
743(doctor-put-meaning kill 'death)
744(doctor-put-meaning kills 'death)
f535f6b2 745(doctor-put-meaning killing 'death)
6679505f
JB
746(doctor-put-meaning die 'death)
747(doctor-put-meaning dies 'death)
748(doctor-put-meaning died 'death)
749(doctor-put-meaning dead 'death)
750(doctor-put-meaning death 'death)
751(doctor-put-meaning deaths 'death)
752(doctor-put-meaning pain 'symptoms)
753(doctor-put-meaning ache 'symptoms)
754(doctor-put-meaning fever 'symptoms)
755(doctor-put-meaning sore 'symptoms)
756(doctor-put-meaning aching 'symptoms)
757(doctor-put-meaning stomachache 'symptoms)
758(doctor-put-meaning headache 'symptoms)
759(doctor-put-meaning hurts 'symptoms)
760(doctor-put-meaning disease 'symptoms)
761(doctor-put-meaning virus 'symptoms)
762(doctor-put-meaning vomit 'symptoms)
763(doctor-put-meaning vomiting 'symptoms)
764(doctor-put-meaning barf 'symptoms)
765(doctor-put-meaning toothache 'symptoms)
766(doctor-put-meaning hurt 'symptoms)
767(doctor-put-meaning rum 'alcohol)
768(doctor-put-meaning gin 'alcohol)
769(doctor-put-meaning vodka 'alcohol)
770(doctor-put-meaning alcohol 'alcohol)
771(doctor-put-meaning bourbon 'alcohol)
772(doctor-put-meaning beer 'alcohol)
773(doctor-put-meaning wine 'alcohol)
774(doctor-put-meaning whiskey 'alcohol)
775(doctor-put-meaning scotch 'alcohol)
da4e5ca9
RS
776(doctor-put-meaning fuck 'sexverb)
777(doctor-put-meaning fucked 'sexverb)
6679505f
JB
778(doctor-put-meaning screw 'sexverb)
779(doctor-put-meaning screwing 'sexverb)
da4e5ca9 780(doctor-put-meaning fucking 'sexverb)
6679505f
JB
781(doctor-put-meaning rape 'sexverb)
782(doctor-put-meaning raped 'sexverb)
783(doctor-put-meaning kiss 'sexverb)
784(doctor-put-meaning kissing 'sexverb)
785(doctor-put-meaning kisses 'sexverb)
786(doctor-put-meaning screws 'sexverb)
da4e5ca9 787(doctor-put-meaning fucks 'sexverb)
6679505f
JB
788(doctor-put-meaning because 'conj)
789(doctor-put-meaning but 'conj)
790(doctor-put-meaning however 'conj)
791(doctor-put-meaning besides 'conj)
792(doctor-put-meaning anyway 'conj)
793(doctor-put-meaning that 'conj)
794(doctor-put-meaning except 'conj)
795(doctor-put-meaning why 'conj)
796(doctor-put-meaning how 'conj)
797(doctor-put-meaning until 'when)
798(doctor-put-meaning when 'when)
799(doctor-put-meaning whenever 'when)
800(doctor-put-meaning while 'when)
801(doctor-put-meaning since 'when)
802(doctor-put-meaning rms 'rms)
803(doctor-put-meaning stallman 'rms)
804(doctor-put-meaning school 'school)
805(doctor-put-meaning schools 'school)
806(doctor-put-meaning skool 'school)
807(doctor-put-meaning grade 'school)
808(doctor-put-meaning grades 'school)
809(doctor-put-meaning teacher 'school)
810(doctor-put-meaning teachers 'school)
811(doctor-put-meaning classes 'school)
812(doctor-put-meaning professor 'school)
813(doctor-put-meaning prof 'school)
814(doctor-put-meaning profs 'school)
815(doctor-put-meaning professors 'school)
816(doctor-put-meaning mit 'school)
817(doctor-put-meaning emacs 'eliza)
818(doctor-put-meaning eliza 'eliza)
819(doctor-put-meaning liza 'eliza)
820(doctor-put-meaning elisa 'eliza)
821(doctor-put-meaning weizenbaum 'eliza)
822(doctor-put-meaning doktor 'eliza)
eb8c3be9 823(doctor-put-meaning athletics 'sports)
6679505f
JB
824(doctor-put-meaning baseball 'sports)
825(doctor-put-meaning basketball 'sports)
826(doctor-put-meaning football 'sports)
827(doctor-put-meaning frisbee 'sports)
828(doctor-put-meaning gym 'sports)
829(doctor-put-meaning gymnastics 'sports)
830(doctor-put-meaning hockey 'sports)
831(doctor-put-meaning lacrosse 'sports)
832(doctor-put-meaning soccer 'sports)
833(doctor-put-meaning softball 'sports)
834(doctor-put-meaning sports 'sports)
835(doctor-put-meaning swimming 'sports)
836(doctor-put-meaning swim 'sports)
837(doctor-put-meaning tennis 'sports)
838(doctor-put-meaning volleyball 'sports)
839(doctor-put-meaning math 'math)
840(doctor-put-meaning mathematics 'math)
841(doctor-put-meaning mathematical 'math)
842(doctor-put-meaning theorem 'math)
843(doctor-put-meaning axiom 'math)
844(doctor-put-meaning lemma 'math)
845(doctor-put-meaning algebra 'math)
846(doctor-put-meaning algebraic 'math)
847(doctor-put-meaning trig 'math)
848(doctor-put-meaning trigonometry 'math)
849(doctor-put-meaning trigonometric 'math)
850(doctor-put-meaning geometry 'math)
851(doctor-put-meaning geometric 'math)
852(doctor-put-meaning calculus 'math)
853(doctor-put-meaning arithmetic 'math)
854(doctor-put-meaning zippy 'zippy)
855(doctor-put-meaning zippy 'zippy)
856(doctor-put-meaning pinhead 'zippy)
857(doctor-put-meaning chat 'chat)
858\f
859;;;###autoload
860(defun doctor ()
861 "Switch to *doctor* buffer and start giving psychotherapy."
862 (interactive)
863 (switch-to-buffer "*doctor*")
864 (doctor-mode))
865
866(defun doctor-ret-or-read (arg)
867 "Insert a newline if preceding character is not a newline.
868Otherwise call the Doctor to parse preceding sentence."
869 (interactive "*p")
870 (if (= (preceding-char) ?\n)
871 (doctor-read-print)
872 (newline arg)))
873
874(defun doctor-read-print nil
875 "top level loop"
876 (interactive)
877 (let ((sent (doctor-readin)))
878 (insert "\n")
879 (setq lincount (1+ lincount))
880 (doctor-doc sent)
881 (insert "\n")
882 (setq bak sent)))
883
884(defun doctor-readin nil
885 "Read a sentence. Return it as a list of words."
886 (let (sentence)
887 (backward-sentence 1)
888 (while (not (eobp))
889 (setq sentence (append sentence (list (doctor-read-token)))))
890 sentence))
891
892(defun doctor-read-token ()
893 "read one word from buffer"
894 (prog1 (intern (downcase (buffer-substring (point)
895 (progn
896 (forward-word 1)
897 (point)))))
898 (re-search-forward "\\Sw*")))
899\f
900;; Main processing function for sentences that have been read.
901
902(defun doctor-doc (sent)
903 (cond
904 ((equal sent '(foo))
a3e58c1a 905 (doctor-type '(bar! (doc$ please)(doc$ continue) \.)))
6679505f 906 ((member sent howareyoulst)
a3e58c1a 907 (doctor-type '(i\'m ok \. (doc$ describe) yourself \.)))
6679505f
JB
908 ((or (member sent '((good bye) (see you later) (i quit) (so long)
909 (go away) (get lost)))
910 (memq (car sent)
a1506d29 911 '(bye halt break quit done exit goodbye
6679505f 912 bye\, stop pause goodbye\, stop pause)))
a3e58c1a 913 (doctor-type (doc$ bye)))
6679505f 914 ((and (eq (car sent) 'you)
454473ea
JPW
915 (memq (cadr sent) abusewords))
916 (setq found (cadr sent))
a3e58c1a 917 (doctor-type (doc$ abuselst)))
6679505f 918 ((eq (car sent) 'whatmeans)
454473ea 919 (doctor-def (cadr sent)))
6679505f
JB
920 ((equal sent '(parse))
921 (doctor-type (list 'subj '= subj ", "
922 'verb '= verb "\n"
923 'object 'phrase '= obj ","
924 'noun 'form '= object "\n"
925 'current 'keyword 'is found
926 ", "
927 'most 'recent 'possessive
928 'is owner "\n"
929 'sentence 'used 'was
930 "..."
a3e58c1a 931 '(doc// bak))))
daa6ddb5 932 ((memq (car sent) '(are is do has have how when where who why))
a3e58c1a 933 (doctor-type (doc$ qlist)))
6679505f 934 ;; ((eq (car sent) 'forget)
454473ea 935 ;; (set (cadr sent) nil)
a3e58c1a
JPW
936 ;; (doctor-type '((doc$ isee)(doc$ please)
937 ;; (doc$ continue)\.)))
6679505f
JB
938 (t
939 (if (doctor-defq sent) (doctor-define sent found))
27664fbe 940 (if (> (length sent) 12)(setq sent (doctor-shorten sent)))
6679505f
JB
941 (setq sent (doctor-correct-spelling (doctor-replace sent replist)))
942 (cond ((and (not (memq 'me sent))(not (memq 'i sent))
943 (memq 'am sent))
944 (setq sent (doctor-replace sent '((am . (are)))))))
945 (cond ((equal (car sent) 'yow) (doctor-zippy))
946 ((< (length sent) 2)
947 (cond ((eq (doctor-meaning (car sent)) 'howdy)
948 (doctor-howdy))
949 (t (doctor-short))))
950 (t
951 (if (memq 'am sent)
952 (setq sent (doctor-replace sent '((me . (i))))))
953 (setq sent (doctor-fixup sent))
454473ea 954 (if (and (eq (car sent) 'do) (eq (cadr sent) 'not))
6679505f 955 (cond ((zerop (random 3))
a3e58c1a 956 (doctor-type '(are you (doc$ afraidof) that \?)))
6679505f
JB
957 ((zerop (random 2))
958 (doctor-type '(don\'t tell me what to do \. i am the
a8bccd82 959 doctor here!))
6679505f
JB
960 (doctor-rthing))
961 (t
a3e58c1a 962 (doctor-type '((doc$ whysay) that i shouldn\'t
454473ea 963 (cddr sent)
6679505f
JB
964 \?))))
965 (doctor-go (doctor-wherego sent))))))))
966\f
967;; Things done to process sentences once read.
968
969(defun doctor-correct-spelling (sent)
970 "Correct the spelling and expand each word in sentence."
971 (if sent
7382bcae 972 (apply 'append (mapcar (lambda (word)
6679505f
JB
973 (if (memq word typos)
974 (get (get word 'doctor-correction) 'doctor-expansion)
975 (list word)))
976 sent))))
977
978(defun doctor-shorten (sent)
eb8c3be9 979 "Make a sentence manageably short using a few hacks."
6679505f 980 (let (foo
27664fbe 981 (retval sent)
6679505f
JB
982 (temp '(because but however besides anyway until
983 while that except why how)))
984 (while temp
985 (setq foo (memq (car temp) sent))
986 (if (and foo
987 (> (length foo) 3))
27664fbe
RS
988 (setq retval (doctor-fixup foo)
989 temp nil)
6679505f
JB
990 (setq temp (cdr temp))))
991 retval))
992
993(defun doctor-define (sent found)
994 (doctor-svo sent found 1 nil)
995 (and
996 (doctor-nounp subj)
997 (not (doctor-pronounp subj))
998 subj
999 (doctor-meaning object)
1000 (put subj 'doctor-meaning (doctor-meaning object))
1001 t))
1002
1003(defun doctor-defq (sent)
1004 "Set global var FOUND to first keyword found in sentence SENT."
1005 (setq found nil)
1006 (let ((temp '(means applies mean refers refer related
1007 similar defined associated linked like same)))
1008 (while temp
1009 (if (memq (car temp) sent)
1010 (setq found (car temp)
1011 temp nil)
1012 (setq temp (cdr temp)))))
1013 found)
1014
1015(defun doctor-def (x)
1016 (progn
a1506d29 1017 (doctor-type (list 'the 'word x 'means (doctor-meaning x) 'to 'me))
6679505f
JB
1018 nil))
1019
1020(defun doctor-forget ()
1021 "Delete the last element of the history list."
1022 (setq history (reverse (cdr (reverse history)))))
1023
1024(defun doctor-query (x)
1025 "Prompt for a line of input from the minibuffer until a noun or verb is seen.
1026Put dialogue in buffer."
1027 (let (a
1028 (prompt (concat (doctor-make-string x)
1029 " what \? "))
1030 retval)
1031 (while (not retval)
1032 (while (not a)
1033 (insert ?\n
1034 prompt
1035 (read-string prompt)
1036 ?\n)
1037 (setq a (doctor-readin)))
1038 (while (and a (not retval))
1039 (cond ((doctor-nounp (car a))
1040 (setq retval (car a)))
1041 ((doctor-verbp (car a))
1042 (setq retval (doctor-build
1043 (doctor-build x " ")
1044 (car a))))
1045 ((setq a (cdr a))))))
1046 retval))
1047
1048(defun doctor-subjsearch (sent key type)
1049 "Search for the subject of a sentence SENT, looking for the noun closest
1050to and preceding KEY by at least TYPE words. Set global variable subj to
1051the subject noun, and return the portion of the sentence following it."
1052 (let ((i (- (length sent) (length (memq key sent)) type)))
1053 (while (and (> i -1) (not (doctor-nounp (nth i sent))))
1054 (setq i (1- i)))
1055 (cond ((> i -1)
1056 (setq subj (nth i sent))
1057 (nthcdr (1+ i) sent))
1058 (t
1059 (setq subj 'you)
1060 nil))))
1061
1062(defun doctor-nounp (x)
1063 "Returns t if the symbol argument is a noun."
1064 (or (doctor-pronounp x)
1065 (not (or (doctor-verbp x)
1066 (equal x 'not)
1067 (doctor-prepp x)
1068 (doctor-modifierp x) )) ))
1069
1070(defun doctor-pronounp (x)
1071 "Returns t if the symbol argument is a pronoun."
1072 (memq x '(
1073 i me mine myself
1074 we us ours ourselves ourself
1075 you yours yourself yourselves
1076 he him himself she hers herself
1077 it that those this these things thing
1078 they them themselves theirs
1079 anybody everybody somebody
1080 anyone everyone someone
1081 anything something everything)))
1082
0ff22356
SM
1083(dolist (x
1084 '(abort aborted aborts ask asked asks am
1085 applied applies apply are associate
1086 associated ate
1087 be became become becomes becoming
1088 been being believe believed believes
1089 bit bite bites bore bored bores boring bought buy buys buying
1090 call called calling calls came can caught catch come
1091 contract contracted contracts control controlled controls
1092 could croak croaks croaked cut cuts
1093 dare dared define defines dial dialed dials did die died dies
1094 dislike disliked
1095 dislikes do does drank drink drinks drinking
1096 drive drives driving drove dying
1097 eat eating eats expand expanded expands
1098 expect expected expects expel expels expelled
1099 explain explained explains
1100 fart farts feel feels felt fight fights find finds finding
1101 forget forgets forgot fought found
1102 fuck fucked fucking fucks
1103 gave get gets getting give gives go goes going gone got gotten
1104 had harm harms has hate hated hates have having
1105 hear heard hears hearing help helped helping helps
1106 hit hits hope hoped hopes hurt hurts
1107 implies imply is
1108 join joined joins jump jumped jumps
1109 keep keeping keeps kept
1110 kill killed killing kills kiss kissed kisses kissing
1111 knew know knows
1112 laid lay lays let lets lie lied lies like liked likes
1113 liking listen listens
1114 login look looked looking looks
1115 lose losing lost
1116 love loved loves loving
1117 luse lusing lust lusts
1118 made make makes making may mean means meant might
1119 move moved moves moving must
1120 need needed needs
1121 order ordered orders ought
1122 paid pay pays pick picked picking picks
1123 placed placing prefer prefers put puts
1124 ran rape raped rapes
1125 read reading reads recall receive received receives
1126 refer refered referred refers
1127 relate related relates remember remembered remembers
1128 romp romped romps run running runs
1129 said sang sat saw say says
1130 screw screwed screwing screws scrod see sees seem seemed
1131 seems seen sell selling sells
1132 send sendind sends sent shall shoot shot should
1133 sing sings sit sits sitting sold studied study
1134 take takes taking talk talked talking talks tell tells telling
1135 think thinks
1136 thought told took tooled touch touched touches touching
1137 transfer transferred transfers transmit transmits transmitted
1138 type types types typing
1139 walk walked walking walks want wanted wants was watch
1140 watched watching went were will wish would work worked works
1141 write writes writing wrote use used uses using))
1142 (put x 'doctor-sentence-type 'verb))
6679505f
JB
1143
1144(defun doctor-verbp (x) (if (symbolp x)
1145 (eq (get x 'doctor-sentence-type) 'verb)))
1146
1147(defun doctor-plural (x)
1148 "Form the plural of the word argument."
1149 (let ((foo (doctor-make-string x)))
1150 (cond ((string-equal (substring foo -1) "s")
1151 (cond ((string-equal (substring foo -2 -1) "s")
1152 (intern (concat foo "es")))
1153 (t x)))
1154 ((string-equal (substring foo -1) "y")
1155 (intern (concat (substring foo 0 -1)
1156 "ies")))
1157 (t (intern (concat foo "s"))))))
1158
1159(defun doctor-setprep (sent key)
1160 (let ((val)
1161 (foo (memq key sent)))
454473ea
JPW
1162 (cond ((doctor-prepp (cadr foo))
1163 (setq val (doctor-getnoun (cddr foo)))
6679505f
JB
1164 (cond (val val)
1165 (t 'something)))
454473ea
JPW
1166 ((doctor-articlep (cadr foo))
1167 (setq val (doctor-getnoun (cddr foo)))
1168 (cond (val (doctor-build (doctor-build (cadr foo) " ") val))
6679505f
JB
1169 (t 'something)))
1170 (t 'something))))
1171
1172(defun doctor-getnoun (x)
1173 (cond ((null x)(setq object 'something))
1174 ((atom x)(setq object x))
1175 ((eq (length x) 1)
1176 (setq object (cond
1177 ((doctor-nounp (setq object (car x))) object)
1178 (t (doctor-query object)))))
1179 ((eq (car x) 'to)
1180 (doctor-build 'to\ (doctor-getnoun (cdr x))))
1181 ((doctor-prepp (car x))
1182 (doctor-getnoun (cdr x)))
1183 ((not (doctor-nounp (car x)))
1184 (doctor-build (doctor-build (cdr (assq (car x)
1185 (append
1186 '((a . this)
1187 (some . this)
1188 (one . that))
1189 (list
1190 (cons
1191 (car x) (car x))))))
1192 " ")
1193 (doctor-getnoun (cdr x))))
daa6ddb5
RS
1194 (t (setq object (car x))
1195 (doctor-build (doctor-build (car x) " ") (doctor-getnoun (cdr x))))
1196 ))
6679505f
JB
1197
1198(defun doctor-modifierp (x)
1199 (or (doctor-adjectivep x)
1200 (doctor-adverbp x)
1201 (doctor-othermodifierp x)))
1202
1203(defun doctor-adjectivep (x)
1204 (or (numberp x)
1205 (doctor-nmbrp x)
1206 (doctor-articlep x)
1207 (doctor-colorp x)
1208 (doctor-sizep x)
1209 (doctor-possessivepronounp x)))
1210
1211(defun doctor-adverbp (xx)
b8797e1f
RS
1212 (let ((xxstr (doctor-make-string xx)))
1213 (and (>= (length xxstr) 2)
1214 (string-equal (substring (doctor-make-string xx) -2) "ly"))))
6679505f
JB
1215
1216(defun doctor-articlep (x)
1217 (memq x '(the a an)))
1218
1219(defun doctor-nmbrp (x)
1220 (memq x '(one two three four five six seven eight nine ten
1221 eleven twelve thirteen fourteen fifteen
1222 sixteen seventeen eighteen nineteen
1223 twenty thirty forty fifty sixty seventy eighty ninety
1224 hundred thousand million billion
1225 half quarter
1226 first second third fourth fifth
eb8c3be9 1227 sixth seventh eighth ninth tenth)))
a1506d29 1228
6679505f
JB
1229(defun doctor-colorp (x)
1230 (memq x '(beige black blue brown crimson
1231 gray grey green
1232 orange pink purple red tan tawny
1233 violet white yellow)))
1234
1235(defun doctor-sizep (x)
1236 (memq x '(big large tall fat wide thick
1237 small petite short thin skinny)))
1238
1239(defun doctor-possessivepronounp (x)
1240 (memq x '(my your his her our their)))
1241
1242(defun doctor-othermodifierp (x)
1243 (memq x '(all also always amusing any anyway associated awesome
1244 bad beautiful best better but certain clear
1245 ever every fantastic fun funny
0f668406 1246 good great grody gross however if ignorant
6679505f
JB
1247 less linked losing lusing many more much
1248 never nice obnoxious often poor pretty real related rich
1249 similar some stupid super superb
1250 terrible terrific too total tubular ugly very)))
1251
1252(defun doctor-prepp (x)
1253 (memq x '(about above after around as at
1254 before beneath behind beside between by
1255 for from in inside into
1256 like near next of on onto over
1257 same through thru to toward towards
1258 under underneath with without)))
1259
1260(defun doctor-remember (thing)
1261 (cond ((null history)
1262 (setq history (list thing)))
1263 (t (setq history (append history (list thing))))))
1264
1265(defun doctor-type (x)
1266 (setq x (doctor-fix-2 x))
1267 (doctor-txtype (doctor-assm x)))
1268
1269(defun doctor-fixup (sent)
1270 (setq sent (append
1271 (cdr
1272 (assq (car sent)
1273 (append
1274 '((me i)
1275 (him he)
1276 (her she)
1277 (them they)
1278 (okay)
1279 (well)
1280 (sigh)
1281 (hmm)
1282 (hmmm)
1283 (hmmmm)
1284 (hmmmmm)
1285 (gee)
1286 (sure)
1287 (great)
1288 (oh)
1289 (fine)
1290 (ok)
1291 (no))
1292 (list (list (car sent)
1293 (car sent))))))
1294 (cdr sent)))
1295 (doctor-fix-2 sent))
1296
1297(defun doctor-fix-2 (sent)
1298 (let ((foo sent))
1299 (while foo
1300 (if (and (eq (car foo) 'me)
454473ea 1301 (doctor-verbp (cadr foo)))
6679505f
JB
1302 (rplaca foo 'i)
1303 (cond ((eq (car foo) 'you)
454473ea 1304 (cond ((memq (cadr foo) '(am be been is))
6679505f 1305 (rplaca (cdr foo) 'are))
454473ea 1306 ((memq (cadr foo) '(has))
6679505f 1307 (rplaca (cdr foo) 'have))
454473ea 1308 ((memq (cadr foo) '(was))
6679505f
JB
1309 (rplaca (cdr foo) 'were))))
1310 ((equal (car foo) 'i)
454473ea 1311 (cond ((memq (cadr foo) '(are is be been))
6679505f 1312 (rplaca (cdr foo) 'am))
454473ea 1313 ((memq (cadr foo) '(were))
6679505f 1314 (rplaca (cdr foo) 'was))
454473ea 1315 ((memq (cadr foo) '(has))
6679505f
JB
1316 (rplaca (cdr foo) 'have))))
1317 ((and (doctor-verbp (car foo))
454473ea
JPW
1318 (eq (cadr foo) 'i)
1319 (not (doctor-verbp (car (cddr foo)))))
6679505f
JB
1320 (rplaca (cdr foo) 'me))
1321 ((and (eq (car foo) 'a)
1322 (doctor-vowelp (string-to-char
454473ea 1323 (doctor-make-string (cadr foo)))))
6679505f
JB
1324 (rplaca foo 'an))
1325 ((and (eq (car foo) 'an)
1326 (not (doctor-vowelp (string-to-char
454473ea 1327 (doctor-make-string (cadr foo))))))
6679505f
JB
1328 (rplaca foo 'a)))
1329 (setq foo (cdr foo))))
1330 sent))
1331
1332(defun doctor-vowelp (x)
1333 (memq x '(?a ?e ?i ?o ?u)))
1334
1335(defun doctor-replace (sent rlist)
1336 "Replace any element of SENT that is the car of a replacement
1337element pair in RLIST."
1338 (apply 'append
1339 (mapcar
1340 (function
1341 (lambda (x)
1342 (cdr (or (assq x rlist) ; either find a replacement
1343 (list x x))))) ; or fake an identity mapping
1344 sent)))
1345
1346(defun doctor-wherego (sent)
a3e58c1a 1347 (cond ((null sent)(doc$ whereoutp))
6679505f
JB
1348 ((null (doctor-meaning (car sent)))
1349 (doctor-wherego (cond ((zerop (random 2))
1350 (reverse (cdr sent)))
1351 (t (cdr sent)))))
1352 (t
1353 (setq found (car sent))
1354 (doctor-meaning (car sent)))))
1355
1356(defun doctor-svo (sent key type mem)
1357 "Find subject, verb and object in sentence SENT with focus on word KEY.
1358TYPE is number of words preceding KEY to start looking for subject.
1359MEM is t if results are to be put on Doctor's memory stack.
1360Return in the global variables SUBJ, VERB and OBJECT."
4746118a 1361 (let ((foo (doctor-subjsearch sent key type)))
6679505f
JB
1362 (or foo
1363 (setq foo sent
1364 mem nil))
1365 (while (and (null (doctor-verbp (car foo))) (cdr foo))
1366 (setq foo (cdr foo)))
1367 (setq verb (car foo))
1368 (setq obj (doctor-getnoun (cdr foo)))
1369 (cond ((eq object 'i)(setq object 'me))
1370 ((eq subj 'me)(setq subj 'i)))
1371 (cond (mem (doctor-remember (list subj verb obj))))))
1372
1373(defun doctor-possess (sent key)
1374 "Set possessive in SENT for keyword KEY.
1375Hack on previous word, setting global variable OWNER to correct result."
1376 (let* ((i (- (length sent) (length (memq key sent)) 1))
1377 (prev (if (< i 0) 'your
1378 (nth i sent))))
1379 (setq owner (if (or (doctor-possessivepronounp prev)
1380 (string-equal "s"
1381 (substring (doctor-make-string prev)
1382 -1)))
1383 prev
1384 'your))))
1385\f
1386;; Output of replies.
1387
1388(defun doctor-txtype (ans)
1389 "Output to buffer a list of symbols or strings as a sentence."
1390 (setq *print-upcase* t *print-space* nil)
0ff22356 1391 (mapc 'doctor-type-symbol ans)
6679505f
JB
1392 (insert "\n"))
1393
1394(defun doctor-type-symbol (word)
1395 "Output a symbol to the buffer with some fancy case and spacing hacks."
1396 (setq word (doctor-make-string word))
1397 (if (string-equal word "i") (setq word "I"))
1398 (if *print-upcase*
1399 (progn
1400 (setq word (capitalize word))
1401 (if *print-space*
1402 (insert " "))))
1403 (cond ((or (string-match "^[.,;:?! ]" word)
1404 (not *print-space*))
1405 (insert word))
6f08431c 1406 (t (insert ?\s word)))
a1982090
RS
1407 (and auto-fill-function
1408 (> (current-column) fill-column)
1409 (apply auto-fill-function nil))
6679505f
JB
1410 (setq *print-upcase* (string-match "[.?!]$" word)
1411 *print-space* t))
1412
1413(defun doctor-build (str1 str2)
1414 "Make a symbol out of the concatenation of the two non-list arguments."
1415 (cond ((null str1) str2)
1416 ((null str2) str1)
1417 ((and (atom str1)
1418 (atom str2))
1419 (intern (concat (doctor-make-string str1)
1420 (doctor-make-string str2))))
1421 (t nil)))
1422
1423(defun doctor-make-string (obj)
1424 (cond ((stringp obj) obj)
1425 ((symbolp obj) (symbol-name obj))
1426 ((numberp obj) (int-to-string obj))
1427 (t "")))
1428
1429(defun doctor-concat (x y)
1430 "Like append, but force atomic arguments to be lists."
1431 (append
1432 (if (and x (atom x)) (list x) x)
1433 (if (and y (atom y)) (list y) y)))
1434
1435(defun doctor-assm (proto)
1436 (cond ((null proto) nil)
1437 ((atom proto) (list proto))
1438 ((atom (car proto))
1439 (cons (car proto) (doctor-assm (cdr proto))))
1440 (t (doctor-concat (doctor-assm (eval (car proto))) (doctor-assm (cdr proto))))))
1441\f
1442;; Functions that handle specific words or meanings when found.
1443
1444(defun doctor-go (destination)
1445 "Call a `doctor-*' function."
1446 (funcall (intern (concat "doctor-" (doctor-make-string destination)))))
1447
1448(defun doctor-desire1 ()
a3e58c1a 1449 (doctor-go (doc$ whereoutp)))
6679505f
JB
1450
1451(defun doctor-huh ()
a3e58c1a
JPW
1452 (cond ((< (length sent) 9) (doctor-type (doc$ huhlst)))
1453 (t (doctor-type (doc$ longhuhlst)))))
6679505f 1454
a3e58c1a 1455(defun doctor-rthing () (doctor-type (doc$ thlst)))
6679505f
JB
1456
1457(defun doctor-remem () (cond ((null history)(doctor-huh))
a3e58c1a 1458 ((doctor-type (doc$ remlst)))))
6679505f
JB
1459
1460(defun doctor-howdy ()
1461 (cond ((not howdyflag)
a3e58c1a 1462 (doctor-type '((doc$ hello) what brings you to see me \?))
6679505f
JB
1463 (setq howdyflag t))
1464 (t
a3e58c1a
JPW
1465 (doctor-type '((doc$ ibelieve) we\'ve introduced ourselves already \.))
1466 (doctor-type '((doc$ please) (doc$ describe) (doc$ things) \.)))))
6679505f
JB
1467
1468(defun doctor-when ()
1469 (cond ((< (length (memq found sent)) 3)(doctor-short))
1470 (t
1471 (setq sent (cdr (memq found sent)))
1472 (setq sent (doctor-fixup sent))
a3e58c1a 1473 (doctor-type '((doc$ whatwhen)(doc// sent) \?)))))
6679505f
JB
1474
1475(defun doctor-conj ()
1476 (cond ((< (length (memq found sent)) 4)(doctor-short))
1477 (t
1478 (setq sent (cdr (memq found sent)))
1479 (setq sent (doctor-fixup sent))
1480 (cond ((eq (car sent) 'of)
a3e58c1a 1481 (doctor-type '(are you (doc$ sure) that is the real reason \?))
6679505f
JB
1482 (setq things (cons (cdr sent) things)))
1483 (t
1484 (doctor-remember sent)
a3e58c1a 1485 (doctor-type (doc$ beclst)))))))
6679505f
JB
1486
1487(defun doctor-short ()
1488 (cond ((= (car repetitive-shortness) (1- lincount))
1489 (rplacd repetitive-shortness
1490 (1+ (cdr repetitive-shortness))))
1491 (t
1492 (rplacd repetitive-shortness 1)))
1493 (rplaca repetitive-shortness lincount)
1494 (cond ((> (cdr repetitive-shortness) 6)
1495 (cond ((not **mad**)
a3e58c1a 1496 (doctor-type '((doc$ areyou)
6679505f
JB
1497 just trying to see what kind of things
1498 i have in my vocabulary \? please try to
1499 carry on a reasonable conversation!))
1500 (setq **mad** t))
1501 (t
1502 (doctor-type '(i give up \. you need a lesson in creative
1503 writing \.\.\.))
6679505f
JB
1504 )))
1505 (t
1506 (cond ((equal sent (doctor-assm '(yes)))
a3e58c1a 1507 (doctor-type '((doc$ isee) (doc$ inter) (doc$ whysay) this is so \?)))
6679505f 1508 ((equal sent (doctor-assm '(because)))
a3e58c1a 1509 (doctor-type (doc$ shortbeclst)))
6679505f 1510 ((equal sent (doctor-assm '(no)))
a3e58c1a
JPW
1511 (doctor-type (doc$ neglst)))
1512 (t (doctor-type (doc$ shortlst)))))))
a1506d29 1513
a3e58c1a 1514(defun doctor-alcohol () (doctor-type (doc$ drnk)))
6679505f
JB
1515
1516(defun doctor-desire ()
1517 (let ((foo (memq found sent)))
1518 (cond ((< (length foo) 2)
1519 (doctor-go (doctor-build (doctor-meaning found) 1)))
454473ea 1520 ((memq (cadr foo) '(a an))
6679505f
JB
1521 (rplacd foo (append '(to have) (cdr foo)))
1522 (doctor-svo sent found 1 nil)
1523 (doctor-remember (list subj 'would 'like obj))
a3e58c1a 1524 (doctor-type (doc$ whywant)))
454473ea 1525 ((not (eq (cadr foo) 'to))
6679505f
JB
1526 (doctor-go (doctor-build (doctor-meaning found) 1)))
1527 (t
1528 (doctor-svo sent found 1 nil)
1529 (doctor-remember (list subj 'would 'like obj))
a3e58c1a 1530 (doctor-type (doc$ whywant))))))
6679505f
JB
1531
1532(defun doctor-drug ()
a3e58c1a 1533 (doctor-type (doc$ drugs))
6679505f
JB
1534 (doctor-remember (list 'you 'used found)))
1535
1536(defun doctor-toke ()
a3e58c1a 1537 (doctor-type (doc$ toklst)))
6679505f
JB
1538
1539(defun doctor-state ()
a3e58c1a 1540 (doctor-type (doc$ states))(doctor-remember (list 'you 'were found)))
6679505f
JB
1541
1542(defun doctor-mood ()
a3e58c1a 1543 (doctor-type (doc$ moods))(doctor-remember (list 'you 'felt found)))
6679505f
JB
1544
1545(defun doctor-fear ()
1546 (setq feared (doctor-setprep sent found))
a3e58c1a 1547 (doctor-type (doc$ fears))
6679505f
JB
1548 (doctor-remember (list 'you 'were 'afraid 'of feared)))
1549
1550(defun doctor-hate ()
1551 (doctor-svo sent found 1 t)
1552 (cond ((memq 'not sent) (doctor-forget) (doctor-huh))
1553 ((equal subj 'you)
a3e58c1a
JPW
1554 (doctor-type '(why do you (doc// verb)(doc// obj) \?)))
1555 (t (doctor-type '((doc$ whysay)(list subj verb obj))))))
6679505f
JB
1556
1557(defun doctor-symptoms ()
a8bccd82
RS
1558 (doctor-type '((doc$ maybe) you should consult a medical doctor\;
1559 i am a psychotherapist. \.)))
6679505f
JB
1560
1561(defun doctor-hates ()
1562 (doctor-svo sent found 1 t)
1563 (doctor-hates1))
1564
1565(defun doctor-hates1 ()
a3e58c1a 1566 (doctor-type '((doc$ whysay)(list subj verb obj) \?)))
6679505f
JB
1567
1568(defun doctor-loves ()
1569 (doctor-svo sent found 1 t)
1570 (doctor-qloves))
1571
1572(defun doctor-qloves ()
a3e58c1a 1573 (doctor-type '((doc$ bother)(list subj verb obj) \?)))
6679505f
JB
1574
1575(defun doctor-love ()
1576 (doctor-svo sent found 1 t)
1577 (cond ((memq 'not sent) (doctor-forget) (doctor-huh))
1578 ((memq 'to sent) (doctor-hates1))
1579 (t
1580 (cond ((equal object 'something)
1581 (setq object '(this person you love))))
1582 (cond ((equal subj 'you)
1583 (setq lover obj)
1584 (cond ((equal lover '(this person you love))
1585 (setq lover '(your partner))
1586 (doctor-forget)
1587 (doctor-type '(with whom are you in love \?)))
a3e58c1a
JPW
1588 ((doctor-type '((doc$ please)
1589 (doc$ describe)
1590 (doc$ relation)
1591 (doc// lover)
6679505f
JB
1592 \.)))))
1593 ((equal subj 'i)
1594 (doctor-txtype '(we were discussing you!)))
1595 (t (doctor-forget)
1596 (setq obj 'someone)
1597 (setq verb (doctor-build verb 's))
1598 (doctor-qloves))))))
1599
1600(defun doctor-mach ()
1601 (setq found (doctor-plural found))
a3e58c1a 1602 (doctor-type (doc$ machlst)))
6679505f
JB
1603
1604(defun doctor-sexnoun () (doctor-sexverb))
1605
1606(defun doctor-sexverb ()
1607 (if (or (memq 'me sent)(memq 'myself sent)(memq 'i sent))
1608 (doctor-foul)
a3e58c1a 1609 (doctor-type (doc$ sexlst))))
6679505f 1610
f535f6b2 1611(defun doctor-death ()
a3e58c1a 1612 (cond (suicide-flag (doctor-type (doc$ deathlst)))
f535f6b2
RS
1613 ((or (equal found 'suicide)
1614 (and (or (equal found 'kill)
1615 (equal found 'killing))
1616 (memq 'yourself sent)))
1617 (setq suicide-flag t)
1618 (doctor-type '(If you are really suicidal, you might
1619 want to contact the Samaritans via
1620 E-mail: jo@samaritans.org or, at your option,
e597d8fb
GM
1621 anonymous E-mail: samaritans@anon.twwells.com\ \.
1622 or find a Befrienders crisis center at
1623 http://www.befrienders.org/\ \.
a3e58c1a
JPW
1624 (doc$ please) (doc$ continue) \.)))
1625 (t (doctor-type (doc$ deathlst)))))
6679505f
JB
1626
1627(defun doctor-foul ()
a3e58c1a 1628 (doctor-type (doc$ foullst)))
6679505f
JB
1629
1630(defun doctor-family ()
1631 (doctor-possess sent found)
a3e58c1a 1632 (doctor-type (doc$ famlst)))
6679505f
JB
1633
1634;; I did not add this -- rms.
1635;; But he might have removed it. I put it back. --roland
1636(defun doctor-rms ()
a3e58c1a 1637 (cond (rms-flag (doctor-type (doc$ stallmanlst)))
6679505f
JB
1638 (t (setq rms-flag t) (doctor-type '(do you know Stallman \?)))))
1639
a3e58c1a 1640(defun doctor-school nil (doctor-type (doc$ schoollst)))
6679505f
JB
1641
1642(defun doctor-eliza ()
a3e58c1a 1643 (cond (eliza-flag (doctor-type (doc$ elizalst)))
6679505f 1644 (t (setq eliza-flag t)
a3e58c1a
JPW
1645 (doctor-type '((doc// found) \? hah !
1646 (doc$ please) (doc$ continue) \.)))))
a1506d29 1647
a3e58c1a 1648(defun doctor-sports () (doctor-type (doc$ sportslst)))
6679505f 1649
a3e58c1a 1650(defun doctor-math () (doctor-type (doc$ mathlst)))
6679505f
JB
1651
1652(defun doctor-zippy ()
a3e58c1a 1653 (cond (zippy-flag (doctor-type (doc$ zippylst)))
6679505f
JB
1654 (t (setq zippy-flag t)
1655 (doctor-type '(yow! are we interactive yet \?)))))
1656
1657
a3e58c1a 1658(defun doctor-chat () (doctor-type (doc$ chatlst)))
6679505f 1659
896546cd
RS
1660(provide 'doctor)
1661
0ff22356 1662;; arch-tag: 579380f6-4902-4ea5-bccb-6339e30e1257
c0274f38 1663;;; doctor.el ends here