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