'Type=Brain 'Name=Blank Slate Brain 'Language=VBScript 'DataFolder=DefBrain ' '------------------------------------------------ 'The following code begins the "GetResponse" function. 'The function called "GetResponse" has the purpose of 'creating contents for a variant also named "GetResponse." 'When the script is finished, "GetResponse" will be 'what UltraHal says to the user. 'The next line of code declares the function and 'lists the "arguments" that pertain to this function: Function GetResponse(ByVal UserSentence, ByVal UserName, ByVal ComputerName, ByVal LearningLevel, ByRef WorkingDir, ByRef Hate, ByRef Swear, ByRef Insults, ByRef Compliment, ByRef PrevSent, ByRef LastResponseTime, ByRef PrevUserSent, ByRef CustomMem, ByRef GainControl, ByRef TopicFocus) 'PROCESS: CREATE HALBRAIN ACTIVEX OBJECT 'These ActiveX controls contain many functions 'needed for the script to process a sentence. Set HalBrain = CreateObject("UltraHalAsst.Brain") 'PROCESS: PRESERVE ORIGINAL SENTENCE 'Preserve the original user's sentence verbatim '(no pronoun reversals or other processing). OriginalSentence = UserSentence 'PROCESS: PREPARE FOR HALFORMAT AND REVERSE PERSON 'We try some pre-processing to try to prevent 'problems with the upcoming routines. UserSentence = Replace("" & UserSentence & "", " I MYSELF ", " I, MYSELF, ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " I'M ", " I AM ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " YOU'RE ", " YOU ARE ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " YOU YOURSELF ", " YOU, YOURSELF, ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " I'M NOT ", " I AM NOT ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " I'VE ", " I HAVE ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", "YOU'RE NOT ", "YOU ARE NOT ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", "YOU AREN'T ", "YOU ARE NOT ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " YOU'VE ", " YOU HAVE ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " I AM YOUR ", " VIMRQ ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", " YOU ARE MY ", " VURMQ ", 1, -1, vbTextCompare) 'PROCESS: SUBSTITUTE FOR PUNCTUATION 'The next routine removes hyphens etc., so we 'substitute for better word appearance later on. UserSentence = Replace("" & UserSentence & "", "-", " VHZ ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", ";", " VSZ ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", ":", " VMZ ", 1, -1, vbTextCompare) UserSentence = Replace("" & UserSentence & "", ", ", " VCZ ", 1, -1, vbTextCompare) 'PROCESS: REMOVE PUNCTUATION 'This function removes all punctuation and 'symbols from the User's sentence so they won't 'confuse Hal during processing. UserSentence = HalBrain.AlphaNumericalOnly(UserSentence) 'PROCESS: MODIFY SENTENCE 'The function, HalFormat, from the ActiveX DLL 'corrects many common typos and chat shortcuts. 'Example: "U R Cool" becomes "You are cool." 'It also fixes a few grammatical errors. UserSentence = HalBrain.HalFormat(UserSentence) 'PROCESS: REVERSE PERSON 'This function reverses first and second person 'pronouns. Example: The user's statement '"You are cool" becomes Hal's statement "I am cool." 'Keep this is mind and don't get confused. 'When we are in Hal's brain; In the databases, "I" 'refers to Hal and in the databases, "you" 'refers to the user. This is true whenever we are 'dealing with a user response "processed" by 'Hal's brain. UserSentence = HalBrain.SwitchPerson(UserSentence) 'PROCESS: MODIFY SENTENCE 'We now must run HalFormat again, to fix some 'grammatical errors the switch person above might 'have caused. Example: If the original sentence 'was "How are you"; after the function above it 'became "How are me" which is grammatically wrong. 'This will fix it to "How am I" 'NOTE TO DEVELOPERS: An especially important function 'performed by HalFormat is the removal of 'extra empty spaces in a sentence which may have been 'caused by other processing. For this 'reason, use Halformat closely before any "Len" comparison 'in which the counting of characters 'must be accurate. UserSentence = HalBrain.HalFormat(UserSentence) 'PROCESS: CHANGE TO ALL CAPS 'Next, we captitalize the entire sentence for 'easy comparison. Almost all of Hal's thinking is done in caps. UserSentence = UCase(UserSentence) 'PROCESS: WORD AND PHRASE SUBSTITUTIONS 'This will fix common errors in the user's sentence 'that the HalFormat function didn't take 'care of. These subsitutions are placed only the 'users sentence, not on Hal's responses. 'The HalFormat function is used on both Hal's 'and the user's sentences throughout the script. UserSentence = HalBrain.ProcessSubstitutions(UserSentence, WorkingDir & "substitutions.brn") 'PROCESS: ADD SPACES 'This will add spaces to the beggining and end 'of the user sentence to make sure that 'whole words can be found at the beginning and end of any sentence, UserSentence = " " & UserSentence & " " 'PROCESS: RESTORE QUESTION MARKS AND EXCLAMATION POINTS If Instr(OriginalSentence, "?") > 0 Then UserSentence = UserSentence & "?" If Instr(OriginalSentence, "!") > 0 Then UserSentence = UserSentence & "!" '------------------------------------------------------------------ '-------------------------------------------- 'RESPOND: CALL CheckALICEBRAIN FUNCTION '-------------------------------------------- 'This function will check for insults and swearing and respond to them. It is built into this script, 'so you can edit it. CheckALICEBRAIN = Trim(ALICEBRAIN(UserSentence,UserName,ComputerName,LearningLevel,WorkingDir,Hate,Swear,Insults,Compliment,PrevSent,LastResponseTime,PrevUserSent)) If Len(CheckALICEBRAIN) > 4 And GetResponseBlock <> True Then GetResponse = GetResponse & CheckALICEBRAIN & VbCrLf AvoidBeingFlag = True DebugInfo = DebugInfo & "The user has CheckALICEBRAIN : " & CheckALICEBRAIN & VbCrLf Else DebugInfo = DebugInfo & "hal has not used the alice brain: " & CheckALICEBRAIN & VbCrLf End If '-------------------------------------------- '------------------------------------------------------------------ 'PROCESS: REVERSE CERTAIN CONTRACTIONS AND OTHER SUBSTITUTIONS 'Standardizing on contractions can make Hal sound conversational. 'However, certain sentence constructions don't work well 'if expressed as contractions. For example: '"I don't know where it is" becomes "I don't know where it's." 'For another example, "That's how he is" becomes "That's how he's." 'To solve these types of cases 'we attempt to modify certain contractions, words, and phrases 'at the end of this function, now that Hal's thinking is done. GetResponse = HalBrain.HalFormat(GetResponse) GetResponse = HalBrain.ProcessSubstitutions(GetResponse, WorkingDir & "Corrections.brn") 'POST PROCESS: SAVE USER'S SENTENCE AND HAL'S RESPONSE PrevUserSent = UserSentence PrevSent = GetResponse 'POST PROCESS: PRESERVE ALL VARIABLES 'Remember all the variables through encoding 'them into one function string using 'the DLL, since for some reason ByRef 'assignments don't work when a Visual Basic 'executable is calling a function in a VBScript program. GetResponse = HalBrain.FixCaps(HalBrain.HalFormat(GetResponse)) GetResponse = GetResponse & HalBrain.StoreVars(WorkingDir, Hate, Swear, Insults, Compliment, PrevSent, LastResponseTime, PrevUserSent, CustomMem, GainControl, TopicFocus) End Function '-------------------------------------------- ' ALICEBRAIN FUNCTION '-------------------------------------------- Function ALICEBRAIN(ByVal UserSentence, ByVal UserName, ByVal ComputerName, ByVal LearningLevel, ByRef WorkingDir, ByRef Hate, ByRef Swear, ByRef Insults, ByRef Compliment, ByRef PrevSent, ByRef LastResponseTime, ByRef PrevUserSent) 'CREATE HALBRAIN ACTIVEX OBJECT 'This ActiveX control contains many functions 'needed for the script to proccess a sentence. Set Alice = CreateObject("HalAlice.PlugIn") 'GET RESPONSE ALICEBRAIN = Alice.Respond(UserSentence, UserName, WorkingDir, "data\bot.ini", "log\localuser.txt") Set Alice = Nothing End Function '-------------------------------------------- 'If the user clicks on the About/Options button for this plugin 'this sub will be called. There are no extra settings for this brain, 'so we'll display an information box Sub AboutOptions() Set HalBrain = CreateObject("UltraHalAsst.Brain") HalBrain.MsgAlert "This is the Ultra Hal Experimenter's Brain. This brain has no additional options." End Sub 'This sub will be called when the Ultra Hal program starts up in case 'the script needs to load some modules or seperate programs. Sub Script_Load() End Sub 'This sub will be called before the Ultra Hal program is closed in case 'the script needs to do any cleanup work. Sub Script_Unload() End Sub