' This is a TWO Part Snippet,  ELIZA.BAS & ELIZA.DAT
 
10 '
20 ' Eliza/Doctor
30 ' Original author: Joseph Weizenbaum
40 ' This version: Frederick B. Maxwell, Jr.
50 ' Version 1.0    2/12/85        Initial CP/M (MBASIC) release.
60 ' Version 2.0    6/13/89        Initial PC (GWBASIC) release.
70 '
80 '***********************************************************************
90 '
100 '     This version of Eliza is released into the public domain.
110 '
120 '***********************************************************************
130 '
' no floating point is used.
' up to 300 responses.
' up to 200 keywords.
' first reply for keyword number in subscript.
' last reply   "     "      "     "     "    .
' offset from first reply for each keyword.
200 '
210 '***********************************************************************
220 '
230 '     -Initialization-
240 '     We will read in data from the file ELIZA.DAT in the following format:
250 '          KEYWORD 1
260 '          KEYWORD N all keywords which will get the same responses
270 '          !         indicates end of keywords
280 '          RESPONSE 1     all responses for this/these keywords.
290 '          RESPONSE N
300 '          .         indicates end of responses
310 '
320 '***********************************************************************
330 '
"I", 1, "ELIZA.DAT":       ' file with keyword/response data.
' number of keywords
360 MINREPLY = 1:              ' first reply for first keyword.
370 '
' number of keys with same responses.
' get keyword or !
"!"' if ! then get replys.
' we've got one more keyword
"."; :          ' let user know we're still alive.
' 1 more keyword with same replys.
" " + F$ + " ":  ' put in a keyword bounded with spaces.
'
' get the reply or .
"."' check for end of reply list.
500      MAXREPLY = MAXREPLY + 1:   ' 1 more reply.
'
' first reply for key.
' last reply for key.
' set up for next keyword.
590      '
'
630 '***********************************************************************
640 '
650 '     Here we go!  Send intro message to "patient".
660 '
670 '***********************************************************************
680 '
"HI!  I'M ELIZA.  LET'S TALK.  TYPE `BYE' TO END THIS SESSION."
710 '
720 '***********************************************************************
730 '
740 '     Get the user input into I$.
750 '
760 '***********************************************************************
770 '
">"' Get user input.
""' Just hitting return isn't good enough.
800 I$ = " " + I$ + " ": ' Put a space on each end.
810 '
820 '***********************************************************************
830 '
840 '     Get rid of punctuation/extraneous characters, and make uppercase.
850 '
860 '***********************************************************************
870 '
880 L = 1:           ' Start at the first character
' Get the character.
900 '
910 '     Capitalize if necessary.
920 '
"a""z"'
" "' Spaces are OK.
"0""9"' So are numbers.
"A""Z"' So are capital letters.
' Delete character.
990 L = L + 1:                 ' Next character.
' Keep on processin'
1010 '
1020 '***********************************************************************
1030 '
1040 '    Has he/she said this before?  Does he/she want to terminate session?
1050 '
1060 '***********************************************************************
1070 '
"PLEASE DON'T REPEAT YOURSELF!"' Set up for next run.
1100 '
" BYE ""TALK TO YOU LATER!  BYE!"'
1130 '***********************************************************************
1140 '
1150 '    Find keyword in user input string (I$).
1160 '
1170 '***********************************************************************
1180 '
' Start search at keyword number 1.
' Look for the keyword in the string.
' Exit on match.
' Keyword number.
' We don't need anything if no match.
1250 REMAINS$ = MID$(I$, C - 1 + LEN(KWD$(K))): ' Grab remainder for reply.
1260 '
1270 '***********************************************************************
1280 '
1290 '    Take everything after the keyword (remains$) and conjugate it
1300 '         using the data for conjugation.
1310 '
1320 '***********************************************************************
1330 '
' Read search and replacement words.
"."' Periods (.) idicate end of data.
REMAINS$, S$):       ' Search for string S$ in REMAINS$
' If no match, try the next one.
REMAINS$, C - 1): ' Replacement.
1400 TEMP$ = TEMP$ + R$:             ' Word.
1410 REMAINS$ = TEMP$ + MID$(REMAINS$, C + LEN(S$)): ' Right side.
' Next conjugation to be done.
REMAINS$, "+"):      ' Strip the plus signs out.
REMAINS$ = LEFT$(REMAINS$, C - 1) + MID$(REMAINS$, C + 1):  ' Strip it.
' Go for the next one.
1470 '
1480 ' Handle the special case of " I " being the last word.
1490 '
REMAINS$, 3) <> " I " THEN 1540
1510 REMAINS$ = LEFT$(REMAINS$, LEN(REMAINS$) - 2) + "ME "
1520 '
1530 '***********************************************************************
1540 '
1550 '    Get the reply using the keyword number (KWD).
1560 '
1570 '***********************************************************************
1580 '
' Get reply.
' Point to next reply.
' Wrap.
1620 '
1630 '    Bump offsets on all keywords that use these replys.
1640 '
'
1690 '    If the last character of the reply is *, append REMAINS$ to reply.
1700 '
"*"REMAINS$
'
1750 '***********************************************************************
1760 '
1770 '    Data for conjugations in the following form:
1780 '         Word to replace , Replacement with + appended on end
1790 '    + is to keep the word from being switched back later and will
1800 '    be stripped before output.
1810 '
1820 '***********************************************************************
1830 '
" ARE "  ,  " AM+ "" AM "   ,  " ARE+ "" WERE " ,  " WAS+ "" WAS "  ,  " WERE+ "" YOU "  ,  " I+ "" I "    ,  " YOU+ "" YOUR " ,  " MY+ "" MY "   ,  " YOUR+ "" IVE "  ,  " YOUVE+ "" YOUVE ",  " IVE+ "" IM "   ,  " YOURE+ "" ME "   ,  " YOU+ "" US "   ,  " YOU+ "" WE "   ,  " YOU+ "".","."
1990 '
 
 
'-------------------8<------[ Begin ELIZA.DAT ]------->8--------------------
'T IMPRESSED BY VULGARITY.
'S TRY TO KEEP THIS SESSION CLEAN, SHALL WE?
'T YOU THINK COMPUTERS CAN HELP PEOPLE?
'T YOU BELIEVE THAT I CAN*
'T WANT TO*
'T YOU REALLY*
'T YOU*
'T*
'T YOU*
'T*
'T LOVE TOO STRONG A WORD FOR YOUR FEELING ABOUT*
'T YOU THINK?
'T INTEREST ME... TOO MUCH... PICK ANOTHER TOPIC PLEASE.
'T CARE ABOUT NAMES--PLEASE GO ON.
'T ANY OTHER REASONS COME TO MIND?
'T APOLOGIZE.
'T BE SO DEFENSIVE!
'S IT GOING?
'T SEEM QUITE CERTAIN.
'T YOU BE MORE POSITIVE?
YOU AREN'T SURE?
'T YOU KNOW?
'T SOUND THAT BAD TO ME. PERHAPS YOU'RE WORRYING TOO MUCH.
'RE USING ANGER TO AVOID SOCIAL CONTACT.
'RE NOT REALLY TALKING ABOUT ME, ARE YOU?
'T IT?
'T YOU ENJOY?
'S YOUR IQ?
'M NOT SURE I UNDERSTAND YOU FULLY.
'-------------------8<------[ End ELIZA.DAT ]------->8--------------------