_TITLE "AI Chat Bot Z" ' started by Zeppelin 2018-12-03 '2018-12-03 B+ mods fix no file started error, more efficient coding of new lines
' changed topNull to found to continue to use lines to track last loaded item in line$()
' created function to remove punctuation and lower case all letters, like Eliza
' setup global variables: line$(), lines, the file as CONST
' created sub to show the data file to check wording call either as in$ or res$, for debugging
' create function to read commands from user input in$ or user input res$, for Interpreter stuff like Bill's bot
' so started a commands list and parameters list.
'global variables start with cap, constants are all cap
CONST DATFILE
= "AI Chat Data.txt"
'load line$
OPEN DATFILE
FOR APPEND AS #1 '<<<<<<<<<<<<<<<<<< in case a file is not started yet Lines = Lines + 1 ' <<<<<<<<<<<<<<<<<<<<< let lines track last entry in array
INPUT #1, Line$
(Lines
) ' <<<<<<<<<<<<<<<< here you have lines tracking top line number
'load commands
Commands(1) = "show "
'no paramter
Commands(2) = "bye"
Commands(3) = "good bye"
Commands(4) = "goodbye"
Commands(5) = "shutup"
Commands(6) = "shut up"
'load parameters
DIM SHARED Parameters
(1 TO 5) AS STRING 'Data or Time are Parameters eg Show Time, Show Data... Parameters(1) = " data"
Parameters(2) = " time"
Parameters(3) = " date"
Parameters(4) = " today"
Parameters(5) = " commands"
found = 0 'topNull ????
LINE INPUT "Input >> ", in$
'<<<<<<<<<<<<<<<<<<<<<<<<<<< line input allows commas modIN$ = RemovePunctuation$(in$)
testInterpret = Interpret(modIN$)
IF testInterpret
= 0 THEN 'no commands found 'in$ = LCASE$(in$) '<<<< removePunctuation$ will do this and more
found = n
'try searching the in$ string for keywords like show or tell
'no key words or phrases found THEN do this
PRINT "How should I respond to that? (Just enter will skip recording a response.)" LINE INPUT "respond >> ", res$
'<<<<<<<<<<<<<<<<<<<<<<<<<<< line input allows commas IF res$
<> "" THEN 'sometimes you just don't know a good response modRes$ = RemovePunctuation$(res$)
test = Interpret(modRes$)
' instead of this VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
'FOR n = 1 TO lines
' line$(n) = ""
'NEXT n
'OPEN "AIDatabase.txt" FOR INPUT AS #1
'WHILE NOT EOF(1)
' lines = lines + 1
' INPUT #1, line$(lines)
'WEND
'CLOSE #1
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'this VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
Lines = Lines + 2
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'could offer a menu of options when res$ is blank, like r for random slection
END IF 'found a response in line$() END IF 'testInterpret = 0
FUNCTION RemovePunctuation$
(s$
) 'and return lower case for copmaring Data string with Input string RemovePunctuation$ = b$
SUB ShowData
'this is first thing I want to see when debugging the Chat Bot INPUT "Press enter to continue data display... any other to quit display."; cont$
INPUT "End of Data, Press enter to continue... any other to quit."; cont$
'assume removePunctuation has been used on string
FUNCTION Interpret%
(s$
) 'return 1 if found something to do (and did it) else 0 so main code can process it as normal chat ' commands
Interpret = 1
IF s$
= "bye" OR s$
= "good bye" OR s$
= "goodbye" OR s$
= "shutup" OR s$
= "shut up" THEN INPUT "Do you wish to end this session? y for yes ", cont$
PRINT "Command"; k
, Commands
(k
) lineCount = lineCount + 1
INPUT "Press enter to continue, any other to quit ", cont$
PRINT "Parameter"; k
, Parameters
(k
) INPUT "Press enter to continue, any other to quit ", cont$
Interpret = 0