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