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