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