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