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