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