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