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