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