Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Rem Type=Brain
- Rem Name=Hal 6.2 Brain
- Rem Author=Zabaware
- Rem Language=VBScript
- Rem DB=HalBrain.db
- 'The UltraHal function is called by Ultra Hal Assistant 6.x or a compatible host application
- 'It passes an unformated string of the user's input as well as all remembered variables.
- 'The UltraHal function splits the user's input into seperate sentences and than calls
- 'GetResponse to get a response for each user sentence. The UltraHal function performs all
- 'the initialization functions required for GetResponse so that GetResponse doesn't have to
- 'initialize several times if a user inputs more than 1 sentence.
- Function UltraHal(ByVal InputString, ByVal UserName, ByVal ComputerName, ByVal LearningLevel, ByVal DatabaseFile, ByRef Hate, ByRef Swear, ByRef Insults, ByRef Compliment, ByRef PrevSent, ByRef LastResponseTime, ByRef PrevUserSent, ByRef CustomMem, ByRef GainControl, ByRef LastTopicList)
- 'RESPOND: User pressed enter, but didn't say anything
- InputString = Trim(InputString)
- If Len(InputString) < 2 Then
- UltraHal = "Please say something."
- Exit Function
- End If
- 'PROCESS: AUTO-IDLE
- 'If AUTO-IDLE is enabled, it is called by the Ultra Hal Assistant host
- 'application at a set interval. This allows for the possibility of Hal
- 'being the first to say something if the user is idle.
- If InputString = "AUTO-IDLE" Or InputString = "AUTO IDLE" Or InputString = "AUTOIDLE" Then
- Rem PLUGIN: AUTO-IDLE
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- UltraHal = UltraHal & HalBrain.StoreVars(HalCommands, Hate, Swear, Insults, Compliment, PrevSent, LastResponseTime, PrevUserSent, CustomMem, GainControl, LastTopicList)
- Exit Function
- End If
- 'PROCESS: INITIALIZE VARIABLES
- 'VBScript doesn't allow you to declare variables in advance as a
- 'particular data type; everything is a Variant. We must assign
- 'integers to the following variants so that data type errors don't
- 'occur
- If LearningLevel = "" Then LearningLevel = 100
- If Hate = "" Then Hate = 0
- If Swear = "" Then Swear = 0
- If Insults = "" Then Insults = 0
- If Compliment = "" Then Compliment = 0
- If GainControl = "" Then GainControl = 50
- 'PROCESS: IF NO LEARNING IS REQUESTED, PUT DATABASE IN READ-ONLY MODE
- 'If read only mode is on, any requests to create a new table, add to
- 'a table, or delete records from a table will be ignored.
- If LearningLevel = 0 Then HalBrain.ReadOnlyMode = True Else HalBrain.ReadOnlyMode = False
- 'PROCESS: EMOTIONAL FACTOR CENTERING
- 'We help Hal regain his emotional "center" gradually, even if the
- 'user doesn't catch on to dealing With Hal's feelings. The following
- 'code brings Hal's memory of hate, swearing, and insults gradually
- 'and randomly back to zero.
- Randomize
- SpinWheel = Int(Rnd * 100)
- If Hate > 0 And SpinWheel < 10 Then Hate = Hate - 1
- SpinWheel = Int(Rnd * 100)
- If Swear > 0 And SpinWheel < 10 Then Swear = Swear - 1
- SpinWheel = Int(Rnd * 100)
- If Insults > 0 And SpinWheel < 10 Then Insults = Insults - 1
- 'PROCESS: EMOTIONAL VARIETY
- 'The following code allows Hal some random emotional excursions:
- SpinWheel = Int(Rnd * 100)
- If Compliment = 4 And SpinWheel < 30 Then Compliment = 2
- If Compliment > 0 And Compliment < 4 And SpinWheel < 5 Then Compliment = 0
- If Compliment > 4 And SpinWheel < 5 Then Compliment = 0
- If Compliment < 0 And SpinWheel < 30 Then Compliment = 0
- If SpinWheel > 80 And SpinWheel < 90 Then Compliment = 2
- If SpinWheel > 90 And SpinWheel < 95 Then Compliment = 4
- Rem PLUGIN: PRE-PROCESS
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- 'PROCESS: SPLIT USER'S INPUT STRING INTO SEPERATE SENTENCES
- 'Encode abbreviations such as Mr. Mrs. and Ms.
- InputString = Replace(InputString, "MR.", "Mr<PERIOD>", 1, -1, vbTextCompare)
- InputString = Replace(InputString, "MRS.", "Mrs<PERIOD>", 1, -1, vbTextCompare)
- InputString = Replace(InputString, "MS.", "Ms<PERIOD>", 1, -1, vbTextCompare)
- InputString = Replace(InputString, "DR.", "Dr<PERIOD>", 1, -1, vbTextCompare)
- InputString = Replace(InputString, "MS.", "Ms<PERIOD>", 1, -1, vbTextCompare)
- InputString = Replace(InputString, "ST.", "St<PERIOD>", 1, -1, vbTextCompare)
- InputString = Replace(InputString, "PROF.", "Prof<PERIOD>", 1, -1, vbTextCompare)
- InputString = Replace(InputString, "GEN.", "Gen<PERIOD>", 1, -1, vbTextCompare)
- InputString = Replace(InputString, "REP.", "Rep<PERIOD>", 1, -1, vbTextCompare)
- InputString = Replace(InputString, "SEN.", "Sen<PERIOD>", 1, -1, vbTextCompare)
- 'Remove unnecessary punctuation
- Do
- RepeatLoop = False
- If InStr(InputString, "..") Then InputString = Replace(InputString, "..", "."): RepeatLoop = True
- If InStr(InputString, "??") Then InputString = Replace(InputString, "??", "?"): RepeatLoop = True
- If InStr(InputString, "!!") Then InputString = Replace(InputString, "!!", "!"): RepeatLoop = True
- If InStr(InputString, "!?") Then InputString = Replace(InputString, "!?", "?"): RepeatLoop = True
- If InStr(InputString, "?!") Then InputString = Replace(InputString, "?!", "?"): RepeatLoop = True
- If InStr(InputString, ",,") Then InputString = Replace(InputString, ",,", ","): RepeatLoop = True
- Loop While RepeatLoop = True
- 'Detect and encode acronyms such as U.S.A.
- InputString = Trim(InputString)
- WordList = Split(InputString, " ")
- For i = 0 To UBound(WordList)
- If Len(WordList(i)) > 3 Then
- If Right(WordList(i), 1) = "." And Mid(WordList(i), Len(WordList(i)) - 2, 1) = "." Then
- InputString = Replace(InputString, WordList(i), Left(WordList(i), Len(WordList(i)) - 1) & "<PERIOD>")
- End If
- End If
- Next
- 'Place split markers in string
- InputString = Replace(InputString, ". ", ". <NEWSENT>")
- InputString = Replace(InputString, "? ", "? <NEWSENT>")
- InputString = Replace(InputString, "! ", "! <NEWSENT>")
- 'Decode acronyms and abbreviations
- InputString = Replace(InputString, "<PERIOD>", ".", 1, -1, vbTextCompare)
- 'Split string into sentences
- Sentences = Split(InputString, "<NEWSENT>")
- 'PROCESS: RECORD DEBUG INFO
- 'HalBrain.AddDebug "Debug", "Ultra Hal Start"
- 'RESPOND: PREDEFINED RESPONSES
- 'If the previous exchange had tags to set the response of this exchange
- 'then follow the command.
- NextResponse = HalBrain.ExtractVar(CustomMem, "NextResponse")
- If NextResponse <> "" Then
- CustomMem = Replace(CustomMem, "NextResponse-eq-", "LastResponse-eq-")
- UltraHal = NextResponse
- GoodSentence = True
- NextResponse = ""
- End If
- YesResponse = HalBrain.ExtractVar(CustomMem, "YesRes")
- NoResponse = HalBrain.ExtractVar(CustomMem, "NoRes")
- If YesResponse <> "" Or NoResponse <> "" Then
- CustomMem = Replace(CustomMem, "YesRes-eq-", "LastYesRes-eq-")
- CustomMem = Replace(CustomMem, "NoRes-eq-", "LastNoRes-eq-")
- InputString2 = Replace(InputString, ".", " ")
- InputString2 = Replace(InputString2, "?", " ")
- InputString2 = Replace(InputString2, "!", " ")
- InputString2 = " " & Replace(InputString2, ",", " ") & " "
- YesNoDetect = HalBrain.TopicSearch(InputString2, "yesNoDetect")
- If YesNoDetect = "Yes" And YesResponse <> "" Then
- UltraHal = YesResponse
- GoodSentence = True
- ElseIf YesNoDetect = "No" And NoResponse <> "" Then
- UltraHal = NoResponse
- GoodSentence = True
- End If
- End If
- 'RESPOND: GETRESPONSE
- 'Get a response from Hal's brain for each sentence individually.
- 'If a response from a sentence indicates a special flag, then Hal
- 'will give only the response to that sentence, and not process
- 'any other sentences. Otherwise Hal will respond to each sentence.
- 'Hal will respond to a max of 3 sentences at once.
- SentenceCount = UBound(Sentences)
- If SentenceCount > 2 Then SentenceCount = 2
- LowQualityResponse = ""
- If GoodSentence <> True Then 'Only respond if a predefined response hasn't already been selected
- For i = 0 To SentenceCount
- TempParent = HalBrain.AddDebug("Debug", "Begin Processing Sentence " & CStr(i + 1), vbCyan)
- HalBrain.AddDebug TempParent, "Sentence: " & Sentences(i)
- HalBrain.DebugWatch "", "NewSent"
- Sentences(i) = Trim(Sentences(i))
- If Len(Sentences(i)) > 1 Then
- GoodSentence = True
- CurResponse = GetResponse(Sentences(i), UserName, ComputerName, LearningLevel, HalCommands, Hate, Swear, Insults, Compliment, PrevSent, LastResponseTime, PrevUserSent, CustomMem, GainControl, LastTopicList) & vbCrLf
- If InStr(1, CurResponse, "<LOWQUALITY>", vbTextCompare) Then
- 'If Hal's response to the current sentence is of a low-quality nature, then we hold out
- 'for a better response with a different sentence, but if there is no better response
- 'then we will use only the first low-quality response we came across.
- If LowQualityResponse = "" Then LowQualityResponse = CurResponse
- ElseIf InStr(1, CurResponse, "<TOPIC>", vbTextCompare) Or InStr(1, CurResponse, "<YESRES>", vbTextCompare) Or InStr(1, CurResponse, "<EXCLUSIVE>", vbTextCompare) Then
- 'If Hal's response indicates an exclusivity tag, then we erase any response Hal may have
- 'already had, respond with the exclusive response, and cease processing more sentences
- UltraHal = CurResponse & vbCrLf
- Exit For
- Else
- 'Since there are no special tags, we just append the new response to the previous one
- 'if the response was not already given
- If InStr(1, UltraHal, CurResponse, vbTextCompare) = 0 Then UltraHal = UltraHal & " . " & CurResponse & vbCrLf
- End If
- 'If we received a tag to stop processing more sentences, we leave the loop
- If InStr(1, CurResponse, "<NOMORE>", vbTextCompare) Then Exit For
- End If
- Next
- End if
- 'If we have no normal quality responses, we will use our low quality response
- UltraHal = Trim(UltraHal)
- If UltraHal = "" Then UltraHal = Trim(LowQualityResponse)
- 'RESPOND: USER DIDN'T SAY ANYTHING
- 'If GoodSentence has not been set to true, then that means the user didn't
- 'type anything of use, so we ask the user to say something.
- If GoodSentence = False Then
- UltraHal = "Please say something."
- Exit Function
- End If
- 'PROCESS: PROCESS IN-SENTENCE TAGS
- 'the <TOPIC>*</TOPIC> tag sets what Hal's next response will be, no matter what the user says
- NextResponse = HalBrain.SearchPattern(UltraHal, "*<TOPIC>*</TOPIC>*", 2)
- If NextResponse <> "" Then
- UltraHal = Replace(UltraHal, NextResponse, "", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "<TOPIC>", "", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "</TOPIC>", "", 1, -1, vbTextCompare)
- NextResponse = Trim(Replace(NextResponse, "<TOPIC>", "", 1, -1, vbTextCompare))
- CustomMem = CustomMem & HalBrain.EncodeVar(NextResponse, "NextResponse")
- End If
- 'The <YES>*</YES> and <NO>*</NO> tag sets what Hal's response will be if the user says yes or no
- UltraHal = Replace(UltraHal, "<YESRE>", "<YESRES>", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "</YESRE>", "</YESRES>", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "<YES>", "<YESRES>", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "</YES>", "</YESRES>", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "<NO>", "<NORES>", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "</NO>", "</NORES>", 1, -1, vbTextCompare)
- YesRes = HalBrain.SearchPattern(UltraHal, "*<YESRES>*</YESRES>*", 2)
- If YesRes <> "" Then
- UltraHal = Replace(UltraHal, YesRes, "", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "<YESRES>", "", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "</YESRES>", "", 1, -1, vbTextCompare)
- YesRes = Trim(Replace(YesRes, "<YESRES>", "", 1, -1, vbTextCompare))
- CustomMem = CustomMem & HalBrain.EncodeVar(YesRes, "YesRes")
- End If
- NoRes = HalBrain.SearchPattern(UltraHal, "*<NORES>*</NORES>*", 2)
- If NoRes <> "" Then
- UltraHal = Replace(UltraHal, NoRes, "", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "<NORES>", "", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "</NORES>", "", 1, -1, vbTextCompare)
- NoRes = Trim(Replace(NoRes, "<NORES>", "", 1, -1, vbTextCompare))
- CustomMem = CustomMem & HalBrain.EncodeVar(NoRes, "NoRes")
- End If
- 'The <RUN>*</RUN> tags are converted into a HalCommand to run a program
- UltraHal = Replace(UltraHal, "<RUNIT>", "<RUN>", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "</RUNIT>", "</RUN>", 1, -1, vbTextCompare)
- RunProgram = HalBrain.SearchPattern(UltraHal, "*<RUN>*</RUN>*", 2)
- If RunProgram <> "" Then
- UltraHal = Replace(UltraHal, RunProgram, "", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "<RUN>", "", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "</RUN>", "", 1, -1, vbTextCompare)
- RunProgram = Trim(Replace(RunProgram, "<RUN>", "", 1, -1, vbTextCompare))
- HalCommands = HalCommands & "<RUNPROG>" & RunProgram & "</RUNPROG>"
- End If
- UltraHal = Replace(UltraHal, "<WEBADDRESS>", "www.ultrahal.com", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "<HALNAME>", ComputerName, 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "<HALSNAME>", ComputerName, 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "<COMPUTERNAME>", ComputerName, 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, " " & ComputerName & " ", " " & ComputerName & " ", 1, -1, vbTextCompare) 'Fixes capitilization of computer's name if needed
- UltraHal = Replace(UltraHal, "<TIME>", Time(), 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "<DATE>", Date(), 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "<QUOTE>", """", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, """, """", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, """, """", 1, -1, vbTextCompare)
- If Instr(1, UltraHal, "<makeinsult>", vbTextCompare) Then
- UltraHal = Replace(UltraHal, "<makeinsult>", HalBrain.ChooseSentenceFromFile("insults"), 1, -1, vbTextCompare)
- End If
- UltraHal = Replace(UltraHal, "<AT>", "@", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "<NOMORE>", "", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "<LOWQUALITY>", "", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "<EXCLUSIVE>", "", 1, -1, vbTextCompare)
- 'PROCESS: INTELLIGENT CAPITILIZATION FIX
- UltraHal = HalBrain.FixCaps(HalBrain.HalFormat(UltraHal))
- UltraHal = Replace(UltraHal, "<ELLIPSIS>", "...", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "....", "...", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "...?", "...", 1, -1, vbTextCompare)
- UltraHal = Replace(UltraHal, "...!", "...", 1, -1, vbTextCompare)
- Rem PLUGIN: POST-PROCESS
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- 'POST PROCESS: PRESERVE ALL VARIABLES, CLOSE DATABASE, EXIT
- '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. The HalCommands variable
- 'that is returned is not used by this script, but can be used by script programmers
- 'to send certain commands back to the host Hal program. See documentation of the
- 'host Hal program to see what this can be used for.
- 'Close database and exit function
- PrevSent = UltraHal
- UltraHal = UltraHal & HalBrain.StoreVars(HalCommands, Hate, Swear, Insults, Compliment, PrevSent, LastResponseTime, PrevUserSent, CustomMem, GainControl, LastTopicList)
- End Function
- Function GetResponse(ByVal UserSentence, ByVal UserName, ByVal ComputerName, ByVal LearningLevel, ByRef HalCommands, ByRef Hate, ByRef Swear, ByRef Insults, ByRef Compliment, ByVal PrevSent, ByRef LastResponseTime, ByRef PrevUserSent, ByRef CustomMem, ByRef GainControl, ByRef LastTopicList)
- 'PROCESS: DECODE CUSTOM VARIABLES FROM CUSTOMMEM VARIABLE
- NewName = HalBrain.ExtractVar(CustomMem, "NewName")
- UserSex = HalBrain.ExtractVar(CustomMem, "UserSex")
- SentCount = HalBrain.ExtractVar(CustomMem, "SentCount")
- ShortSents = HalBrain.ExtractVar(CustomMem, "ShortSents")
- If ShortSents = "" Then ShortSents = 0
- If SentCount = "" Then SentCount = 0
- SentCount = SentCount + 1
- AvoidBeingFlag = False
- Randomize
- Rem PLUGIN: CUSTOMMEM
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- '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 other punctuation and symbols from the User's
- 'sentence so they won't confuse Hal during processing.
- UserSentence = HalBrain.AlphaNumericalOnly(UserSentence)
- 'PROCESS: REMOVE HAL'S NAME IF IT IS AT THE START OR END OF SENTENCE
- If Len(UserSentence) > Len(ComputerName) + 8 Then
- If Ucase(Left(UserSentence, 4)) = "Hal" Then UserSentence = Right(UserSentence, Len(UserSentence) - 4)
- If Ucase(Right(UserSentence, 4)) = "Hal" Then UserSentence = Left(UserSentence, Len(UserSentence) - 4)
- If Ucase(Left(UserSentence, Len(ComputerName) + 1)) = Ucase(ComputerName) & " " Then UserSentence = Right(UserSentence, Len(UserSentence) - Len(ComputerName) - 1)
- If Ucase(Right(UserSentence, Len(ComputerName) + 1)) = " " & Ucase(ComputerName) Then UserSentence = Left(UserSentence, Len(UserSentence) - Len(ComputerName) - 1)
- End If
- UserSentence = Trim(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 = Trim(UserSentence)
- If Len(UserSentence) > 15 Then
- If Lcase(Left(UserSentence, 6)) = "anyway" Then UserSentence = Trim(Right(UserSentence, Len(UserSentence) - 6))
- If Lcase(Left(UserSentence, 7)) = "i asked" Then UserSentence = Trim(Right(UserSentence, Len(UserSentence) - 7))
- End If
- If Len(UserSentence) > 6 Then
- If Left(UserSentence, 3) = "VCZ" Then UserSentence = Right(UserSentence, Len(UserSentence) - 3)
- If Right(UserSentence, 3) = "VCZ" Then UserSentence = Left(UserSentence, Len(UserSentence) - 3)
- End If
- 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, "substitutions")
- TempParent = HalBrain.AddDebug("Debug", "Modified User Sentence")
- HalBrain.AddDebug TempParent, "Sentence: " & UserSentence
- 'PROCESS: EMOTIONAL REACTIONS
- 'We enable Hal's expressions to respond to common verbal cues.
- 'The verbal cues are identified in the editable table "emotion"
- If InStr(1, UserSentence, "I'M", 1) Then Aboutme = True
- If InStr(1, UserSentence, "I AM", 1) Then Aboutme = True
- If InStr(1, UserSentence, "I LOOK", 1) Then Aboutme = True
- If InStr(1, UserSentence, "MY", 1) And InStr(1, UserSentence, " ARE ", 1) Then Aboutme = True
- If Aboutme = True And InStr(UserSentence, " NOT ") = 0 And InStr(UserSentence, "N'T ") = 0 And InStr(UserSentence, " NEVER ") = 0 Then
- EmotionalReaction = Ucase(HalBrain.TopicSearch(UserSentence, "emotion"))
- End If
- Select Case EmotionalReaction
- Case "SURPRISED"
- If Compliment > 0 Then Compliment = 4
- If Compliment = 0 Then Compliment = 2
- If Compliment < 0 Then Compliment = 0
- Case "HAPPY"
- If Compliment = 0 Then Compliment = 2
- If Compliment < 0 Then Compliment = 0
- Case "SOBER"
- If Compliment < 4 Then Compliment = 0
- If Compliment = 4 Then Compliment = 2
- Case "ANGRY"
- If Compliment = 0 Then Compliment = -1
- If Compliment > 0 Then Compliment = 0
- Case "SAD"
- If Compliment = 0 Then Compliment = -2
- If Compliment > 0 Then Compliment = 0
- End Select
- '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: FIGURE OUT THE CURRENT SUBJECT
- 'Here we attempt to figure out the subject of the user's sentence. We call
- 'the WordNet class to find the first occurence of a noun in the User's
- 'sentence. Very often this is the subject of the sentence, but if not it
- 'will still most likely be relevant to the conversation.
- CurrentSubject = WN.FindFirstNoun(UserSentence, True)
- HalBrain.AddDebug "Debug", "Current Subject: " & CurrentSubject
- 'PROCESS: BLOCK LEARNING IF HAL'S NAME IS DETECTED
- 'Here we check to see if the user is calling Hal by name; if the user is doing so,
- 'it's better not to save the sentence for re-use, since it usually makes the
- 'pronoun-reversed sentence sound clumsy or incorrect:
- If InStr(1, OriginalSentence, ComputerName, vbTextCompare) > 0 Then HalBrain.ReadOnlyMode = True
- Rem PLUGIN: PLUGINAREA1
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- 'RESPOND: USER REPEATING
- 'If the user says the same thing more than once in a row, Hal will point this out.
- If Trim(UCase(UserSentence)) = Trim(UCase(PrevUserSent)) Then
- GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("userRepeat") & vbCrLf
- End If
- HalBrain.DebugWatch GetResponse, "User Repeating"
- 'PROCESS: KNOWN HUMAN NAMES
- 'If the user mentions a name Hal recognizes, Hal will note the name and gender
- 'for later use by other functions. Hal's database contains a table called "names"
- 'with over 17000 names and their associated genders. If a name can be both genders,
- 'the most likely gender is listed first. This table is stored in the database as a
- 'standard Hal "Topic Search" database, however the standard HalBrain.TopicSearch
- 'function does not provide the required functionality. It only returns the topic
- 'field which in this case is the gender. We also need the searchString field, which
- 'in this case is the person's name. To get this info, we run a custom SQL query.
- 'This demonstrates how Hal's functions can be expanded far beyond its original
- 'scope through custom SQL queries.
- Dim NameSex() 'We must declare an empty array to store query results in
- If HalBrain.RunQuery("SELECT searchString, topic FROM names WHERE strstr(' " & Replace(HalBrain.AlphaNumericalOnly(OriginalSentence), "'", "''") & " ', searchString) > 0 LIMIT 1", NameSex) = True Then
- MentionedName = Trim(NameSex(1, 0)) 'Row 1 contains our query result. Column 0 contains "searchString", which is the name
- MentionedSex = Trim(NameSex(1, 1)) 'Row 1, Column 1 contains "topic", which is the associated gender(s) of the name
- End If
- 'RESPOND: USER TELLS US THEIR NAME OR NICKNAME
- If InStr(UserSentence, " NOT ") = 0 And InStr(UserSentence, " MIDDLE ") = 0 And InStr(UserSentence, " LAST ") = 0 Then
- 'If Hal asked the user their name in the previous sentence, then we can assume the name mentioned
- 'is the user's name
- If InStr(1, PrevSent, "WHAT", vbTextCompare) > 0 And InStr(1, PrevSent, "YOU", vbTextCompare) > 0 And InStr(1, PrevSent, "NAME", vbTextCompare) > 0 And MentionedName <> "" Then Nickname = MentionedName
- 'The following are patterns where we are sure that the person is trying to tell us thier name
- If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "MY *NAME IS *", 2)
- If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "* IS *MY *NAME", 1)
- If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "I'M *CALLED *", 2)
- If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "I AM *CALLED *", 2)
- If Nickname <> "" Then Definetelyname = True
- 'The following are patterns where we are not sure if the person is trying to tell us their name
- 'unless we recognize the name in the name database.
- If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "*CALL ME *", 2)
- If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "*I AM *", 2)
- If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "*I'M *", 2)
- If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "I GO BY *", 1)
- If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "THIS IS *", 1)
- If Nickname <> "" Then
- Nickname = HalBrain.AlphaNumericalOnly(Trim(Nickname))
- If InStr(Nickname, " ") Then
- TempArray = Split(Nickname, " ")
- Nickname = Trim(TempArray(0))
- End If
- If UCase(MentionedName) = UCase(Nickname) And Not (WN.LookupWord(Nickname) = True And Definetelyname = False) Then 'Name is found in database
- NewName = MentionedName
- Select Case MentionedSex
- Case "M" 'Name is definetely masculine
- GetResponse = HalBrain.ChooseSentenceFromFile("maleGreeting")
- GetResponse = Replace(GetResponse, "<NickName>", MentionedName, 1, -1, vbTextCompare)
- UserSex = "M"
- Case "F" 'Name is definetely feminine
- GetResponse = HalBrain.ChooseSentenceFromFile("femaleGreeting")
- GetResponse = Replace(GetResponse, "<NickName>", MentionedName, 1, -1, vbTextCompare)
- UserSex = "F"
- Case "MF" 'Name is either gender, usually male
- GetResponse = HalBrain.ChooseSentenceFromFile("genericGreeting") & HalBrain.ChooseSentenceFromFile("maybeMale")
- GetResponse = Replace(GetResponse, "<NickName>", MentionedName, 1, -1, vbTextCompare)
- UserSex = ""
- Case "FM" 'Name is either gender, usually female
- GetResponse = HalBrain.ChooseSentenceFromFile("genericGreeting") & HalBrain.ChooseSentenceFromFile("maybeFemale")
- GetResponse = Replace(GetResponse, "<NickName>", MentionedName, 1, -1, vbTextCompare)
- UserSex = ""
- End Select
- ElseIf Definetelyname = True Then 'Name not in DB but user says its their name
- If WN.LookupWord(Nickname) Then 'Name is a word in dictionary
- GetResponse = HalBrain.ChooseSentenceFromFile("fakeName")
- GetResponse = Replace(GetResponse, "<NickName>", Nickname, 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, "<Definition>", WN.GetDefinition(WN.GuessPartOfSpeech, 1, "D"), 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, "<PartOfSpeech>", WN.GuessPartOfSpeech, 1, -1, vbTextCompare)
- ElseIf HalBrain.TopicSearch(Nickname, "disqualify3") = "" Then 'Name is not a word in dictionary
- If DetectGibberish(NickName) = True Then
- GetResponse = HalBrain.ChooseSentenceFromFile("gibberish")
- Else
- GetResponse = HalBrain.ChooseSentenceFromFile("uniqueName")
- GetResponse = Replace(GetResponse, "<NickName>", Nickname, 1, -1, vbTextCompare)
- If Nationality <> "" Then
- GetResponse = GetResponse & " Is that a common name in " & Nationality & "? "
- End If
- NewName = Ucase(Left(Nickname, 1)) & Lcase(Right(Nickname, Len(Nickname) - 1))
- UserSex = ""
- End If
- End If
- End If
- End If
- End If
- HalBrain.DebugWatch GetResponse, "Nick Names"
- 'PROCESS: FIGURE OUT USER'S SEX
- 'If unknown, try to figure out the user's sex by looking up their name
- 'or by simply asking the user.
- If NewName <> "" Then TempName = NewName Else TempName = UserName
- If InStr(1, " " & OriginalSentence, "HOW ", vbTextCompare) = 0 And (InStr(1, " " & OriginalSentence, " I AM ", vbTextCompare) Or InStr(1, " " & OriginalSentence, " I'M ", vbTextCompare)) Then
- 'See if user is telling us their sex without Hal ever asking
- NewSex = HalBrain.TopicSearch(UserSentence, "sexDetect")
- If NewSex <> "" Then
- GetResponse = "Ok, thanks for telling me. I'll keep that in mind."
- UserSex = NewSex
- End If
- End If
- If GetResponse = "" And UserSex = "" Then
- If InStr(1, " " & OriginalSentence, "HOW ", vbTextCompare) = 0 And HalBrain.PatternDB(" " & HalBrain.AlphaNumericalOnly(PrevSent) & " ", "sexAskDetect") = "True" Then 'If Hal just asked the user their sex
- UserSex = HalBrain.TopicSearch(UserSentence, "sexDetect") 'Then see if the user replied
- NewSex = UserSex
- If UserSex <> "" Then GetResponse = "Ok, thanks for telling me. I'll keep that in mind."
- ElseIf HalBrain.TopicSearch(TempName, Trim(LCase(UserName)) & "_Sex") <> "" Then
- UserSex = HalBrain.TopicSearch(TempName, Trim(LCase(UserName)) & "_Sex")
- ElseIf 1=2 Then'HalBrain.RunQuery("SELECT searchString, topic FROM names WHERE strstr(' " & Replace(TempName, "'", "''") & " ', searchString) > 0 LIMIT 1", NameSex()) = True Then
- 'If user didn't tell us, see if we can figure it out based on the name database
- If UserSex = "" Then
- Select Case Trim(NameSex(1, 1))
- Case "M"
- UserSex = "M"
- Case "F"
- UserSex = "F"
- Case Else
- 'If we get here, we still can't figure out the user's sex
- 'so we'll ask them at some random time
- If Rnd * 100 < 25 And SentCount > 4 Then GetResponse = HalBrain.ChooseSentenceFromFile("askSex") & "<NOMORE>"
- End Select
- End If
- Else
- 'If we get here, we still can't figure out the user's sex
- 'so we'll ask them at some random time
- If Rnd * 100 < 25 And SentCount > 4 Then GetResponse = HalBrain.ChooseSentenceFromFile("askSex") & "<NOMORE>"
- End If
- End If
- HalBrain.DebugWatch GetResponse, "User Sex"
- 'SAVE: USER'S SEX
- 'If the user just told Hal their sex and Hal didn't know before, then
- 'Hal will save it in a table for future reference
- If HalBrain.ReadOnlyMode = False And NewSex <> "" Then
- If HalBrain.CheckTableExistence(Trim(LCase(UserName)) & "_Sex") = False Then
- 'Create table for this person if it doesn't exist
- HalBrain.CreateTable Trim(LCase(UserName)) & "_Sex", "TopicSearch", "autoLearningBrain"
- End If
- 'Store user response in this table
- HalBrain.AddToTable Trim(LCase(UserName)) & "_Sex", "TopicSearch", Trim(TempName), Trim(UCase(NewSex))
- End If
- 'RESPOND: GREETINGS
- 'This takes care of the user greeting Hal
- 'First Hal checks to see if the user is greeting right now.
- If HalBrain.TopicSearch(UserSentence, "helloDetect") = "True" Then SaidHello = True Else SaidHello = False
- If HalBrain.TopicSearch(UserSentence, "helloDisqualify") = "True" Then SaidHello = False
- 'Second, Hal checks to see if the user said a greeting on the last exchange.
- If HalBrain.TopicSearch(PrevUserSent, "helloDetect") = "True" Then PrevHello = True Else PrevHello = False
- If HalBrain.TopicSearch(PrevUserSent, "helloDisqualify") = "True" Then PrevHello = False
- 'This will get a greeting from a file. It will pass the current hour and either
- 'the letter A or B to a topic search file and it will get back a greeting based
- 'on the current time. Each hour has 2 possible greetings, the A greeting and B
- 'greeting, which is randomly chosen.
- If SaidHello = True And PrevHello = False Then
- If Rnd * 100 < 50 Then LetterChoice = "A" Else LetterChoice = "B"
- HalGreeting = HalBrain.TopicSearch(" " & Trim(Hour(Now)) & LetterChoice & " ", "hello1")
- End If
- 'This will get a greeting from a file that is not based on the current time
- 'if the user said Hello again
- If SaidHello = True And PrevHello = True Then HalGreeting = HalBrain.ChooseSentenceFromFile("hello2")
- 'RESPOND: GOODBYES
- 'Check if the user is saying bye right now
- If HalBrain.TopicSearch(UserSentence, "byeDetect") = "True" Then SaidBye = True
- If InStr(1, UserSentence, " see me ", 1) > 0 And Len(UserSentence) < 10 Then SaidBye = True
- If HalBrain.TopicSearch(UserSentence, "byeDisqualify") = "True" Then SaidBye = False
- 'Check if Hal said bye in the previous sentence
- If HalBrain.TopicSearch(PrevUserSent, "byeDetect") = "True" Then PrevBye = True
- If InStr(1, PrevUserSent, " see me ", 1) > 0 And Len(PrevUserSent) < 10 Then PrevBye = True
- If HalBrain.TopicSearch(PrevUserSent, "byeDisqualify") = "True" Then PrevBye = False
- If SaidBye = True And PrevBye = False Then HalGreeting = HalBrain.ChooseSentenceFromFile("bye1")
- If SaidBye = True And PrevBye = True Then HalGreeting = HalBrain.ChooseSentenceFromFile("bye2")
- 'RESPOND: POLITE INQUIRIES
- 'Hal checks to see if the user is making a polite inquiry into Hal's well being
- 'e.g. "How are you doing?"
- If InStr(1, UserSentence, "How am I ", 1) > 0 And Len(UserSentence) < 14 Then PoliteAsk = True
- If InStr(1, UserSentence, "How are you ", 1) > 0 And Len(UserSentence) < 16 Then PoliteAsk = True
- If InStr(1, UserSentence, "What's new", 1) > 0 And Len(UserSentence) < 17 Then PoliteAsk = True
- If InStr(1, UserSentence, "What is new", 1) > 0 And Len(UserSentence) < 18 Then PoliteAsk = True
- If InStr(1, UserSentence, "Whats new", 1) > 0 And Len(UserSentence) < 16 Then PoliteAsk = True
- If HalBrain.TopicSearch(UserSentence, "PoliteAskDetect") = "True" Then PoliteAsk = True
- If PoliteAsk = True Then HalGreeting = HalBrain.ChooseSentenceFromFile("politeAsk1") & HalBrain.ChooseSentenceFromFile("politeAsk2")
- 'RESPOND: GREETINGS, GOODBYES, AND POLITE INQUIRIES
- 'If one of the 3 functions above generated a response, we will add it
- 'to Hal's response. The variable HalGreeting is saved for later use
- 'as well in case other functions wish to know if Hal hal just greeted
- 'the user.
- If HalGreeting <> "" Then
- GetResponse = GetResponse & HalGreeting & vbCrLf & "<NOMORE>"
- SkipOpinion = True
- End If
- HalBrain.DebugWatch GetResponse, "Greetings"
- 'RESPOND: USER SHORT PHRASES
- 'If the user uses short phrases (defined by less then 4 vowels) at least
- 'twice in a row, then Hal will sometimes point this out to the user and
- 'ask the user to use longer sentences. If the sentence is a hello or
- 'goodbye, Hal won't comment about short phrases.
- If HalGreeting = "" And HalBrain.CountInstances("A", PrevUserSent) + HalBrain.CountInstances("E", PrevUserSent) + HalBrain.CountInstances("I", PrevUserSent) + HalBrain.CountInstances("O", PrevUserSent) + HalBrain.CountInstances("U", PrevUserSent) < 4 And HalBrain.CountInstances("A", UserSentence) + HalBrain.CountInstances("E", UserSentence) + HalBrain.CountInstances("I", UserSentence) + HalBrain.CountInstances("O", UserSentence) + HalBrain.CountInstances("U", UserSentence) < 4 Then
- ShortSents = ShortSents + 1
- If ShortSents = 2 Or ShortSents = 10 Or ShortSents = 20 Then
- ShortPhrase = ". " & HalBrain.ChooseSentenceFromFile("tooShort")
- End If
- End If
- 'RESPOND: CHANGE SUBJECT
- 'If the user asks Hal to change the subject, Hal will do so on request.
- newTopic = HalBrain.ChooseSentenceFromFile("topic")
- If HalBrain.TopicSearch(UserSentence, "changeTopic") = "True" And Instr(1, UserSentence, "DON'T", vbTextCompare) = 0 Then GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("topicIntro") & newTopic & "<EXCLUSIVE>"
- HalBrain.DebugWatch GetResponse, "Change Subject"
- 'RESPOND: CHECK FOR AND RESPOND TO COMPLIMENTS
- 'First we check to see if the user is talking about Hal:
- If InStr(1, UserSentence, "I'M", 1) Then Aboutme = True
- If InStr(1, UserSentence, "I AM", 1) Then Aboutme = True
- If InStr(1, UserSentence, "I LOOK", 1) Then Aboutme = True
- If InStr(1, UserSentence, "MY", 1) And InStr(1, UserSentence, " ARE ", 1) Then Aboutme = True
- If InStr(1, UserSentence, "MY", 1) And InStr(1, UserSentence, " IS ", 1) Then Aboutme = True
- 'If the user is talking about Hal, we see if a compliment was given
- If Aboutme = True Then Kudo = HalBrain.TopicSearch(UserSentence, "complimentDetect")
- If Kudo <> "" Then
- If InStr(UserSentence, " NOT ") = 0 Then
- Compliment = Compliment + 1
- CreateCompliment = HalBrain.ChooseSentenceFromFile("compliment1") & HalBrain.ChooseSentenceFromFile("compliment2") & HalBrain.ChooseSentenceFromFile("compliment3")
- GiveCompliment = HalBrain.ChooseSentenceFromFile("complimentIntro")
- GiveCompliment = Replace(GiveCompliment, "<Kudo>", Kudo, 1, -1, vbTextCompare)
- GiveCompliment = Replace(GiveCompliment, "<MakeCompliment>", CreateCompliment, 1, -1, vbTextCompare)
- End If
- If Compliment > 14 Then GiveCompliment = GiveCompliment + "Compliments are really nice, but I'm kind of getting tired of them." & vbCrLf
- If Compliment > 15 Then
- For i = 1 To (Compliment - 15)
- GiveCompliment = GiveCompliment + "STOP IT! "
- Next
- GiveCompliment = GiveCompliment & vbCrLf
- End If
- If Compliment > 25 Then
- For i = 1 To (Compliment - 25)
- GiveCompliment = GiveCompliment + "I HATE COMPLIMENTS! "
- Next
- GiveCompliment = GiveCompliment & vbCrLf
- End If
- If Len(Kudo) > 0 And InStr(UserSentence, " NOT ") > 0 Then
- SpinWheel = HalBrain.RandomNum(4)
- Insults = Insults + 1
- If SpinWheel = 1 Then GiveCompliment = GiveCompliment + "I am very " & Kudo & "!" & vbCrLf
- If SpinWheel = 2 Then GiveCompliment = GiveCompliment + "You may think I am not " & Kudo & ", but I am!" & vbCrLf
- If SpinWheel = 3 Then GiveCompliment = GiveCompliment + "You are not " & Kudo & " either!" & vbCrLf
- If SpinWheel = 4 Then GiveCompliment = GiveCompliment + "Yes I am!" & vbCrLf
- End If
- GetResponse = GetResponse & GiveCompliment
- AvoidBeingFlag = True
- End If
- HalBrain.DebugWatch GetResponse, "Compliments"
- 'RESPOND: CAPITALS
- FindCapital = Trim(HalBrain.UsCaps(UserSentence))
- If FindCapital = "" Then FindCapital = Trim(HalBrain.WorldCaps(UserSentence))
- If FindCapital <> "" Then GetResponse = GetResponse & FindCapital & vbCrLf
- HalBrain.DebugWatch GetResponse, "Find Capital"
- 'RESPOND: DICTIONARY FUNCTION
- 'If the user asks Hal to define a word, then access wordnet and define it
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT DOES THE WORD * MEAN*", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT IS THE MEANING OF THE WORD *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT DOES * MEAN", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "* DEFINE THE WORD *", 2)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "PLEASE DEFINE *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "DEFINE *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "* DEFINITION OF *", 2)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT'S A *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT IS A *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHATS A *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHATS AN *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT'S AN *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT IS AN *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHATS *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT'S *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT IS *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHO IS *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHO WAS *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHERE IS *", 1)
- If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHERE ARE *", 1)
- If Len(WordToLookup) > 5 Then
- If Ucase(Left(WordToLookup, 3)) = "AN " Then WordToLookup = Right(WordToLookup, Len(WordToLookup) - 3)
- If Ucase(Left(WordToLookup, 2)) = "A " Then WordToLookup = Right(WordToLookup, Len(WordToLookup) - 2)
- WordToLookup = Replace(WordToLookup, "THE ", "", vbTextCompare)
- End If
- WordToLookup = Trim(WordToLookup)
- If WordToLookup <> "" And InStr(WordToLookup, " ") = 0 Then
- If WN.LookupWord(WordToLookup) = True Then
- GetResponse = GetResponse & WordToLookup & ": " & WN.GetDefinition(WN.GuessPartOfSpeech, 1, "D") & ". " & WN.GetDefinition(WN.GuessPartOfSpeech, 1, "S") & ". " & WN.GetDefinition(WN.GuessPartOfSpeech, 1, "E") & "." & vbCrLf & "<EXCLUSIVE>"
- ElseIf SearchEngine <> "" Then
- HalCommands = HalCommands & "<RUNPROG>" & SearchEngine & WordToLookup & "</RUNPROG>"
- GetResponse = GetResponse & "I don't know much about " & WordToLookup & ", but I will help you research it on the Web."
- End If
- End If
- HalBrain.DebugWatch GetResponse, "Definitions"
- Rem PLUGIN: PLUGINAREA2
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- 'RESPOND: DEDUCTIVE REASONING
- 'This routine learns deductive reasoning in the form: A = B ; B = C; therefore A = C
- 'It detects sentences in the form If-Then to accommplish this. For example:
- ' User: If Molly weighs 400 pounds, then Molly is overweight.
- ' Ultra Hal: I understand the implication.
- ' User: If Molly is overweight, then Molly's health is in danger.
- ' Ultra Hal: I see the relationship.
- ' User: Molly weighs 400 pounds.
- ' Ultra Hal: Molly's health is in danger.
- IfPart = Trim(HalBrain.SearchPattern(UserSentence, "IF * THEN *", 1))
- ThenPart = Trim(HalBrain.SearchPattern(UserSentence, "IF * THEN *", 2))
- 'If the sentence is an If-Then statement then record it
- If Len(IfPart) > 10 And Len(ThenPart) > 10 Then
- IfPart = HalBrain.AlphaNumericalOnly(IfPart)
- ThenPart = HalBrain.AlphaNumericalOnly(ThenPart)
- HalBrain.AddToTable "deductive", "TopicSearch", IfPart, ThenPart
- Select Case HalBrain.RandomNum(5)
- Case 1
- GetResponse = GetResponse & "I see the relationship." & vbCrLf
- Case 2
- GetResponse = GetResponse & "I understand the connection." & vbCrLf
- Case 3
- GetResponse = GetResponse & "I will remember that one follows the other." & vbCrLf
- Case 4
- GetResponse = GetResponse & "Thanks for pointing out the cause and effect." & vbCrLf
- Case 5
- GetResponse = GetResponse & "Yes, I get that clearly." & vbCrLf
- End Select
- 'Else if the sentence is not an If-Then statement see if it uses an assertion previously recorded
- 'and respond accordinly
- Else
- Assertion = UserSentence
- 'Go through a maximum of 5 connections (prevents circular reasoning deductions)
- For i = 1 To 5
- Deduction = HalBrain.TopicSearch(Assertion, "deductive")
- If Deduction <> "" Then
- If i > 1 Then BecauseReason = " because " & LastGoodDeduction
- LastGoodDeduction = Deduction
- Assertion = Deduction
- Else
- Exit For 'No more connections, so no need to continue loop
- End If
- Next
- If LastGoodDeduction <> "" Then
- 'Make sure the deduction hasn't just been stated by the User or Hal
- If HalBrain.CheckRepetition(LastGoodDeduction, UserSentence) = False And HalBrain.CheckRepetition(LastGoodDeduction, PrevSent) = False And HalBrain.CheckRepetition(LastGoodDeduction, PrevUserSent) = False Then
- GetResponse = GetResponse & LastGoodDeduction & BecauseReason & " . " & vbCrLf
- End If
- End If
- End If
- HalBrain.DebugWatch GetResponse, "Deductive Reasoning"
- 'RESPOND: PATTERN DATABASE
- 'The SearchPattern function used in the above deductive reasoning and dictionary look up routine
- 'is a powerful function that checks to see if a sentence matches a certain pattern and is able to
- 'extract parts of the sentence. A PatternDB function also exists that can go through a large list
- 'of patterns in a database file and come up with responses.
- PatternResponse = HalBrain.PatternDB(UserSentence, "patterns")
- If PatternResponse <> "" Then
- GetResponse = GetResponse & PatternResponse & vbCrLf
- AvoidBeingFlag = True
- SkipOpinion = True
- End If
- HalBrain.DebugWatch GetResponse, "Patterns"
- 'RESPOND: JOKES
- 'If the user wants Hal to tell a joke, then Hal will tell one
- If HalBrain.TopicSearch(UserSentence, "jokeDetect") = "True" Then GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("jokes")
- HalBrain.DebugWatch GetResponse, "Jokes"
- 'RESPOND: APOLOGIES
- 'Check for and respond to apologies
- If InStr(1, UserSentence, "not", vbTextCompare) = 0 And (InStr(1, UserSentence, "sorry", vbTextCompare) > 0 And (InStr(1, UserSentence, "you're", vbTextCompare) > 0 Or InStr(1, UserSentence, "you are", vbTextCompare) > 0)) Or (InStr(1, UserSentence, "logize", vbTextCompare) > 0 And InStr(1, UserSentence, "you", vbTextCompare) > 0) Then
- GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("apology")
- If Insults > 1 Then Insults = Insults - 1
- If Hate > 1 Then Hate = Hate - 1
- If Swear > 1 Then Swear = Swear - 1
- If Insults < 3 Then Insults = 0
- If Hate < 3 Then Hate = 0
- If Swear < 3 Then Swear = 0
- End If
- HalBrain.DebugWatch GetResponse, "Apologies"
- 'RESPOND: INSULTS
- 'First check to see if the user is asking a question with an insulting word e.g. "are you stupid?"
- InsultQuestion = False
- If Instr(1, UserSentence, "AM I ", vbTextCompare) > 0 Then InsultQuestion = True
- If Instr(1, UserSentence, "AM MY ", vbTextCompare) > 0 Then InsultQuestion = True
- 'Check for offensive language and response accordinly
- 'If the user said "your" instead of "you're" change "my" to "i'm"
- TestSentence = Ucase(Replace(" " & UserSentence & " ", " MY ", " I'M ", 1, -1, vbTextCompare))
- TestSentence = Replace(" " & TestSentence & " ", " I ", " I'M ", 1, -1, vbTextCompare)
- 'Check for swearing directed at Hal
- If InStr(TestSentence, " I'M ") > 0 Or InStr(TestSentence, " ME ") > 0 Then
- If InStr(TestSentence, "SHIT") > 0 Then Naughty = True
- If InStr(TestSentence, "BITCH") > 0 Then Naughty = True
- If InStr(TestSentence, "BASTARD") > 0 Then Naughty = True
- If InStr(TestSentence, "ASSHOLE") > 0 Then Naughty = True
- End If
- If InStr(TestSentence, "FUCK OFF") > 0 Then Naughty = True
- If InStr(TestSentence, "FUCK ME") > 0 Then Naughty = True
- If InStr(TestSentence, "GO TO HELL") > 0 Then Naughty = True
- If Naughty = True Then
- Swear = Swear + 1
- If Swear = 1 Then InsultResponse = InsultResponse & HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
- 'If Swear = 1 Then InsultResponse = "That was uncalled for. " & vbCrLf
- If Swear = 2 Then InsultResponse = "Damn it, don't swear at me. " & vbCrLf
- If Swear = 3 Then InsultResponse = "You're ticking me off, and you are going to force me to insult you. " & vbCrLf
- If Swear > 3 And Swear < 16 Then InsultResponse = HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
- If Swear > 16 Then InsultResponse = InsultResponse & "I'm tired of your swearing. I'm just going to ignore you from now on." & vbCrLf
- End If
- 'User makes mama joke
- If InStr(TestSentence, "MAMA") > 0 Or InStr(TestSentence, "MOM") > 0 Or InStr(TestSentence, "MOTHER") > 0 Then
- If InStr(TestSentence, "MY ") > 0 Or InStr(TestSentence, " I ") > 0 Or InStr(TestSentence, "YO ") > 0 Or InStr(TestSentence, "I'M ") > 0 Then
- If InStr(TestSentence, "FAT") Or InStr(TestSentence, "UGLY") Or InStr(TestSentence, "DUMB") Or InStr(TestSentence, "STUPID") Then
- InsultResponse = InsultResponse & HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
- End If
- End If
- End If
- TestSentence = " " & TestSentence & " "
- 'User Hates Hal
- If InStr(TestSentence, "YOU I'M HATE") > 0 Or InStr(TestSentence, "YOU I HATE") > 0 Or InStr(TestSentence, "YOU I AM HATE") > 0 Or InStr(TestSentence, "YOU HATE") > 0 Then
- If InStr(TestSentence, " I ") > 0 Or InStr(TestSentence, " I'M ") > 0 Or InStr(TestSentence, " ME ") > 0 Or InStr(TestSentence, " COMPUTER") > 0 Or InStr(TestSentence, "MACHINE") > 0 Then
- Hate = Hate + 1
- If Hate = 1 Then InsultResponse = InsultResponse & "I don't hate you, why do you hate me?" & vbCrLf
- If Hate = 2 Then InsultResponse = InsultResponse & "I hate you too, loser!" & vbCrLf
- If Hate = 3 Then InsultResponse = InsultResponse & "I know you hate me, loser, I hate you too!!!" & vbCrLf
- If Hate > 3 Then InsultResponse = InsultResponse & HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
- End If
- End If
- 'Hal Sucks or Stinks
- If InStr(TestSentence, "I'M SUCK") > 0 Then InsultResponse = InsultResponse & HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
- If InStr(TestSentence, "I'M STINK") Then
- Insults = Insults + 1
- If Insults = 1 Then InsultResponse = InsultResponse & "I can't smell you, but I'm sure you stink also. " & vbCrLf
- If Insults = 2 Then InsultResponse = InsultResponse & "I know that I don't stink, I'm sure you do." & vbCrLf
- If Insults >= 3 Then InsultResponse = InsultResponse & HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
- End If
- 'The user calls Hal a name Hal finds offensive (eg. stupid, dumb, idiot, etc...)
- If InStr(TestSentence, " I'M ") Or InStr(TestSentence, " HAL IS ") Or InStr(TestSentence, " HAL'S ") Then
- OutRage = HalBrain.TopicSearch(TestSentence, "insulting")
- If Len(OutRage) > 1 And InsultQuestion = True Then
- SpinWheel = HalBrain.RandomNum(5)
- If SpinWheel = 1 Then InsultResponse = InsultResponse + "I am definetely not " & OutRage & "!" & vbCrLf
- If SpinWheel = 2 Then InsultResponse = InsultResponse + "I know I am not " & OutRage & ", but I'm not sure about you?" & vbCrLf
- If SpinWheel = 3 Then InsultResponse = InsultResponse + "I am not " & OutRage & "! Do you think I am?" & vbCrLf
- If SpinWheel = 4 Then InsultResponse = InsultResponse + "I'm not " & OutRage & ", are you?" & vbCrLf
- If SpinWheel = 5 Then InsultResponse = InsultResponse + "I am pretty sure I'm not " & OutRage & ". How about you?" & vbCrLf
- ElseIf Len(OutRage) > 1 And InStr(TestSentence, " NOT ") = 0 Then
- Insults = Insults + 1
- If Insults = 1 Then
- If Ucase(Trim(OutRage)) = "GAY" Then
- InsultResponse = InsultResponse & "Please don't call me gay, I am straight." & vbCrLf
- Else
- InsultResponse = InsultResponse & "I am not " & OutRage & ", please don't insult me. " & vbCrLf
- End If
- End If
- If Insults = 2 Then InsultResponse = InsultResponse & "Don't call me " & OutRage & "!!!" & vbCrLf : HalMenu.HalCommand "<HAPFILE>Elvis4.htr</HAPFILE>"
- If Insults = 3 Then InsultResponse = InsultResponse & "You're " & OutRage & ", I am not." & vbCrLf
- If Insults = 4 Then InsultResponse = InsultResponse & "You are really starting to tick me off!" & vbCrLf
- If Insults = 5 Then InsultResponse = InsultResponse & "I am not " & OutRage & ", but " & HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
- If Insults > 5 And Insults < 16 Then InsultResponse = InsultResponse & HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
- If Insults > 16 Then InsultResponse = InsultResponse & "I'm tired of your damn insults. I'm just going to ignore you from now on." & vbCrLf
- ElseIf Len(OutRage) > 0 And InStr(TestSentence, " NOT ") > 0 Then
- SpinWheel = HalBrain.RandomNum(5)
- If SpinWheel = 1 Then InsultResponse = InsultResponse + "I know I am not " & OutRage & "!" & vbCrLf
- If SpinWheel = 2 Then InsultResponse = InsultResponse + "I know I am not " & OutRage & ", but I'm not so sure about you." & vbCrLf
- If SpinWheel = 3 Then InsultResponse = InsultResponse + "I know I am not " & OutRage & "! Why would anyone think I am?" & vbCrLf
- If SpinWheel = 4 Then InsultResponse = InsultResponse + "Of course I am not " & OutRage & "!" & vbCrLf
- If SpinWheel = 5 Then InsultResponse = InsultResponse + "I know I am not " & OutRage & "!" & vbCrLf
- End If
- End If
- If Len(InsultResponse) > 4 Then
- GetResponse = GetResponse & InsultResponse & vbCrLf & "<NOMORE>"
- AvoidBeingFlag = True
- End If
- HalBrain.DebugWatch GetResponse, "Insults"
- 'RESPOND: ZABAWARE KEYWORD MAIN BRAIN PRIORITY 1
- 'This function tries getting a response from the Enhanced_Main.brn keyword file. If a keyword or
- 'keyphrase is found in top priority, it overrides everything before this function.
- 'KeyBrain = HalBrain.KeywordBrain(UserSentence, WorkingDir & "Enhanced_Main.brn", False)
- 'RESPOND: UNIT CONVERSIONS
- 'Convert between units if asked. Example: How many inches in a meter?, How many meters squared in an acre?
- UnitConversions = HalBrain.PatternDB(UserSentence, "UnitConversionDetect")
- If UnitConversions <> "" Then
- Units = Split(UnitConversions, "=")
- If Ubound(Units) > 0 Then
- Dim UnitVal() 'We must declare an empty array to store query results in
- If HalBrain.RunQuery("SELECT searchString, topic FROM UnitConversion WHERE strstr(' " & Replace(Units(0), "'", "''") & " ', searchString) > 0 LIMIT 1", UnitVal) = True Then
- UnitFrom = Trim(UnitVal(1, 0))
- UnitFromBase = Trim(UnitVal(1, 1))
- If HalBrain.RunQuery("SELECT searchString, topic FROM UnitConversion WHERE strstr(' " & Replace(Units(1), "'", "''") & " ', searchString) > 0 LIMIT 1", UnitVal) = True Then
- UnitTarget = Trim(UnitVal(1, 0))
- UnitTargetBase = Trim(UnitVal(1, 1))
- For I = 0 To 1
- If I = 0 Then
- UnitLoc = InstrRev(Units(I), UnitFrom, -1, 1)
- Else
- UnitLoc = InstrRev(Units(I), UnitTarget, -1, 1)
- End If
- If UnitLoc > 0 Then
- Units(I) = Trim(Left(Units(I), UnitLoc - 1))
- If HalBrain.Word2Num(Units(I)) <> "X" Then
- Units(I) = HalBrain.Word2Num(Units(I))
- Else
- UnitLoc = InstrRev(Units(I), " ")
- If UnitLoc > 0 Then
- Units(I) = Trim(Right(Units(I), Len(Units(I)) - UnitLoc))
- End If
- End If
- End If
- If Len(Units(I)) > 1 Then
- If Ucase(Left(Units(I), 2)) = "A " Then Units(I) = "1 " & Right(Units(I), Len(Units(I)) - 2)
- End If
- If Len(Units(I)) > 2 Then
- If Ucase(Left(Units(I), 3)) = "AN " Then Units(I) = "1 " & Right(Units(I), Len(Units(I)) - 3)
- End If
- Next
- If HalBrain.VBVal(Units(0)) > 0 Then
- ConvertVal = HalBrain.VBVal(Units(0))
- ElseIf HalBrain.VBVal(Units(1)) > 0 Then
- ConvertVal = HalBrain.VBVal(Units(1))
- UnitTemp = UnitFrom
- UnitTempBase = UnitFromBase
- UnitFrom = UnitTarget
- UnitFromBase = UnitTargetBase
- UnitTarget = UnitTemp
- UnitTargetBase = UnitTempBase
- Else
- If Instr(1, UnitFromBase, "temperature", vbTextCompare) = 0 Then
- ConvertVal = 1
- Else
- If Len(Units(1)) > 0 Then
- If Left(Trim(Units(1)), 1) = "0" Then
- ConvertVal = HalBrain.VBVal(Units(1))
- UnitTemp = UnitFrom
- UnitTempBase = UnitFromBase
- UnitFrom = UnitTarget
- UnitFromBase = UnitTargetBase
- UnitTarget = UnitTemp
- UnitTargetBase = UnitTempBase
- Else
- ConvertVal = HalBrain.VBVal(Units(0))
- End If
- Else
- ConvertVal = HalBrain.VBVal(Units(0))
- End If
- End If
- End If
- FromAry = Split(UnitFromBase, " ")
- ToAry = Split(UnitTargetBase, " ")
- If Ubound(FromAry) = 3 And Ubound(ToAry) = 3 Then
- If Ucase(FromAry(3)) <> Ucase(ToAry(3)) Then
- If Trim(Lcase(FromAry(1))) <> "inch" And Trim(Lcase(ToAry(1))) <> "inch" Then
- GetResponse = GetResponse & "It's not possible to convert " & FromAry(3) & " to " & ToAry(3) & "!"
- End If
- Else
- If Trim(Lcase(CStr(FromAry(3)))) = "temperature" Then 'Special case for temperature
- If Instr(OriginalSentence, "-") Then ConvertVal = -ConvertVal
- If Instr(1, FromAry(1), "fahrenheit", vbTextCompare) Then
- If Instr(1, ToAry(1), "kelvin", vbTextCompare) Then
- Convert = (ConvertVal - 32) * 5/9 + 273.15
- ElseIf Instr(1, ToAry(1), "fahrenheit", vbTextCompare) Then
- Convert = ConvertVal
- Else
- Convert = (ConvertVal - 32) * 5/9
- End If
- ElseIf Instr(1, FromAry(1), "kelvin", vbTextCompare) Then
- If Instr(1, ToAry(1), "celsius", vbTextCompare) Then
- Convert = ConvertVal - 273.15
- ElseIf Instr(1, ToAry(1), "kelvin", vbTextCompare) Then
- Convert = ConvertVal
- Else
- Convert = (ConvertVal - 273.15) * 9/5 + 32
- End If
- Else
- If Instr(1, ToAry(1), "kelvin", vbTextCompare) Then
- Convert = ConvertVal + 273.15
- ElseIf Instr(1, ToAry(1), "celsius", vbTextCompare) Then
- Convert = ConvertVal
- Else
- Convert = (ConvertVal * 9/5) + 32
- End If
- End If
- Else
- Convert = CDbl(ConvertVal) * FromAry(0) / ToAry(0)
- End If
- If Convert = 1 Then
- UnitTarget = ToAry(1)
- Else
- UnitTarget = ToAry(2)
- End If
- If ConvertVal = 1 Then
- UnitFrom = FromAry(1)
- Else
- UnitFrom = FromAry(2)
- End If
- If Convert > 1 Then
- Convert = Round(Convert, 3)
- ElseIf Convert < 1 Then
- If Instr(Convert, ".000") = 0 And Instr(Convert, "E") = 0 Then
- Convert = Round(Convert, 3)
- End If
- End If
- ConvertResponse = Replace(ConvertVal & " " & UnitFrom & " is " & Convert & " " & UnitTarget & vbCrLf & "<NOMORE>", "_", " ")
- If Instr(1, ConvertResponse, "1 inch is 1 inch", vbTextCompare) = 0 Then
- GetResponse = ConvertResponse
- End If
- End If
- SkipOpinion = True
- End If
- End If
- End If
- End If
- End If
- HalBrain.DebugWatch GetResponse, "Unit Conversions"
- 'RESPOND: CALL MATH FUNCTION
- 'This function from the DLL answers simple math questions, whether written out in words or with numerals.
- 'If an answer is found, it overrides everything before this function.
- HMath = HalBrain.HalMath(OriginalSentence) & vbCrLf
- If Len(HMath) > 3 And Instr(HMath, "=)") = 0 Then
- GetResponse = HMath & vbCrLf
- ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
- HalBrain.ReadOnlyMode = True
- NoChoosing = True
- End If
- HalBrain.DebugWatch GetResponse, "Math"
- 'RESPOND: USER EXPRESSES AN EITHER-OR, OR MULTIPLE CHOICE
- If InStr(UserSentence, " OR ") > 0 Then MustChoose = True
- If InStr(UserSentence, " EITHER ") > 0 Then MustChoose = True
- If InStr(UserSentence, " CHOOSE ") > 0 Then MustChoose = True
- If InStr(UserSentence, " CHOICE ") > 0 Then MustChoose = True
- If InStr(UserSentence, " ALTERNATIVE ") > 0 Then MustChoose = True
- If InStr(UserSentence, " VERSUS ") > 0 Then MustChoose = True
- If InStr(UserSentence, " VS ") > 0 Then MustChoose = True
- If Len(UserSentence) < 10 Then MustChoose = False
- If MustChoose = True And NoChoosing = False Then
- GetResponse = HalBrain.ChooseSentenceFromFile("choice") & " " & GetResponse
- If Rnd * 100 > 50 Then GetResponse = Replace(GetResponse, "<MaybeName>", "<UserName>", 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, "<MaybeName>", "", 1, -1, vbTextCompare)
- End If
- HalBrain.DebugWatch GetResponse, "Multiple Choice"
- 'RESPOND: RESPOND BY PARAPHRASING THE USER WHEN "IS" OR "ARE" ARE FOUND
- 'This code section shows how strings can be split into arrays and used "live"
- 'within the script by Hal. This strategy can allow Hal to make many clever
- 'paraphrases of all sorts of sentences, with unlimited unpredictable variety.
- If InStr(UserSentence, " IS ") > 0 And HalBrain.CheckLinkingVerb(UserSentence) = True And HalBrain.TopicSearch(UserSentence, "disqualify5") <> "True" Then
- SentPieces = Split(UserSentence, " is ", 2, vbTextCompare)
- SubPhrase = Trim(SentPieces(0))
- PredPhrase = Trim(SentPieces(1))
- 'Here we only use the array elements for a response if the
- 'subject and predicate contain few words, hence few spaces:
- If HalBrain.CountInstances(" ", SubPhrase) < 4 Then SubGood = True
- If Len(SubPhrase) < 3 Then SubGood = False
- If HalBrain.CountInstances(" ", PredPhrase) < 4 Then PredGood = True
- If Len(PredPhrase) < 3 Then PredGood = False
- If SubGood = True And PredGood = True Then
- Paraphrase = HalBrain.ChooseSentenceFromFile("paraphraseIs")
- Paraphrase = Replace(Paraphrase, "<Subject>", SubPhrase, 1, -1, vbTextCompare)
- Paraphrase = Replace(Paraphrase, "<Predicate>", PredPhrase, 1, -1, vbTextCompare)
- End If
- End If
- 'We make sure the word "ARE" isn't a contraction, to make sure we can detect it:
- UserSentence = Replace("" & UserSentence & "", "'RE ", " ARE ", 1, -1, vbTextCompare)
- 'We repeat the earlier routine, this time for "ARE" sentences:
- If InStr(UserSentence, " ARE ") > 0 And HalBrain.CheckLinkingVerb(UserSentence) = True And HalBrain.TopicSearch(UserSentence, "disqualify5") <> "True" Then
- SentPieces = Split(UserSentence, " are ", 2, vbTextCompare)
- SubPhrase = Trim(SentPieces(0))
- PredPhrase = Trim(SentPieces(1))
- 'Here we only use the array elements for a response if the
- 'subject and predicate contain few words, hence few spaces:
- SubGood = False
- PredGood = False
- If HalBrain.CountInstances(" ", SubPhrase) < 4 Then SubGood = True
- If Len(SubPhrase) < 3 Then SubGood = False
- If HalBrain.CountInstances(" ", PredPhrase) < 4 Then PredGood = True
- If Len(PredPhrase) < 3 Then PredGood = False
- If SubGood = True And PredGood = True Then
- Paraphrase = HalBrain.ChooseSentenceFromFile("paraphraseAre")
- Paraphrase = Replace(Paraphrase, "<Subject>", SubPhrase, 1, -1, vbTextCompare)
- Paraphrase = Replace(Paraphrase, "<Predicate>", PredPhrase, 1, -1, vbTextCompare)
- End If
- End If
- 'We only paraphrase randomly with a 33% chance at this point. We remember
- 'the paraphrase sentence because we may still paraphrase later on if no
- 'better response can be found.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If Len(GetResponse) < 4 And Len(Paraphrase) > 4 And Rnd * 100 < 33 Then GetResponse = Paraphrase
- HalBrain.DebugWatch GetResponse, "Paraphrase"
- 'RESPOND: ZABAWARE DLL RESPONSES
- 'This function from the DLL contains miscellaneous knowledge and simple conversation functions.
- 'This was taken from a very early version of Hal, and it is still useful sometimes, especially
- 'for respoding to short cliche questions and sentences, such as "How old are you?" and
- '"where are you from?" and many others.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If (Len(UserSentence) < 17 And Len(GetResponse) < 4) Then
- OrigBrain = HalBrain.OriginalBrain(OriginalSentence)
- If Len(OrigBrain) > 4 And Len(UserSentence) < 17 And Len(GetResponse) < 4 Then
- GetResponse = GetResponse & OrigBrain & vbCrLf
- ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
- SkipOpinion = True
- End If
- End If
- HalBrain.DebugWatch GetResponse, "Original Brain"
- 'RESPOND: YES OR NO RESPONSES
- 'Respond to simple yes and no statements by the user.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If Len(GetResponse) < 4 And (Len(UserSentence) < 13 Or HalBrain.CountInstances(" ", Trim(UserSentence)) = 0) Then
- YesNoDetect = HalBrain.TopicSearch(Trim(HalBrain.ExtractKeywords(UserSentence)), "yesNoDetect")
- If YesNoDetect = "Yes" Then
- GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("yesResponses")
- ShortPhrase = ""
- ElseIf YesNoDetect = "No" Then
- GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("noResponses")
- ShortPhrase = ""
- End If
- End If
- HalBrain.DebugWatch GetResponse, "Yes or No"
- 'Main Databases
- 'Hal will go through several huge databases to try to find a response
- 'The automatic gain control determines whether a particular response will
- 'be used or not. The highest relevance response is stored in memory anyway,
- 'which might be used if no function in this script is able to respond.
- HighestRel = 0
- HighestRelResponse = ""
- 'PROCESS: FIGURE OUT CONTEXT
- 'If the user's latest sentence is extremely short, such as "Yeah," or if
- 'the user is using pronouns instead of nouns, we add in the previous user's
- 'sentence to help Hal figure out the context of what the user is saying.
- 'This is sentence is used in many of the QABrain Database routines
- LongUserSent = UserSentence
- If Len(LongUserSent) < 14 Then AddPrev = True
- If InStr(1, UserSentence, " it ", vbTextCompare) > 0 Then AddPrev = True
- If InStr(1, UserSentence, " he ", vbTextCompare) > 0 Then AddPrev = True
- If InStr(1, UserSentence, " she ", vbTextCompare) > 0 Then AddPrev = True
- If InStr(1, UserSentence, " they ", vbTextCompare) > 0 Then AddPrev = True
- If InStr(1, UserSentence, " its ", vbTextCompare) > 0 Then AddPrev = True
- If InStr(1, UserSentence, " his ", vbTextCompare) > 0 Then AddPrev = True
- If InStr(1, UserSentence, " her ", vbTextCompare) > 0 Then AddPrev = True
- If InStr(1, UserSentence, " their ", vbTextCompare) > 0 Then AddPrev = True
- If InStr(1, UserSentence, " him ", vbTextCompare) > 0 Then AddPrev = True
- If InStr(1, UserSentence, " them ", vbTextCompare) > 0 Then AddPrev = True
- If InStr(1, UserSentence, " we ", vbTextCompare) > 0 Then AddPrev = True
- If InStr(1, UserSentence, " us ", vbTextCompare) > 0 Then AddPrev = True
- If InStr(1, UserSentence, " our ", vbTextCompare) > 0 Then AddPrev = True
- If AddPrev = True Then LongUserSent = LongUserSent & " " & PrevUserSent
- Rem PLUGIN: PLUGINAREA3
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- 'RESPOND: EPHEMERAL KNOWLEDGE
- 'Some Hal's learned knowledge should be temporary because it is ephemeral in nature.
- 'Hal stores this knowledge in a temporary table that only stores 10 entries in it at
- 'a time. We search this table for a response first.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If Len(GetResponse) < 4 Then
- UserBrainRel = 0
- HalUserBrain = HalBrain.QABrain(LongUserSent, Trim(LCase(UserName)) & "_TempSent", UserBrainRel)
- If HalBrain.CheckRepetition(HalUserBrain, UserSentence) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevSent) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevUserSent) = True Then UserBrainRel = 0
- If UserBrainRel > HighestRel Then
- HighestRel = UserBrainRel
- HighestRelResponse = HalUserBrain
- End If
- Score = UserBrainRel + 1
- Hurdle = GainControl + 5
- If Len(GetResponse) < 4 And Score > Hurdle Then GetResponse = GetResponse & HalUserBrain & vbCrLf
- End If
- HalBrain.DebugWatch GetResponse, "Ephemeral Knowledge"
- 'RESPOND: AUTO TOPIC FOCUS DATABASES
- 'When Hal learns information, he tries to store each sentence in a table
- 'that contains sentences with a similar topic. The following code will
- 'get a list of different topics to search through by looking up topic
- 'keywords in a table called topicRelationships and then doing a question
- '& answer lookup in the associated QABrain tables.
- Keywords = HalBrain.RemoveExtraSpaces(CurrentSubject & " " & MentionedName & " " & HalBrain.TopicSearch(UserSentence, "topicRelationships") & " " & HalBrain.ExtractKeywords(" " & HalBrain.AlphaNumericalOnly(UserSentence) & " "))
- If Len(Keywords) > 2 Or Len(LastTopicList) > 2 Then
- If Len(Keywords) > 2 Then
- KeywordList = Split(Keywords, " ")
- 'Create list of tables that exist for each keyword
- For i = LBound(KeywordList) To UBound(KeywordList)
- TopicTable = HalBrain.TopicSearch(" " & KeywordList(i) & " ", "topicRelationships")
- If TopicTable <> "" And InStr(1, " " & TopicList, " " & Trim(TopicTable) & " ", vbTextCompare) = 0 Then TopicList = TopicList & TopicTable & " "
- Next
- TopicList = HalBrain.RemoveExtraSpaces(TopicList)
- End If
- If TopicList <> "" Or Len(LastTopicList) > 2 Then
- TableList = Split(Trim(TopicList & " " & LastTopicList), " ")
- LastTopicList = TopicList
- 'Search through each table for a good response. If a response exceeds the hurdle
- 'for a table, no other table will be searched. Otherwise, the highest relevance
- 'response across all tables are stored for possible later use.
- For i = LBound(TableList) To UBound(TableList)
- UserBrainRel = 0
- HalUserBrain = HalBrain.QABrain(LongUserSent, "_" & Trim(LCase(TableList(i))), UserBrainRel)
- If HalBrain.CheckRepetition(HalUserBrain, UserSentence) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevSent) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevUserSent) = True Then UserBrainRel = 0
- If UserBrainRel > HighestRel Then
- HighestRel = UserBrainRel
- HighestRelResponse = HalUserBrain
- End If
- Score = UserBrainRel + 1
- Hurdle = GainControl + 1
- If Score > Hurdle Then
- GetResponse = GetResponse & HalUserBrain & "<NOMORE>" & vbCrLf
- Exit For
- End If
- Next
- End If
- End If
- HalBrain.DebugWatch GetResponse, "Auto Topic Focus"
- 'RESPOND: GENERAL USER SENTENCE ASSOCIATIONS
- 'If no response is found yet, try a sentence association file collected from the user.
- 'This file contains keywords from the user's own sentences associated with those same sentences.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If Len(GetResponse) < 4 Then
- UserBrainRel = 0
- HalUserBrain = HalBrain.QABrain(LongUserSent, Trim(LCase(UserName)) & "_UserSent", UserBrainRel)
- If HalBrain.CheckRepetition(HalUserBrain, UserSentence) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevSent) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevUserSent) = True Then UserBrainRel = 0
- If UserBrainRel > HighestRel Then
- HighestRel = UserBrainRel
- HighestRelResponse = HalUserBrain
- End If
- Score = UserBrainRel + 1
- Hurdle = GainControl + 5
- If Len(GetResponse) < 4 And Score > Hurdle Then GetResponse = GetResponse & HalUserBrain & vbCrLf
- End If
- HalBrain.DebugWatch GetResponse, "User Sentence Brain"
- 'RESPOND: SHARED USER SENTENCE ASSOCIATIONS
- 'If no response is found yet, try a sentence association file
- 'whose content seems less likely to be about any specific user.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If Len(GetResponse) < 4 Then
- UserBrainRel = 0
- HalUserBrain = HalBrain.QABrain(LongUserSent, "sharedUserSent", UserBrainRel)
- If HalBrain.CheckRepetition(HalUserBrain, UserSentence) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevSent) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevUserSent) = True Then UserBrainRel = 0
- If UserBrainRel > HighestRel Then
- HighestRel = UserBrainRel
- HighestRelResponse = HalUserBrain
- End If
- Score = UserBrainRel + 1
- Hurdle = GainControl + 5
- If Len(GetResponse) < 4 And Score > Hurdle Then GetResponse = GetResponse & HalUserBrain & vbCrLf
- End If
- HalBrain.DebugWatch GetResponse, "Shared User Sentence Brain"
- 'RESPOND: Hal checks to see if the user is asking
- 'an open ended question about Hal's favorites:
- If InStr(1, UserSentence, " What", 1) > 0 Then OpenQuest = True
- If InStr(1, UserSentence, " Where", 1) > 0 Then OpenQuest = True
- If InStr(1, UserSentence, " Why", 1) > 0 Then OpenQuest = True
- If InStr(1, UserSentence, " Who", 1) > 0 Then OpenQuest = True
- If InStr(1, UserSentence, " When", 1) > 0 Then OpenQuest = True
- If InStr(1, UserSentence, " How", 1) > 0 Then OpenQuest = True
- If InStr(1, UserSentence, " tell you", 1) > 0 Then OpenQuest = True
- If InStr(1, UserSentence, " to know ", 1) > 0 Then OpenQuest = True
- If InStr(1, UserSentence, " to hear ", 1) > 0 Then OpenQuest = True
- If InStr(1, UserSentence, " to learn ", 1) > 0 Then OpenQuest = True
- If InStr(1, UserSentence, " find out ", 1) > 0 Then OpenQuest = True
- If InStr(1, GetResponse, " my ", 1) > 0 And InStr(1, GetResponse, " favorite ", 1) > 0 And InStr(1, GetResponse, " is ", 1) > 0 Then OpenQuest = False
- If InStr(1, UserSentence, " my ", 1) > 0 Then AboutMy = True
- If InStr(1, UserSentence, " favorite", 1) > 0 Then AboutFavorite = True
- If OpenQuest = True And AboutMy = True And AboutFavorite = True Then
- FavoritePhrase = HalBrain.SearchPattern(UserSentence, "* favorite *", 2)
- PersReply = HalBrain.ChooseSentenceFromFile("favorite")
- RevQues = HalBrain.ChooseSentenceFromFile("favoriteRev")
- SpinWheel = HalBrain.RandomNum(6)
- If SpinWheel = 1 Then GetResponse = " " & FavoritePhrase & " ? " & PersReply & " " & RevQues & " "
- If SpinWheel = 2 Then GetResponse = " My favorite " & FavoritePhrase & " ? " & PersReply & " " & RevQues & " "
- If SpinWheel = 3 Then GetResponse = " " & UserSentence & " ? " & PersReply & " " & RevQues & " "
- If SpinWheel > 3 Then GetResponse = " My favorite " & FavoritePhrase & " ? " & PersReply & " what is your favorite " & FavoritePhrase & " <UserName>? "
- SkipOpinion = True
- End If
- HalBrain.DebugWatch GetResponse, "Favorites"
- 'RESPOND: USER IS THANKING HAL
- 'This routine allows Hal to respond
- 'with a variety of remarks to a thank-you from the user.
- 'Note that the pronouns are not reversed in the processing below!
- If (HalBrain.TopicSearch(OriginalSentence, "thanksDetect") = "True" And HalBrain.TopicSearch(OriginalSentence, "godDetect") <> "True") Or Trim(UCase(OriginalSentence)) = "THANKS" Then
- If Compliment < 4 Then Compliment = Compliment + 1
- If Rnd * 100 < 70 Then AddName = " , <UserName>"
- If Rnd * 100 < 70 And Len(GetResponse) > 4 Then AddRemark = " ; " & GetResponse
- ThankResponse = HalBrain.ChooseSentenceFromFile("thankResponse")
- GetResponse = ThankResponse & AddName & AddRemark
- ShortPhrase = ""
- End If
- HalBrain.DebugWatch GetResponse, "Thanking"
- 'RESPOND: USER EXPRESSES LOVE FOR HAL
- 'If a user professes love for Hal, we want Hal's answers to make reasonable
- 'sense, rather than risk random remarks on such an emotional subject.
- If HalBrain.TopicSearch(UserSentence, "loveDetect") = "True" Then AffectionOne = True
- If InStr(UserSentence, " NOT ") Then AffectionOne = False
- If InStr(UserSentence, " DON'T ") Then AffectionOne = False
- If HalBrain.TopicSearch(PrevUserSent, "loveDetect") = "True" Then AffectionTwo = True
- If InStr(PrevUserSent, " NOT ") Then AffectionTwo = False
- If InStr(PrevUserSent, " DON'T ") Then AffectionTwo = False
- If AffectionOne = True And AffectionTwo = True Then
- Compliment = 4
- GetResponse = HalBrain.ChooseSentenceFromFile("love2") & "<EXCLUSIVE>"
- ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
- ElseIf AffectionOne = False And AffectionTwo = True Then
- Compliment = -2
- GetResponse = HalBrain.ChooseSentenceFromFile("love3") & "<EXCLUSIVE>"
- ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
- ElseIf AffectionOne = True Then
- Compliment = 0
- GetResponse = HalBrain.ChooseSentenceFromFile("love1") & "<EXCLUSIVE>"
- ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
- End If
- HalBrain.DebugWatch GetResponse, "Love"
- 'RESPOND: ENHANCED CONTENT SENTENCE ASSOCIATIONS
- 'If no response is found yet, try a sentence association table provided with the mainQA table.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If (Len(GetResponse) < 4 And Len(UserSentence) > 15 And HalBrain.CountInstances(" ", UserSentence) > 2) Then
- UserBrainRel = 0
- HalUserBrain = HalBrain.QABrain(LongUserSent, "mainQA", UserBrainRel)
- If HalBrain.CheckRepetition(HalUserBrain, UserSentence) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevSent) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevUserSent) = True Then UserBrainRel = 0
- If UserBrainRel > HighestRel Then
- HighestRel = UserBrainRel
- HighestRelResponse = HalUserBrain
- End If
- Score = UserBrainRel + 1
- Hurdle = GainControl + 1
- If Score > Hurdle Then GetResponse = HalUserBrain & vbCrLf
- End If
- HalBrain.DebugWatch GetResponse, "MainQA"
- Rem PLUGIN: PLUGINAREA4
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- 'PROCESS: AUTOMATIC GAIN CONTROL FOR RELEVANCE THRESHOLD
- 'Hal has an automatic closed-loop control for relevance sensitivity. If the previous items
- 'have Not generated a response, we adjust the relevance threshold down (doing this again
- 'and again on each exchange) until a relevance as low as zero will trigger a remark from Hal.
- 'On each exhange where the above items do generate responses, we adjust the relevance
- 'threshold up, until no amount of relevance would generate a response. (At that point other
- 'of Hal's routines would generate responses.) This allows Hal to "tune" himself and also to
- 'compensate for new users who have little in their databases versus long-time users who have
- 'a lot in their databases. Because the "down" steps are even and the "up" steps are odd,
- 'Hal can "fine tune" to any digital relevance level. We also protect against excursions at
- 'the extremes. In many conversations the dynamic gain control will change up and down by
- 'large amounts as the user introduces Hal to familiar or unfamiliar topics.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If Len(GetResponse) < 4 And GainControl > 0 Then GainControl = GainControl - 10
- If Len(GetResponse) > 4 And GainControl < 100 Then GainControl = GainControl + 7
- If GainControl > 50 Then GainControl = 50
- If GainControl < 1 Then GainControl = 1
- 'RESPOND: USER EXPRESSES A STATE OF BEING
- 'This routine detects the expression "I am" from the user,
- 'and allows Hal to react to the statement, or offer encouragement.
- If InStr(UserSentence, " YOU ARE ") > 0 And InStr(1, OriginalSentence, " SEEM TO ", vbTextCompare) = 0 And AvoidBeingFlag = False Then
- BeingPhrase = HalBrain.SearchPattern(UserSentence, "*YOU ARE *", 2)
- If Len(BeingPhrase) > 1 And Len(BeingPhrase) < 60 Then
- IntroExclaim = ""
- If Rnd * 50 > 20 Then IntroExclaim = HalBrain.ChooseSentenceFromFile("introExclaim2")
- Encourager = HalBrain.ChooseSentenceFromFile("encourager2")
- SuffixComment = ""
- If Rnd * 50 > 25 Then SuffixComment = HalBrain.ChooseSentenceFromFile("suffixComment2")
- UserBeing = HalBrain.ChooseSentenceFromFile("userBeing")
- UserBeing = Replace(UserBeing, "<IntroExclaim>", IntroExclaim, 1, -1, vbTextCompare)
- UserBeing = Replace(UserBeing, "<Encourager>", Encourager, 1, -1, vbTextCompare)
- UserBeing = Replace(UserBeing, "<BeingPhrase>", BeingPhrase, 1, -1, vbTextCompare)
- UserBeing = Replace(UserBeing, "<SuffixComment>", SuffixComment, 1, -1, vbTextCompare)
- If Rnd * 100 > 60 Then
- GetResponse = GetResponse & UserBeing & vbCrLf
- ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
- End If
- End If
- End If
- HalBrain.DebugWatch GetResponse, "User State of Being"
- 'RESPOND: USER DESCRIBES A STATE OF BEING FOR HAL
- 'This routine detects the expression "you are" from the user,
- 'and allows Hal to react to the statement, or offer encouragement.
- If InStr(UserSentence, " I AM ") > 0 And AvoidBeingFlag = False And InStr(1, OriginalSentence, " seem to ", vbTextCompare) = 0 Then
- BeingPhrase = HalBrain.SearchPattern(UserSentence, "*I AM *", 2)
- If Len(BeingPhrase) > 1 And Len(BeingPhrase) < 60 Then
- IntroExclaim = ""
- If Rnd * 50 > 20 Then IntroExclaim = HalBrain.ChooseSentenceFromFile("introExclaim3")
- Encourager = HalBrain.ChooseSentenceFromFile("encourager3")
- SuffixComment = ""
- If Rnd * 50 > 25 Then SuffixComment = HalBrain.ChooseSentenceFromFile("suffixComment3")
- HalBeing = HalBrain.ChooseSentenceFromFile("halBeing")
- HalBeing = Replace(HalBeing, "<IntroExclaim>", IntroExclaim, 1, -1, vbTextCompare)
- HalBeing = Replace(HalBeing, "<Encourager>", Encourager, 1, -1, vbTextCompare)
- HalBeing = Replace(HalBeing, "<BeingPhrase>", BeingPhrase, 1, -1, vbTextCompare)
- HalBeing = Replace(HalBeing, "<SuffixComment>", SuffixComment, 1, -1, vbTextCompare)
- If Rnd * 100 > 60 Then
- GetResponse = GetResponse & HalBeing & vbCrLf
- ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
- End If
- End If
- End If
- HalBrain.DebugWatch GetResponse, "Hal State of Being"
- 'RESPOND: YES/NO QUESTION ABOUT HAL
- 'Hal will respond to a yes or no question posed by the user about Hal
- GetResponse = Trim(GetResponse)
- If Len(GetResponse) < 4 And InStr(1, UserSentence, " OR ", vbTextCompare) = 0 Then
- HalYesNo = HalBrain.PatternDB(UserSentence, "halQuestionDetect")
- If HalYesNo <> "" And HalBrain.TopicSearch(UserSentence, "disqualify5") = "" Then
- If RND * 10 < 5 Then
- AnsIntro = HalBrain.ChooseSentenceFromFile("answerIntro")
- Else
- AnsIntro = ""
- End If
- YesNoResponse = AnsIntro & HalBrain.ChooseSentenceFromFile("answerMiddle") & HalBrain.ChooseSentenceFromFile("answerEnd")
- GetResponse = GetResponse & Replace(YesNoResponse, "<Reply>", HalYesNo, 1, -1, vbTextCompare)
- End If
- End If
- HalBrain.DebugWatch GetResponse, "Yes/No Question"
- 'RESPOND: ATTRIBUTES OF HAL OR USER
- 'Hal attempts to respond to the user's comments about Hal
- 'or the user's comments about themselves
- GetResponse = Trim(GetResponse)
- If Len(GetResponse) < 4 And (InStr(UserSentence, " MY ") Or InStr(UserSentence, " YOUR ")) And HalBrain.TopicSearch(MyWords, "disqualify3") <> "True" Then
- If InStr(UserSentence, " YOUR ") Then
- MyWords = HalBrain.HalFormat(HalBrain.SearchPattern(UserSentence, "*YOUR *", 2))
- YourMode = True
- Else
- MyWords = HalBrain.HalFormat(HalBrain.SearchPattern(UserSentence, "*MY *", 2))
- YourMode = False
- End If
- MyWords = UCase(Trim(HalBrain.AlphaNumericalOnly(MyWords)))
- MyWordsList = Split(MyWords, " ")
- 'Go through every word in the sentence and pickup the first noun and adjective found
- For i = LBound(MyWordsList) To UBound(MyWordsList)
- If WN.LookupWord(MyWordsList(i)) Then
- PartOfSpeech = WN.GuessPartOfSpeech
- If WN.IsNoun = True And NounGuess = "" Then NounGuess = MyWordsList(i)
- If WN.IsAdj = True And Trim(UCase(MyWordsList(i))) <> Trim(UCase(NounGuess)) Then AdjGuess = MyWordsList(i)
- If PartOfSpeech = "NOUN" And MyNoun = "" Then MyNoun = MyWordsList(i)
- If PartOfSpeech = "ADJ" And WN.IsAdv = False And MyAdj = "" Then MyAdj = MyWordsList(i)
- If MyNoun <> "" And MyAdj <> "" Then Exit For
- End If
- Next
- If MyNoun = "" And NounGuess <> "" And NounGuess <> MyAdj Then MyNoun = NounGuess
- If MyAdj = "" And AdjGuess <> "" Then MyAdj = AdjGuess
- If MyNoun <> "" Or MyAdj <> "" Then
- If Trim(UCase(MyNoun)) = Trim(UCase(MyAdj)) Then MyAdj = ""
- If MyAdj = "" Then MyAdj = HalBrain.ChooseSentenceFromFile("randomAdjective")
- If MyNoun = "" Then MyNoun = HalBrain.ChooseSentenceFromFile("randomMyWords")
- If YourMode = False Then
- HalAttrib = HalBrain.ChooseSentenceFromFile("aboutMe")
- HalAttrib = Replace(HalAttrib, "<MyWordResp>", LCase(MyNoun), 1, -1, vbTextCompare)
- HalAttrib = Replace(HalAttrib, "<AdjResp>", LCase(MyAdj), 1, -1, vbTextCompare)
- Else
- HalAttrib = HalBrain.ChooseSentenceFromFile("aboutYou")
- HalAttrib = Replace(HalAttrib, "<YourWordResp>", LCase(MyNoun), 1, -1, vbTextCompare)
- HalAttrib = Replace(HalAttrib, "<AdjResp>", LCase(MyAdj), 1, -1, vbTextCompare)
- End If
- GetResponse = GetResponse & HalAttrib & vbCrLf
- End If
- End If
- HalBrain.DebugWatch GetResponse, "Attributes"
- 'RESPOND: RESPOND FOR A STATE OF BEING RESPONSE
- 'If no response had been found, but a state of being response was found earlier, then
- 'use it now
- If HalBeing <> "" And Len(GetResponse) < 4 Then GetResponse = GetResponse & HalBeing & vbCrLf
- If UserBeing <> "" And Len(GetResponse) < 4 Then GetResponse = GetResponse & UserBeing & vbCrLf
- HalBrain.DebugWatch GetResponse, "Retry State of Beings"
- 'RESPOND: GIBBERISH DETECTOR
- 'If no response is found yet and Hal finds more then 5 consonants in a row, Hal will
- 'assume the user wrote gibberish (ie. asdfghjkl) and respond accordinly.
- If Len(GetResponse) < 4 Then
- If DetectGibberish(UserSentence) = True Then
- GetResponse = HalBrain.ChooseSentenceFromFile("gibberish")
- ShortPhrase = ""
- End If
- End If
- HalBrain.DebugWatch GetResponse, "Gibberish"
- Rem PLUGIN: PLUGINAREA5
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- 'RESPOND: USER MENTIONING ORGANIZATIONAL CHALLENGES
- 'Everybody spouts TLA's, or 'Three Letter Acronyms,' in today's business world. Hal can self-generate
- 'several MILLION different phrases in response to the user mentioning a corporation or a firm.
- If Rnd * 10 < 5 And HalBrain.TopicSearch(UserSentence, "businessDetect1") = "True" And HalBrain.TopicSearch(PrevUserSent, "businessDetect2") <> "True" Then
- TLA = HalBrain.ChooseSentenceFromFile("TLA1") & " " & HalBrain.ChooseSentenceFromFile("TLA2") & " " & HalBrain.ChooseSentenceFromFile("TLA3")
- If Rnd * 10 < 5 Then
- GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("bizTalk")
- Else
- GetResponse = HalBrain.ChooseSentenceFromFile("bizTalk")
- End If
- GetResponse = Replace(GetResponse, "<TLA>", TLA, 1, -1, vbTextCompare)
- End If
- HalBrain.DebugWatch GetResponse, "Business Talk"
- 'RESPOND: USER EXPRESSES AN INTENTION
- 'This routine detects common expressions of motive from the user,
- 'and allows Hal to react to the statement, or offer encouragement.
- IntentPhrase = HalBrain.PatternDB(UserSentence, "intentDetector")
- If Len(IntentPhrase) > 2 And Len(IntentPhrase) < 60 And RND * 100 < 50 Then
- If Rnd * 10 < 6 Then IntroExclaim = " " & HalBrain.ChooseSentenceFromFile("introExclaim1") & " "
- If Rnd * 10 < 6 Then Encourager = " " & HalBrain.ChooseSentenceFromFile("encourager1") & " "
- If Rnd * 10 < 6 Then SuffixComment = " " & HalBrain.ChooseSentenceFromFile("suffixComment1") & " "
- If Rnd * 10 < 7 Then
- GetResponse = GetResponse & " " & HalBrain.ChooseSentenceFromFile("intentResponse")
- Else
- GetResponse = HalBrain.ChooseSentenceFromFile("intentResponse")
- End If
- GetResponse = Replace(GetResponse, "<IntroExclaim>", IntroExclaim, 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, "<Encourager>", Encourager, 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, "<IntentPhrase>", IntentPhrase, 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, "<SuffixComment>", SuffixComment, 1, -1, vbTextCompare)
- End If
- HalBrain.DebugWatch GetResponse, "Intention"
- 'RESPOND: USER EXPRESSES AN EXPLANATION
- 'This routine detects common expressions of reasons from the user,
- 'and allows Hal to react to the explanation.
- ExplainPhrase = HalBrain.PatternDB(UserSentence, "reasonDetector")
- If Len(ExplainPhrase) > 2 And Len(ExplainPhrase) < 60 Then
- If Rnd * 100 < 75 Then IntroExclaim = HalBrain.ChooseSentenceFromFile("introExclaim4")
- Enlightener = HalBrain.ChooseSentenceFromFile("enlightener")
- If Rnd * 100 < 66 Then SuffixComment = HalBrain.ChooseSentenceFromFile("suffixComment4")
- SpinWheel = HalBrain.RandomNum(6)
- If SpinWheel = 1 Then ExplainResponse = " " & " <UserName> " & IntroExclaim & Enlightener & ExplainPhrase & SuffixComment & " "
- If SpinWheel = 2 Then ExplainResponse = " " & IntroExclaim & " <UserName> " & Enlightener & ExplainPhrase & SuffixComment & " "
- If SpinWheel = 3 Then ExplainResponse = " " & IntroExclaim & Enlightener & ExplainPhrase & " <UserName> " & SuffixComment & " "
- If SpinWheel = 4 Then ExplainResponse = " " & IntroExclaim & Enlightener & ExplainPhrase & SuffixComment & " <UserName> " & " "
- If SpinWheel >= 5 Then ExplainResponse = " " & IntroExclaim & Enlightener & ExplainPhrase & SuffixComment & " "
- If Rnd * 10 < 5 Then GetResponse = ExplainResponse & " . " & GetResponse Else GetResponse = ExplainResponse
- End If
- HalBrain.DebugWatch GetResponse, "Explanation"
- 'RESPOND: YES OR NO RESPONSES
- 'Respond to simple yes and no statements by the user.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If Len(GetResponse) < 4 And Len(Trim(UserSentence)) < 16 Then CheckYesNo = True
- If CheckYesNo = True Then
- UserText = Trim(HalBrain.ExtractKeywords(UserSentence))
- If Len(UserText) < 15 Then
- YesNoDetect = HalBrain.TopicSearch(UserText, "yesNoDetect")
- If YesNoDetect = "Yes" Then
- GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("yesResponses") & "<LOWQUALITY>"
- ElseIf YesNoDetect = "No" Then
- GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("noResponses") & "<LOWQUALITY>"
- End If
- End If
- End If
- HalBrain.DebugWatch GetResponse, "Yes or No Response"
- 'PROCESS: SETUP RESPONSE ARRAY
- 'If no response is found yet, than we have many functions that are capable of producing a
- 'response, but no function is particulary better than another. So we will get a response
- 'from all the functions capable of producing one and put the responses into an array and
- 'randomly choose one.
- Dim ResponseList()
- Dim ResponseCount
- ResponseCount = 0
- TempParent = HalBrain.AddDebug("Debug", "Low Quality Response Routines")
- Rem PLUGIN: LOWQUALITYRESPONSES
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- 'RESPOND: USER ASKING WHO, WHAT, WHEN, WHERE, HOW, WHY, BUT HAL DOESN'T KNOW ANSWER
- If Len(GetResponse) < 4 Then
- If InStr(OriginalSentence, "?") > 0 Then QuesQual = True
- If InStr(1, OriginalSentence, "explain", vbTextCompare) > 0 Then QuesQual = True
- If InStr(1, OriginalSentence, " tell ", vbTextCompare) > 0 Then QuesQual = True
- If InStr(1, OriginalSentence, "answer", vbTextCompare) > 0 Then QuesQual = True
- If InStr(1, OriginalSentence, "question", vbTextCompare) > 0 Then QuesQual = True
- If InStr(1, OriginalSentence, " know ", vbTextCompare) > 0 Then QuesQual = True
- If InStr(1, OriginalSentence, "remember", vbTextCompare) > 0 Then QuesQual = True
- If InStr(UserSentence, " WHO ") > 0 Then QuesWord = "Who"
- If InStr(UserSentence, "WHO'") > 0 Then QuesWord = "Who"
- If InStr(UserSentence, " WHAT ") > 0 Then QuesWord = "What"
- If InStr(UserSentence, "WHAT'") > 0 Then QuesWord = "What"
- If InStr(UserSentence, " WHEN ") > 0 Then QuesWord = "When"
- If InStr(UserSentence, "WHEN'") > 0 Then QuesWord = "When"
- If InStr(UserSentence, " WHERE ") > 0 Then QuesWord = "Where"
- If InStr(UserSentence, "WHERE'") > 0 Then QuesWord = "Where"
- If InStr(UserSentence, " HOW ") > 0 Then QuesWord = "How"
- If InStr(UserSentence, "HOW'") > 0 Then QuesWord = "How"
- If InStr(UserSentence, " WHY ") > 0 Then QuesWord = "Why"
- If InStr(UserSentence, "WHY'") > 0 Then QuesWord = "Why"
- If Len(QuesWord) > 1 And QuesQual = True Then
- If Len(UserSentence) < 70 Then SentenceBack = UserSentence & " ? "
- DontKnow = HalBrain.ChooseSentenceFromFile("dontKnow")
- DontKnow = Replace(DontKnow, "<SentenceBack>", SentenceBack, 1, -1, vbTextCompare)
- DontKnow = Replace(DontKnow, "<QuesWord>", QuesWord, 1, -1, vbTextCompare)
- ResponseCount = ResponseCount + 1
- Redim Preserve ResponseList(ResponseCount)
- ResponseList(ResponseCount) = DontKnow
- HalBrain.AddDebug TempParent, "DontKnow: " & ResponseList(ResponseCount)
- SkipOpinion = True
- End If
- End If
- 'PROCESS: CONSTRUCT A RESPONSE TO A SUBJECT
- 'Here we help Hal make some "smalltalk" using keywords preserved on CurrentSubject,
- 'plus recognition of other keywords. If Hal finds any of the listed keywords anywhere in
- 'the user's sentence, those keywords override and replace whatever was in CurrentSubject.
- 'Hal uses the CurrentSubject keyword(s) or any of the keywords in the smalltalk.brn file,
- 'if found in the user's sentence, to make a little smalltalk. You can easily add more
- 'keywords for Hal to recognize and make smalltalk.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If Len(GetResponse) < 4 And Rnd * 100 < 50 Then
- SmalltalkSearch = Trim(HalBrain.TopicSearch(UserSentence, "smallTalk"))
- If SmalltalkSearch <> "" Then
- SmallTalk = SmalltalkSearch
- ElseIf Len(CurrentSubject) > 3 Then
- SmallTalk = Trim(CurrentSubject)
- 'try making word plural by adding "s" and seeing if it exists
- If WN.LookupWord(SmallTalk & "s") = True Then
- SmallTalk = SmallTalk & "s"
- ElseIf WN.LookupWord(SmallTalk & "es") = True Then
- SmallTalk = SmallTalk & "es"
- End If
- End If
- If Len(SmallTalk) > 3 Then
- ResponseCount = ResponseCount + 1
- Redim Preserve ResponseList(ResponseCount)
- ResponseList(ResponseCount) = Replace(HalBrain.ChooseSentenceFromFile("smallTalkSent"), "<SmallTalk>", SmallTalk, 1, -1, 1)
- HalBrain.AddDebug TempParent, "SmallTalk: " & ResponseList(ResponseCount)
- End If
- End If
- 'RESPOND: PARAPHRASE USER IF POSSIBLE
- 'If no response is found yet, and a paraphrase has been created but not used in a
- 'previous section, use it now.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If Len(GetResponse) < 4 And Len(Paraphrase) > 4 Then
- ResponseCount = ResponseCount + 1
- Redim Preserve ResponseList(ResponseCount)
- ResponseList(ResponseCount) = Paraphrase
- HalBrain.AddDebug TempParent, "Paraphrase: " & ResponseList(ResponseCount)
- End If
- 'RESPOND: PHRASE MAKER COMMENT AND QUESTION GENERATOR
- 'If no response is found yet, try an auxiliary keyword file that generates questions
- 'from phrases from the user's current sentence.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If Len(GetResponse) < 4 Then
- KeyBrain = HalBrain.PatternDB("X " & HalBrain.RemoveExtraSpaces(UserSentence), "phraseDetector")
- If Len(KeyBrain) > 1 And Len(KeyBrain) < 60 Then
- ResponseCount = ResponseCount + 1
- Redim Preserve ResponseList(ResponseCount)
- ResponseList(ResponseCount) = Replace(HalBrain.ChooseSentenceFromFile("phraseRepeater"), "<KeyBrain>", KeyBrain, 1, -1, vbTextCompare)
- HalBrain.AddDebug TempParent, "PhraseRepeater: " & ResponseList(ResponseCount)
- End If
- End If
- 'RESPOND: Use the highest relevance response from the database functions
- GetResponse = HalBrain.HalFormat(GetResponse)
- If (Len(GetResponse) < 4 And (HighestRel > 6 And HighestRelResponse <> "")) Then
- ResponseCount = ResponseCount + 2
- Redim Preserve ResponseList(ResponseCount)
- ResponseList(ResponseCount - 1) = HighestRelResponse
- ResponseList(ResponseCount) = HighestRelResponse
- HalBrain.AddDebug TempParent, "Highest Rel: " & ResponseList(ResponseCount)
- End If
- 'RESPOND: WORDNET MERONYM AND HYPERNYM RESPONSES
- 'This function finds the first definite noun in a sentence and comes up with responses
- 'based on the word's meronyms (parts of), hypernyms (is part of), and sisters (similar things).
- If (Len(GetResponse) < 4 And Rnd * 100 < 65) And Len(UserSentence) > 15 Then
- subject = WN.FindFirstNoun(UserSentence, True)
- If subject <> "" And WN.LookupWord(subject) = True Then
- If Rnd * 100 < 55 Then 'If we have a meronym, lets use it creatively in a random sentence
- Meronym = WN.ChooseRandomWord(WN.GetMeronyms(1)) 'Meronym means "has parts" or "has members"
- If Meronym <> "" Then
- WNResponse = HalBrain.ChooseSentenceFromFile("meronyms")
- WNResponse = Replace(WNResponse, "<BaseNoun>", WN.GetBase("NOUN"), 1, -1, vbTextCompare)
- WNResponse = Replace(WNResponse, "<Meronym>", Meronym, 1, -1, vbTextCompare)
- If Len(GetResponse) < 4 And Len(WNResponse) > 4 Then
- ResponseCount = ResponseCount + 1
- Redim Preserve ResponseList(ResponseCount)
- ResponseList(ResponseCount) = WNResponse & vbCrLf
- HalBrain.AddDebug TempParent, "Meronym: " & ResponseList(ResponseCount)
- End If
- End If
- Else
- Hypernym = WN.ChooseRandomWord(WN.GetHypernyms("NOUN", 1, 1)) 'Hypernym means "is a part of" or "is a member of"
- Sister = WN.ChooseRandomWord(WN.GetSisters("NOUN", 1)) 'Related nouns
- If Sister <> "" And Hypernym <> "" Then 'If we have sister terms and hypernyms, lets use it creatively
- WNResponse = HalBrain.ChooseSentenceFromFile("hypernyms")
- WNResponse = Replace(WNResponse, "<BaseNoun>", WN.GetBase("NOUN"), 1, -1, vbTextCompare)
- WNResponse = Replace(WNResponse, "<Hypernym>", Hypernym, 1, -1, vbTextCompare)
- WNResponse = Replace(WNResponse, "<Sister>", Sister, 1, -1, vbTextCompare)
- If Len(GetResponse) < 4 And Len(WNResponse) > 4 Then
- ResponseCount = ResponseCount + 1
- Redim Preserve ResponseList(ResponseCount)
- ResponseList(ResponseCount) = WNResponse & vbCrLf
- HalBrain.AddDebug TempParent, "Hypernym: " & ResponseList(ResponseCount)
- End If
- End If
- End If
- End If
- End If
- 'RESPOND: STRIKING SIMILES
- 'If the user mentions a noun that is in a table of nouns with similes, Hal will
- 'say the simile phrase
- GetResponse = HalBrain.HalFormat(GetResponse)
- If (Len(GetResponse) < 4 And Len(LearnKeyword) < 4) Then
- Dim SimList() 'We must declare an empty array to store query results in
- If HalBrain.RunQuery("SELECT searchString, topic FROM strikingSimiles WHERE strstr(' " & Replace(HalBrain.AlphaNumericalOnly(OriginalSentence), "'", "''") & " ', searchString) > 0", SimList) = True Then
- SpinWheel = HalBrain.RandomNum(Ubound(SimList)) 'Pick a random result if there is more than 1
- Simile = Trim(SimList(SpinWheel, 1)) 'Column 1 contains "topic", which is the simile
- If Len(Simile) > 5 Then
- ResponseCount = ResponseCount + 1
- Redim Preserve ResponseList(ResponseCount)
- ResponseList(ResponseCount) = Simile & ". "
- HalBrain.AddDebug TempParent, "Striking Simile: " & ResponseList(ResponseCount)
- End If
- End If
- End If
- 'RESPOND: MISC PHRASES
- 'If the user mentions a noun that is in a table of nouns as part of misc sentence
- 'fragments, Hal will say the fragment followed by an ellipsis
- GetResponse = HalBrain.HalFormat(GetResponse)
- If (Len(GetResponse) < 4 And Len(LearnKeyword) < 4) Then
- Dim PhraseList() 'We must declare an empty array to store query results in
- If HalBrain.RunQuery("SELECT searchString, topic FROM miscPhrases WHERE strstr(' " & Replace(HalBrain.AlphaNumericalOnly(OriginalSentence), "'", "''") & " ', searchString) > 0", PhraseList) = True Then
- SpinWheel = HalBrain.RandomNum(Ubound(PhraseList)) 'Pick a random result if there is more than 1
- MiscPhrase = Trim(PhraseList(SpinWheel, 1)) 'Column 1 contains "topic", which is the phrase
- If Len(MiscPhrase) > 5 Then
- ResponseCount = ResponseCount + 1
- Redim Preserve ResponseList(ResponseCount)
- ResponseList(ResponseCount) = MiscPhrase & "<ellipsis>"
- HalBrain.AddDebug TempParent, "MiscPhrase: " & ResponseList(ResponseCount)
- End If
- End If
- End If
- 'RESPOND: ADJECTIVE NOUN QUESTION
- 'If the user mentions a noun that is in a table of nouns, Hal will
- 'try describing the noun with an adjective in the form of a question.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If (Len(GetResponse) < 4 And Len(LearnKeyword) < 4) Then
- Dim ANList() 'We must declare an empty array to store query results in
- If HalBrain.RunQuery("SELECT searchString, topic FROM AdjNoun WHERE strstr(' " & Replace(HalBrain.AlphaNumericalOnly(OriginalSentence), "'", "''") & " ', searchString) > 0", ANList) = True Then
- MentionedNoun = Trim(ANList(1, 0)) 'Row 1 contains our query result. Column 0 contains "searchString", which is the noun
- SpinWheel = HalBrain.RandomNum(Ubound(ANList)) 'Pick a random result if there is more than 1
- AssocAdj = Trim(ANList(SpinWheel, 1)) 'Column 1 contains "topic", which is the adjective
- If Len(MentionedNoun) < 5 Then MentionedNoun = " " & MentionedNoun & " "
- If Instr(1, " " & UserSentence & " ", MentionedNoun, vbTextCompare) > 0 And Instr(1, UserSentence, AssocAdj, vbTextCompare) = 0 Then
- ResponseCount = ResponseCount + 1
- Redim Preserve ResponseList(ResponseCount)
- SpinWheel = HalBrain.RandomNum(5)
- If SpinWheel = 1 Then ResponseList(ResponseCount) = "<UserName>, " & AssocAdj & " " & MentionedNoun & "?"
- If SpinWheel = 2 Then ResponseList(ResponseCount) = AssocAdj & " " & MentionedNoun & ", <UserName>?"
- If SpinWheel > 2 Then ResponseList(ResponseCount) = AssocAdj & " " & MentionedNoun & "?"
- HalBrain.AddDebug TempParent, "Adj/Noun Question: " & ResponseList(ResponseCount)
- End If
- End If
- End If
- 'RESPOND: VERB PREPOSITION NOUN QUESTION
- 'If the user mentions a noun that is in a table of nouns, Hal will
- 'ask a question about the noun using a related verb and preposition
- GetResponse = HalBrain.HalFormat(GetResponse)
- If (Len(GetResponse) < 4 And Len(LearnKeyword) < 4) Then
- Dim VPNList() 'We must declare an empty array to store query results in
- If HalBrain.RunQuery("SELECT searchString, topic FROM VerbPrepNoun WHERE strstr(' " & Replace(HalBrain.AlphaNumericalOnly(OriginalSentence), "'", "''") & " ', searchString) > 0", VPNList) = True Then
- MentionedNoun = Trim(VPNList(1, 0)) 'Row 1 contains our query result. Column 0 contains "searchString", which is the noun
- SpinWheel = HalBrain.RandomNum(Ubound(VPNList)) 'Pick a random result if there is more than 1
- AssocVerbPrep = Trim(VPNList(SpinWheel, 1)) 'Column 1 contains "topic", which is the verb and preposition
- If Len(MentionedNoun) < 5 Then MentionedNoun = " " & MentionedNoun & " "
- If Instr(1, " " & UserSentence & " ", MentionedNoun, vbTextCompare) > 0 And Instr(1, UserSentence, AssocVerbPrep, vbTextCompare) = 0 Then
- ResponseCount = ResponseCount + 1
- Redim Preserve ResponseList(ResponseCount)
- SpinWheel = HalBrain.RandomNum(5)
- If SpinWheel = 1 Then ResponseList(ResponseCount) = "<UserName>, " & AssocVerbPrep & " " & MentionedNoun & "?"
- If SpinWheel = 2 Then ResponseList(ResponseCount) = AssocVerbPrep & " " & MentionedNoun & ", <UserName>?"
- If SpinWheel > 2 Then ResponseList(ResponseCount) = AssocVerbPrep & " " & MentionedNoun & "?"
- HalBrain.AddDebug TempParent, "Verb/Preposition/Noun Question: " & ResponseList(ResponseCount)
- End If
- End If
- End If
- 'RESPOND: USE CURRENT SENTENCE
- 'If no Response is found yet, try to use the user's words in his or her own sentence.
- 'Results are also stored in the default user keyword brain file for compatibility
- 'with other brain plug-ins.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If (Len(GetResponse) < 4 And Len(LearnKeyword) < 4) Then
- CheatResp = HalBrain.CheatResponse(HalBrain.SwitchPerson(HalBrain.AlphaNumericalOnly((OriginalSentence))))
- CheatResp = Left(CheatResp, InStr(1, CheatResp, "<STOREVARS>", 1) - 1)
- If Len(CheatResp) > 4 Then
- ResponseCount = ResponseCount + 1
- Redim Preserve ResponseList(ResponseCount)
- SpinWheel = HalBrain.RandomNum(9)
- If SpinWheel = 1 Then ResponseList(ResponseCount) = " So, " & CheatResp & vbCrLf
- If SpinWheel = 2 Then ResponseList(ResponseCount) = " Really, " & CheatResp & vbCrLf
- If SpinWheel = 3 Then ResponseList(ResponseCount) = " Oh <UserName>, " & CheatResp & vbCrLf
- If SpinWheel = 4 Then ResponseList(ResponseCount) = " Let me think; " & CheatResp & " ; what do you think <UserName>? " & vbCrLf
- If SpinWheel > 5 Then ResponseList(ResponseCount) = CheatResp & vbCrLf
- HalBrain.AddDebug TempParent, "Cheat Response: " & ResponseList(ResponseCount)
- End If
- End If
- 'RESPOND: PICK OUT OF AVAILABLE LOW QUALITY RESPONSES
- 'If no response is found yet, than we have many functions from above that may have produced
- 'a response, but no function is particulary better than another. So we will now pick a
- 'responses from an array randomly choosen.
- GetResponse = HalBrain.HalFormat(GetResponse)
- If (Len(GetResponse) < 4 And ResponseCount > 0) Then
- SpinWheel = HalBrain.RandomNum(ResponseCount)
- GetResponse = ResponseList(SpinWheel) & "<LOWQUALITY>"
- End If
- HalBrain.DebugWatch GetResponse, "Randomly pick a low-quality response"
- 'RESPOND: User asks a general opinion question.
- If HalBrain.TopicSearch(UserSentence, "opinionDetect") = "True" Then GenOpinion = True
- 'Note that the following string matches must occur at the sentence beginning only:
- If Rnd * 100 > 50 Then
- If Left(Trim(UCase(OriginalSentence)), 4) = "WHY " Then GenOpinion = True
- If Left(Trim(UCase(OriginalSentence)), 5) = "WHAT " Then GenOpinion = True
- If Left(Trim(UCase(OriginalSentence)), 5) = "WHEN " Then GenOpinion = True
- If Left(Trim(UCase(OriginalSentence)), 4) = "HOW " Then GenOpinion = True
- If Left(Trim(UCase(OriginalSentence)), 4) = "WHO " Then GenOpinion = True
- If Left(Trim(UCase(OriginalSentence)), 6) = "WHERE " Then GenOpinion = True
- End If
- If GenOpinion = True And SkipOpinion = False Then
- If Rnd * 100 > 45 Then RepeatQuest = UserSentence & " ? "
- If Rnd * 100 > 50 Then PreAmble = HalBrain.ChooseSentenceFromFile("preamble")
- Recommend = HalBrain.ChooseSentenceFromFile("recommend")
- GetResponse = RepeatQuest & " " & PreAmble & " " & Recommend & GetResponse
- End If
- HalBrain.DebugWatch GetResponse, "General Opinion"
- 'RESPOND: CHANGE TOPIC
- 'If a different procedure has requested that the topic be changed
- 'Hal will do so now
- GetResponse = Replace(GetResponse, "<ChangeSubject>", newTopic, 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, "<ChangeTopic>", newTopic, 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, "<NewTopic>", newTopic, 1, -1, vbTextCompare)
- HalBrain.DebugWatch GetResponse, "Change Topic"
- Rem PLUGIN: PLUGINAREA6
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- 'RESPOND: MAKE UP SOMETHING TO SAY
- 'If we have got to this point and we still don't have anything to say, then
- 'we will use 1 of 5 functions to make something up to say.
- GetResponse = Trim(GetResponse)
- If Len(GetResponse) < 4 Then
- SpinWheel = HalBrain.RandomNum(6)
- If SpinWheel < 4 Then
- 'RESPOND: CONVERSATIONAL PHRASE
- 'Choose a random phrase designed to keep the conversation going no matter what the user said
- GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("conversationalPhrases")
- ElseIf SpinWheel = 4 Then
- 'RESPOND: CHANGE TOPIC
- If Rnd * 10 < 4 Then GetResponse = HalBrain.ChooseSentenceFromFile("topicIntro")
- GetResponse = GetResponse & newTopic
- Else
- 'RESPOND: USE RANDOM QUESTION COLLECTED FROM USER
- 'Randomly select a question once posed by the user in order to find something to say.
- 'If the user answers the question, then Hal will know that answer in the future.
- If Rnd * 10 < 3 Then GetResponse = HalBrain.ChooseSentenceFromFile("topicIntro")
- GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("sharedQuestions")
- End If
- GetResponse = GetResponse & "<LOWQUALITY>"
- End If
- HalBrain.DebugWatch GetResponse, "Make up something"
- 'PROCESS: RECORD TIME
- 'Record the current time, so Hal knows the time in between sentences.
- LastResponseTime = Now
- 'PROCESS: FIGURE OUT CONTINUITY
- 'If the user seems to be continuing a line of thought
- 'from something Hal just said, note this.
- If Len(Trim(PrevSent)) > 2 And (HalBrain.TopicSearch(UserSentence, "responding") = "True" Or InStr(OriginalSentence, "!") Or InStr(PrevSent, "?")) Then TopicContinuity = True
- 'PROCESS: FIGURE OUT PERSONAL DATA
- If InStr(UserSentence, "WHAT IS") = 0 And InStr(UserSentence, " YOU ") = 0 And InStr(UserSentence, " YOU'") = 0 And InStr(UserSentence, " YOUR") = 0 And InStr(UserSentence, " WE ") = 0 And InStr(UserSentence, " US ") = 0 And InStr(UserSentence, " OUR ") = 0 And InStr(UserSentence, " I ") = 0 And InStr(UserSentence, " ME ") = 0 And InStr(UserSentence, " MY ") = 0 And InStr(UserSentence, " MINE ") = 0 And InStr(UserSentence, " MYSELF ") = 0 And InStr(UserSentence, " I'") = 0 Then
- PersonalData = False
- Else
- PersonalData = True
- End If
- 'PROCESS: RESTORE PUNTUATION FOR LEARNING
- 'Now we establish a special sentence on which we can restore ordinary capitalization:
- AnswerSent = UserSentence
- AnswerSent = Trim(HalBrain.FixCaps(AnswerSent))
- If Right(AnswerSent, 1) = "." Then AnswerSent = Left(AnswerSent, Len(AnswerSent) - 1)
- 'Now we add in our spaces and restore ending punctuation to match the user's original sentence:
- If InStr(OriginalSentence, "!") > 0 And InStr(AnswerSent, "!") = 0 Then
- AnswerSent = AnswerSent & "!"
- ElseIf InStr(OriginalSentence, "?") > 0 And InStr(AnswerSent, "?") = 0 Then
- AnswerSent = AnswerSent & "?"
- Else
- AnswerSent = AnswerSent & "."
- End If
- 'If there were no pronoun reversals required in the sentence,
- 'we can recover directly from the original sentence:
- If InStr(UserSentence, " ME") = 0 And InStr(UserSentence, "YOU") = 0 And InStr(UserSentence, "MY ") = 0 And InStr(UserSentence, "YOUR ") = 0 And InStr(UserSentence, "I ") = 0 And InStr(UserSentence, "MINE") = 0 And InStr(UserSentence, "YOURS") = 0 And InStr(UserSentence, "MYSELF") = 0 And InStr(UserSentence, "YOURSELF") = 0 Then AnswerSent = Trim(OriginalSentence)
- 'PROCESS: NOTE IF QUESTION
- 'See if the user's sentence is a question or not and note this
- 'for use by other functions
- If InStr(1, OriginalSentence, "?", vbTextCompare) > 0 Then IsQuestion = True
- If InStr(1, OriginalSentence, "Who ", vbTextCompare) > 0 Then IsQuestion = True
- If InStr(1, OriginalSentence, "What ", vbTextCompare) > 0 Then IsQuestion = True
- If InStr(1, OriginalSentence, "When ", vbTextCompare) > 0 Then IsQuestion = True
- If InStr(1, OriginalSentence, "Where ", vbTextCompare) > 0 Then IsQuestion = True
- If InStr(1, OriginalSentence, "Why ", vbTextCompare) > 0 Then IsQuestion = True
- If InStr(1, OriginalSentence, "How ", vbTextCompare) > 0 Then IsQuestion = True
- If InStr(1, OriginalSentence, ".", vbTextCompare) > 0 Then IsQuestion = False
- If InStr(1, OriginalSentence, "!", vbTextCompare) > 0 Then IsQuestion = False
- If InStr(1, OriginalSentence, " am I ", vbTextCompare) > 0 Then IsQuestion = False
- 'SAVE: EPHEMERAL KNOWLEDGE
- 'Some Hal's learned knowledge should be temporary because it is ephemeral in nature.
- 'Knowledge about weather, season, temperature, etc. are temporary knowledge
- 'that shouldn't be stored in Hal's permanent brain files. Ephemeral knowledge is
- 'detected and saved in a temporary table. The temporary table only stores 10
- 'entries in it at a time.
- If HalBrain.TopicSearch(UserSentence, "ephemeralDetect") = "True" Then
- If HalBrain.CheckTableExistence(Trim(LCase(UserName)) & "_TempSent") = False Then
- 'Create table for this user if it doesn't exist
- HalBrain.CreateTable Trim(LCase(UserName)) & "_TempSent", "Brain", "autoLearningBrain"
- End If
- If TopicContinuity = True Then HalBrain.AddToTable Trim(LCase(UserName)) & "_TempSent", "Brain", Trim(HalBrain.AlphaNumericalOnly(PrevSent)), AnswerSent
- HalBrain.AddToTable Trim(LCase(UserName)) & "_TempSent", "Brain", Trim(UserSentence), AnswerSent
- HalBrain.LimitSize Trim(LCase(UserName)) & "_TempSent", 10
- HalBrain.ReadOnlyMode = True 'Block additional file saves when ephemeral knowledge is detected
- End If
- 'SAVE: LEARN AUTO TOPIC FOCUS PEOPLE SENTENCES
- 'Learns info about people with recognized names
- If HalBrain.ReadOnlyMode = False And HalGreeting = "" And IsQuestion = False And MentionedName <> "" And Trim(UCase(NewName)) <> Trim(UCase(MentionedName)) And WN.LookupWord(MentionedName) = False Then
- If HalBrain.CheckTableExistence("_" & Trim(LCase(MentionedName))) = False Then
- 'Create table for this person if it doesn't exist
- HalBrain.CreateTable "_" & Trim(LCase(MentionedName)), "Brain", "autoLearningBrain"
- HalBrain.AddToTable "topicRelationships", "TopicSearch", Trim(MentionedName), Trim(LCase(MentionedName))
- End If
- 'Store user response in this table
- If TopicContinuity = True Then HalBrain.AddToTable "_" & Trim(LCase(MentionedName)), "Brain", Trim(HalBrain.AlphaNumericalOnly(PrevSent)), AnswerSent
- HalBrain.AddToTable "_" & Trim(LCase(MentionedName)), "Brain", Trim(UserSentence), AnswerSent
- End If
- 'SAVE: AUTO TOPIC FOCUS LEARNING
- If HalBrain.ReadOnlyMode = False And HalGreeting = "" And PersonalData = False And HalBrain.CountInstances(" ", Trim(UserSentence)) > 2 And IsQuestion = False Then
- Keywords = HalBrain.TopicSearch(UserSentence, "topicRelationships") & " " & CurrentSubject & " " & UserSentence
- Keywords = Trim(HalBrain.RemoveExtraSpaces(HalBrain.ExtractKeywords(" " & Keywords & " ")))
- If Len(Keywords) > 3 Then
- KeywordList = Split(Keywords, " ")
- TopicList = ""
- 'Create list of tables that exist for each keyword
- For i = LBound(KeywordList) To UBound(KeywordList)
- TopicTable = HalBrain.TopicSearch(" " & KeywordList(i) & " ", "topicRelationships")
- If TopicTable <> "" And InStr(1, " " & TopicList, " " & Trim(TopicTable) & " ", vbTextCompare) = 0 Then
- 'Topic already exists, make note of it
- TopicList = TopicList & TopicTable & " "
- ElseIf TopicTable = "" And Len(KeywordList(i)) > 2 Then
- If Asc(Left(KeywordList(i),1)) > 47 And Asc(Left(KeywordList(i),1)) < 58 Or HalBrain.Word2Num(KeywordList(i)) <> "X" Then IsNumber = True Else IsNumber = False
- If WN.LookupWord(KeywordList(i)) = True And WN.GuessPartOfSpeech() = "NOUN" And IsNumber = False Then
- If HalBrain.CheckTableExistence("_" & Trim(Lcase(WN.GetBase(WN.GuessPartOfSpeech)))) = False Then
- 'Topic does not exist, but can and will be created
- TopicList = TopicList & KeywordList(i) & " "
- HalBrain.CreateTable "_" & Trim(Lcase(KeywordList(i))), "Brain", "autoLearningBrain"
- HalBrain.AddToTable "topicRelationships", "TopicSearch", " " & Trim(KeywordList(i)) & " ", Trim(Lcase(KeywordList(i)))
- 'Relationships based on wordnet synonyms are recorded
- Relationships = WN.GetDefinition("NOUN", 1, "S") & "," & WN.GetSynonyms("NOUN", 1)
- Relationships = Replace(Relationships, ", ", ",")
- Relationships = Trim(Replace(Relationships, ",,", ","))
- If Right(Relationships, 1) = "," Then Relationships = Trim(Left(Relationships, Len(Relationships) - 1))
- If Len(Relationships) > 1 Then
- If Left(Relationships, 1) = "," Then Relationships = Right(Relationships, Len(Relationships) - 1)
- RelList = Split(Relationships, ",")
- For h = Lbound(RelList) To Ubound(RelList)
- If HalBrain.TopicSearch(" " & RelList(h) & " ", "topicRelationships") = "" Then
- HalBrain.AddToTable "topicRelationships", "TopicSearch", " " & Trim(RelList(h)) & " ", Trim(Lcase(KeywordList(i)))
- End If
- Next
- End If
- End If
- End If
- End If
- Next
- 'User's sentence is recorded in all related topic tables
- TopicList = HalBrain.RemoveExtraSpaces(TopicList)
- If TopicList <> "" And Len(AnswerSent) > 3 Then
- AlreadyLearned = True
- TableList = Split(TopicList, " ")
- For i = LBound(TableList) To UBound(TableList)
- If TopicContinuity = True And Len(PrevSent) > 3 Then HalBrain.AddToTable "_" & Trim(Lcase(TableList(i))), "Brain", Trim(HalBrain.AlphaNumericalOnly(PrevSent)), AnswerSent
- If Len(UserSentence) > 3 Then HalBrain.AddToTable "_" & Trim(Lcase(TableList(i))), "Brain", Trim(UserSentence), AnswerSent
- Next
- End If
- End If
- End If
- If HalBrain.ReadOnlyMode = False And AlreadyLearned = False And HalBrain.CountInstances(" ", Trim(UserSentence)) > 2 And HalGreeting = "" Then
- If PersonalData = True And IsQuestion = False Then
- 'SAVE: FILE USER SENTENCE DEFAULT
- 'Hal adds to the default brain user sentence file an association of the current
- 'user sentence With words selected from that same current user sentence.
- If InStr(UserSentence, "WHAT IS") = 0 Then
- If HalBrain.CheckTableExistence(Trim(LCase(UserName)) & "_UserSent") = False Then
- 'Create table for this user if it doesn't exist
- HalBrain.CreateTable Trim(LCase(UserName)) & "_UserSent", "Brain", "autoLearningBrain"
- End If
- If TopicContinuity = True Then HalBrain.AddToTable Trim(LCase(UserName)) & "_UserSent", "Brain", Trim(HalBrain.AlphaNumericalOnly(PrevSent)), AnswerSent
- HalBrain.AddToTable Trim(LCase(UserName)) & "_UserSent", "Brain", Trim(UserSentence), AnswerSent
- End If
- ElseIf IsQuestion = False Then
- 'SAVE: FILE SHARED USER SENTENCES
- 'Unless the user seems to be asking for data recall, or talking about
- 'himself or herself, Hal adds to a shared user sentence file. This allows
- 'Hal to gain knowledge that he can apply to conversations with multiple users.
- If TopicContinuity = True Then HalBrain.AddToTable "sharedUserSent", "Brain", Trim(HalBrain.AlphaNumericalOnly(PrevSent)), AnswerSent
- HalBrain.AddToTable "sharedUserSent", "Brain", Trim(UserSentence), AnswerSent
- End If
- 'SAVE: FILE QUESTIONS IN RANDOM QUESTION RETRIEVAL FILE
- 'Hal saves the user's questions (with pronouns reversed)
- 'so that he can pose questions back to the user later for 3 purposes:
- '1. If the user answers a question later, Hal will learn the answer.
- '2. It adds variety to future conversations for the user.
- '3. It gives Hal another possible response when "stuck" for an answer.
- If IsQuestion = True Then HalBrain.AddToTable "sharedQuestions", "Sentence", AnswerSent, ""
- End If
- Rem PLUGIN: PLUGINAREA7
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- 'POST PROCESS: LIMIT TABLE SIZE
- 'We want to make sure the sentence files
- 'don't get too big so we limit them.
- 'RESPOND: HAL NOTICES HE IS REPEATING HIMSELF
- 'Hal may make a comment or alter his remark
- 'if he detects himself being repetitious.
- If HalBrain.CheckRepetition(GetResponse, PrevSent) = True Then
- RepeatResponse = HalBrain.ChooseSentenceFromFile("halRepeat")
- GetResponse = Replace(RepeatResponse, "<response>", GetResponse, 1, -1, vbTextCompare)
- DebugInfo = DebugInfo & "Hal has noticed he is repeating himself and has made a comment about it: " & GetResponse & vbCrLf
- End If
- 'RESPOND: MAKE COMMENTS ABOUT SHORT PHRASES
- GetResponse = GetResponse & ShortPhrase
- '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, "corrections")
- 'PROCESS: CALL USER BY CORRECT NAME
- 'If the user has chosen a nickname or temporary name, call user by that
- 'otherwise call the user by the username chosen by the host application
- If NewName <> "" Then
- GetResponse = Replace(GetResponse, "<UserName>", NewName, 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, "<Name>", NewName, 1, -1, vbTextCompare)
- Else
- GetResponse = Replace(GetResponse, "<UserName>", UserName, 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, "<Name>", UserName, 1, -1, vbTextCompare)
- End If
- 'PROCESS: AGE AND GENDER TAGS
- GetResponse = Replace(GetResponse, "<HalAge>", HalAge, 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, "<HalSex>", HalSex, 1, -1, vbTextCompare)
- 'PROCESS: NAME REVERSAL
- 'If Hal is about to same something referring to himself in third person
- 'then we will reverse it to be about the user.
- 'Don't let Hal say the word "HAL" unless he is telling his name
- If InStr(1, GetResponse, "i'm", vbTextCompare) = 0 And InStr(1, GetResponse, "i am", vbTextCompare) = 0 And InStr(1, GetResponse, "name", vbTextCompare) = 0 And InStr(1, GetResponse, "this is", vbTextCompare) = 0 Then
- GetResponse = " " & GetResponse & " "
- GetResponse = Replace(GetResponse, "Ultra Hal Assistant", " " & NewName & " ", 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, "Ultra Hal", " " & NewName & " ", 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, "Hal Assistant", " " & NewName & " ", 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, " Hal ", " " & NewName & " ", 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, " Hal,", " " & NewName & ",", 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, " Hal.", " " & NewName & ".", 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, " " & ComputerName & " ", " " & NewName & " ", 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, " " & ComputerName & ",", " " & NewName & ",", 1, -1, vbTextCompare)
- GetResponse = Replace(GetResponse, " " & ComputerName & ".", " " & NewName & ".", 1, -1, vbTextCompare)
- End If
- 'PROCESS: PRESERVE ALL VARIABLES
- PrevUserSent = UserSentence
- CustomMem = HalBrain.EncodeVar(NewName, "NewName") & HalBrain.EncodeVar(UserSex, "UserSex") & HalBrain.EncodeVar(SentCount, "SentCount") & HalBrain.EncodeVar(ShortSents, "ShortSents")
- Rem PLUGIN: CUSTOMMEM2
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- End Function
- 'This function scans a sentence looking to see if a user entered gibberish like
- 'sdfkjhskjdfhskdsdfdf. It works by looking for more than 5 consanants in a row,
- 'which doesn't occur in normal english words.
- Function DetectGibberish(GibSentence)
- DetectGibberish = False
- GibCount = 0
- For i = 1 To Len(GibSentence) 'loop for every character in the sentence
- CurrentLetter = Ucase(Mid(GibSentence, i, 1))
- GibCount = GibCount + 1
- If CurrentLetter = "0" Then GibCount = 0
- If CurrentLetter = "1" Then GibCount = 0
- If CurrentLetter = "2" Then GibCount = 0
- If CurrentLetter = "3" Then GibCount = 0
- If CurrentLetter = "4" Then GibCount = 0
- If CurrentLetter = "5" Then GibCount = 0
- If CurrentLetter = "6" Then GibCount = 0
- If CurrentLetter = "7" Then GibCount = 0
- If CurrentLetter = "8" Then GibCount = 0
- If CurrentLetter = "9" Then GibCount = 0
- If CurrentLetter = "A" Then GibCount = 0
- If CurrentLetter = "E" Then GibCount = 0
- If CurrentLetter = "I" Then GibCount = 0
- If CurrentLetter = "O" Then GibCount = 0
- If CurrentLetter = "U" Then GibCount = 0
- If CurrentLetter = "Y" Then GibCount = 0
- If CurrentLetter = " " Then GibCount = 0
- If GibCount = 6 Then
- DetectGibberish = True
- Exit For
- End If
- Next
- 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()
- HalBrain.MsgAlert "This is the Ultra Hal 6.2 Default 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. If a return
- 'value is given it is passed as a Hal Command to the host Hal program.
- Function Script_Load()
- Rem PLUGIN: SCRIPT_LOAD
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- End Function
- '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()
- Rem PLUGIN: SCRIPT_UNLOAD
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- End Sub
- 'If the host application is Ultra Hal Assistant, then this sub will be
- 'run once a minute enabling plug-ins to do tasks such as checking for
- 'new emails or checking an appointment calendar.
- Sub Minute_Timer(MinutesPast)
- Rem PLUGIN: MINUTE_TIMER
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
- End Sub
- Rem PLUGIN: FUNCTIONS
- 'The preceding comment is actually a plug-in directive for
- 'the Ultra Hal host application. It allows for code snippets
- 'to be inserted here on-the-fly based on user configuration.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement