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