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