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