comparison lisp/games/doctor.el @ 0:376386a54a3c r19-14

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