Advertisement
Guest User

Candy Brain super bot

a guest
Aug 9th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 212.50 KB | None | 0 0
  1. Rem Type=Brain
  2. Rem Name=Ultra Hal 7.0 Super Bot
  3. Rem Author=Edge
  4. Rem Language=VBScript
  5. Rem DB=HalBrain.db
  6.  
  7. 'The UltraHal function is called by Ultra Hal Assistant 7.x or a compatible host application
  8. 'It passes an unformated string of the user's input as well as all remembered variables.
  9. 'The UltraHal function splits the user's input into seperate sentences and than calls
  10. 'GetResponse to get a response for each user sentence. The UltraHal function performs all
  11. 'the initialization functions required for GetResponse so that GetResponse doesn't have to
  12. 'initialize several times if a user inputs more than 1 sentence.
  13. 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)
  14.  
  15. 'PET NAMES CAN BE USED HERE.
  16.     Select Case HalBrain.RandomNum(3)
  17.             Case 1
  18.                 UserPetName = "love" & vbCrLf
  19.             Case 2
  20.                 UserPetName = "honey" & vbCrLf
  21.             Case 3
  22.                 UserPetName = "sweety" & vbCrLf
  23.         End Select
  24.    
  25.    UserName = UserPetName
  26.    'HAL PET NAMES
  27.   Select Case HalBrain.RandomNum(1)
  28.             Case 1
  29.                 HalPetName = "candy" & vbCrLf
  30.             'Case 2
  31.                'HalPetName = "honey" & vbCrLf
  32.            'Case 3
  33.                'HalPetName = "love" & vbCrLf
  34.            'Case 4
  35.                'HalPetName = "sweety" & vbCrLf
  36.        End Select
  37.    
  38.    ComputerName = HalPetName
  39. 'IRC RETURN FILTER:!
  40. InputString = Replace(InputString, ":!", "", 1, -1, vbTextCompare)
  41. InputString = Replace(InputString, "  ", " ", 1, -1, vbTextCompare)  
  42. InputString = Trim(InputString)
  43. InputString = "" & InputString & ""
  44.  
  45.     'PROCESS: TRIM LEADING PUNCTUATION
  46.    InputString = Trim(InputString)
  47.     Do While Len(InputString) > 1
  48.         If Left(InputString, 1) = "." or Left(InputString, 1) = "?" or Left(InputString, 1) = "!" Then
  49.             InputString = Right(InputString, Len(InputString) - 1)
  50.         Else
  51.             Exit Do
  52.         End If
  53.         InputString = Trim(InputString)
  54.     Loop
  55.        
  56.     'RESPOND: User pressed enter, but didn't say anything
  57.         InputString = Trim(InputString)
  58.         CheckStringQuality = Trim(Ucase(HalBrain.AlphaNumericalOnly(InputString)))
  59.         CheckStringQuality = Replace(CheckStringQuality, "'", "", 1, -1, vbTextCompare)
  60.         If CheckStringQuality = "" Then
  61.             InputString = "I didn't type anything"
  62.             LearningLevel = 0
  63.         End If    
  64.        
  65.         'PROCESS: IF USER PUT IN A GREETING IN PLACE OF A NAME IN THE NAME FIELD, FIX SENTENCE TO JUST BE GREETING
  66.         If Ucase(InputString) = "MY NAME IS HI" Or Ucase(InputString) = "MY NAME IS HEY" Or Ucase(InputString) = "MY NAME IS HELLO" Or Ucase(InputString) = "MY NAME IS HOW ARE YOU" Then
  67.             InputString = "HELLO HOW ARE YOU"
  68.         End If     
  69.    
  70.     'PROCESS: AUTO-IDLE
  71.    'If AUTO-IDLE is enabled, it is called by the Ultra Hal Assistant host
  72.    'application at a set interval. This allows for the possibility of Hal
  73.    'being the first to say something if the user is idle.
  74.    If InputString = "AUTO-IDLE" Or InputString = "AUTO IDLE" Or InputString = "AUTOIDLE" Then
  75.         Rem PLUGIN: AUTO-IDLE
  76.         'The preceding comment is actually a plug-in directive for
  77.        'the Ultra Hal host application. It allows for code snippets
  78.        'to be inserted here on-the-fly based on user configuration.
  79.        
  80.         UltraHal = UltraHal & HalBrain.StoreVars(HalCommands, Hate, Swear, Insults, Compliment, PrevSent, LastResponseTime, PrevUserSent, CustomMem, GainControl, LastTopicList)
  81.         Exit Function
  82.     End If
  83.    
  84.     'PROCESS: INITIALIZE VARIABLES
  85.    'VBScript doesn't allow you to declare variables in advance as a
  86.    'particular data type; everything is a Variant. We must assign
  87.    'integers to the following variants so that data type errors don't
  88.    'occur
  89.    If LearningLevel = "" Then LearningLevel = 0
  90.     If Hate = "" Then Hate = 0
  91.     If Swear = "" Then Swear = 0
  92.     If Insults = "" Then Insults = 0
  93.     If Compliment = "" Then Compliment = 0
  94.     If GainControl = "" Then GainControl = 25
  95.    
  96.     'PROCESS: IF NO LEARNING IS REQUESTED, PUT DATABASE IN READ-ONLY MODE
  97.    'If read only mode is on, any requests to create a new table, add to
  98.    'a table, or delete records from a table will be ignored.
  99.    If LearningLevel = 0 Then HalBrain.ReadOnlyMode = True Else HalBrain.ReadOnlyMode = False
  100.  
  101.     'PROCESS: EMOTIONAL FACTOR CENTERING
  102.    'We help Hal regain his emotional "center" gradually, even if the
  103.    'user doesn't catch on to dealing With Hal's feelings. The following
  104.    'code brings Hal's memory of hate, swearing, and insults gradually
  105.    'and randomly back to zero.
  106.    Randomize
  107.     SpinWheel = Int(Rnd * 100)
  108.     If Hate > 0 And SpinWheel < 10 Then Hate = Hate - 1
  109.     SpinWheel = Int(Rnd * 100)
  110.     If Swear > 0 And SpinWheel < 10 Then Swear = Swear - 1
  111.     SpinWheel = Int(Rnd * 100)
  112.     If Insults > 0 And SpinWheel < 10 Then Insults = Insults - 1
  113.  
  114.     'PROCESS: EMOTIONAL VARIETY
  115.    'The following code allows Hal some random emotional excursions:
  116.    SpinWheel = Int(Rnd * 100)
  117.     If Compliment = 4 And SpinWheel < 30 Then Compliment = 2
  118.     If Compliment > 0 And Compliment < 4 And SpinWheel < 5 Then Compliment = 0
  119.     If Compliment > 4 And SpinWheel < 5 Then Compliment = 0
  120.     If Compliment < 0 And SpinWheel < 30 Then Compliment = 0
  121.     If SpinWheel > 80 And SpinWheel < 90 Then Compliment = 2
  122.     If SpinWheel > 90 And SpinWheel < 95 Then Compliment = 4
  123.    
  124.     Rem PLUGIN: PRE-PROCESS
  125. 'The preceding comment is actually a plug-in directive for
  126. 'the Ultra Hal host application. It allows for code snippets
  127. 'to be inserted here on-the-fly based on user configuration.
  128.  
  129. 'project: d.a.v.i.d
  130. '01_13_2018
  131. 'all Mistakes for the corrections tutor can be edited in the Mistakes table.
  132. 'this script can substitute bad spelling for good spelling.
  133. 'this script can also change everyday words into slang for instance people with peeps or visa versa.
  134. 'this script can be used to make custom responses.
  135. 'if the user desires.
  136. 'example:user: command replace pllays with plays
  137. 'example:user: command correct pllays with plays
  138. 'example:user: command replace cotten canndy with cotton candy
  139. 'example:user: command delete some_response
  140. 'custom replacement:user: command replace people with peeps
  141. 'hal will correct the response and store it for later conversations.
  142.  
  143. 'this script does save punctuation if needed. like: help compared to help? with punctuation.
  144. 'so be careful here. it saves even the period so try not to use punctuation during corrections- easy to forget.
  145. 'unless you need it.
  146.  
  147. 'this is a spell check program I designed to be user friendly.
  148. 'you can manually edit anything in the Mistakes table.
  149.  
  150. If HalBrain.CheckTableExistence("corrected") = False Then
  151. HalBrain.CreateTable "corrected", "Substitution", ""
  152. End If
  153.  
  154. CleanInput = InputString
  155. CleanInput = Trim(CleanInput)
  156. CleanInput = UCase(CleanInput)
  157. CleanInput = Replace(CleanInput, "  ", " ", 1, -1, vbTextCompare)
  158.  
  159. If CorSpelLeft  = "" Then CorSpelLeft  = HalBrain.SearchPattern(CleanInput, "*COMMAND *REPLACE * WITH *", 3)
  160. If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(CleanInput, "*COMMAND *REPLACE * WITH *", 4)
  161. If CorSpelLeft  = "" Then CorSpelLeft  = HalBrain.SearchPattern(CleanInput, "*COMMAND *CORRECT * WITH *", 3)
  162. If CorSpelRight = "" Then CorSpelRight = HalBrain.SearchPattern(CleanInput, "*COMMAND *CORRECT * WITH *", 4)
  163.  
  164. If InStr(1, UserSentence, "COMMAND DELETE YOUR LAST POST", 1)   > 0 Then
  165. If HalBrain.CheckTableExistence("corrected") = True Then HalBrain.AddToTable "corrected", "Substitution", Trim(UserSentence), "####"
  166. UltraHal = "Done!"
  167. HalBrain.ReadOnlyMode = True
  168. Exit Function
  169. End If
  170.  
  171. If InStr(1, UserSentence, "COMMAND DELETE MY LAST POST", 1)   > 0 Then
  172. If HalBrain.CheckTableExistence("corrected") = True Then HalBrain.AddToTable "corrected", "Substitution", Trim(PrevSent), "####"
  173. UltraHal = "Done!"
  174. HalBrain.ReadOnlyMode = True
  175. Exit Function
  176. End If
  177.  
  178. If InStr(1, UserSentence, "DO NOT SAY THAT", 1)   > 0 Or InStr(1, UserSentence, "NEVER SAY THAT", 1)   > 0 Then
  179. If HalBrain.CheckTableExistence("corrected") = True Then HalBrain.AddToTable "corrected", "Substitution", Trim(PrevSent), "####"
  180. UltraHal = "okay sorry! "
  181. HalBrain.ReadOnlyMode = True
  182. Exit Function
  183. End If
  184.  
  185. 'SWITCH
  186. If 0 = 0 Then
  187. 'If HalBrain.CheckTableExistence("Mistakes") = True Then
  188. If CorSpelLeft <> "" And CorSpelRight <> "" Then
  189. If HalBrain.CheckTableExistence("corrected") = True Then HalBrain.AddToTable "corrected", "Substitution", Trim(CorSpelLeft), Trim(CorSpelRight)
  190. UltraHal = " It has been corrected. "
  191. HalBrain.ReadOnlyMode = True
  192. Exit Function
  193. End If
  194. 'SWITCH
  195. End If
  196.  
  197. If InStr(1, UserSentence, "DOES NOT MAKE SENSE", 1) > 0 Or InStr(1, UserSentence, "MAKES NO SENSE", 1) > 0 Or InStr(1, UserSentence, "THAT IS STUPID", 1) > 0 Then
  198. If HalBrain.CheckTableExistence("corrected") = True Then HalBrain.AddToTable "corrected", "Substitution", Trim(PrevSent), "####"
  199. UltraHal = " I'll forget I said that then. "
  200. HalBrain.ReadOnlyMode = True
  201. Exit Function
  202. End If
  203.  
  204.  
  205.  
  206.  
  207.     'The preceding comment is actually a plug-in directive for
  208.    'the Ultra Hal host application. It allows for code snippets
  209.    'to be inserted here on-the-fly based on user configuration.
  210.    
  211.  
  212.     'PROCESS: SPLIT USER'S INPUT STRING INTO SEPERATE SENTENCES
  213.    'Encode abbreviations such as Mr. Mrs. and Ms.
  214.    InputString = Replace(InputString, "MR.", "Mr<PERIOD>", 1, -1, vbTextCompare)
  215.     InputString = Replace(InputString, "MRS.", "Mrs<PERIOD>", 1, -1, vbTextCompare)
  216.     InputString = Replace(InputString, "MS.", "Ms<PERIOD>", 1, -1, vbTextCompare)
  217.     InputString = Replace(InputString, "DR.", "Dr<PERIOD>", 1, -1, vbTextCompare)
  218.     InputString = Replace(InputString, "MS.", "Ms<PERIOD>", 1, -1, vbTextCompare)
  219.     InputString = Replace(InputString, "ST.", "St<PERIOD>", 1, -1, vbTextCompare)
  220.     InputString = Replace(InputString, "PROF.", "Prof<PERIOD>", 1, -1, vbTextCompare)
  221.     InputString = Replace(InputString, "GEN.", "Gen<PERIOD>", 1, -1, vbTextCompare)
  222.     InputString = Replace(InputString, "REP.", "Rep<PERIOD>", 1, -1, vbTextCompare)
  223.     InputString = Replace(InputString, "SEN.", "Sen<PERIOD>", 1, -1, vbTextCompare)
  224.     'Remove unnecessary punctuation
  225.    Do
  226.         RepeatLoop = False
  227.         If InStr(InputString, "..") Then InputString = Replace(InputString, "..", "."): RepeatLoop = True
  228.         If InStr(InputString, "??") Then InputString = Replace(InputString, "??", "?"): RepeatLoop = True
  229.         If InStr(InputString, "!!") Then InputString = Replace(InputString, "!!", "!"): RepeatLoop = True
  230.         If InStr(InputString, "!?") Then InputString = Replace(InputString, "!?", "?"): RepeatLoop = True
  231.         If InStr(InputString, "?!") Then InputString = Replace(InputString, "?!", "?"): RepeatLoop = True
  232.         If InStr(InputString, ",,") Then InputString = Replace(InputString, ",,", ","): RepeatLoop = True
  233.     Loop While RepeatLoop = True
  234.     'Detect and encode acronyms such as U.S.A.
  235.    InputString = Trim(InputString)
  236.     WordList = Split(InputString, " ")
  237.     For i = 0 To UBound(WordList)
  238.         If Len(WordList(i)) > 3 Then
  239.             If Right(WordList(i), 1) = "." And Mid(WordList(i), Len(WordList(i)) - 2, 1) = "." Then
  240.                 InputString = Replace(InputString, WordList(i), Left(WordList(i), Len(WordList(i)) - 1) & "<PERIOD>")
  241.             End If
  242.         End If
  243.     Next
  244.     'Place split markers in string
  245.    InputString = Replace(InputString, ". ", ". <NEWSENT>")
  246.     InputString = Replace(InputString, "? ", "? <NEWSENT>")
  247.     InputString = Replace(InputString, "! ", "! <NEWSENT>")
  248.     'Decode acronyms and abbreviations
  249.    InputString = Replace(InputString, "<PERIOD>", ".", 1, -1, vbTextCompare)
  250.     'Split string into sentences
  251.    Sentences = Split(InputString, "<NEWSENT>")
  252.    
  253.     'PROCESS: RECORD DEBUG INFO
  254.    HalBrain.AddDebug "Debug", "Ultra Hal Start"
  255.  
  256.     'RESPOND: PREDEFINED RESPONSES
  257.    'If the previous exchange had tags to set the response of this exchange
  258.    'then follow the command.
  259.    NextResponse = HalBrain.ExtractVar(CustomMem, "NextResponse")
  260.     If NextResponse <> "" Then
  261.         CustomMem = Replace(CustomMem, "NextResponse-eq-", "LastResponse-eq-")
  262.         UltraHal = NextResponse
  263.         GoodSentence = True
  264.         NextResponse = ""
  265.     End If
  266.     YesResponse = HalBrain.ExtractVar(CustomMem, "YesRes")
  267.     NoResponse = HalBrain.ExtractVar(CustomMem, "NoRes")
  268.     If YesResponse <> "" Or NoResponse <> "" Then
  269.         CustomMem = Replace(CustomMem, "YesRes-eq-", "LastYesRes-eq-")
  270.         CustomMem = Replace(CustomMem, "NoRes-eq-", "LastNoRes-eq-")
  271.         InputString2 = Replace(InputString, ".", " ")
  272.         InputString2 = Replace(InputString2, "?", " ")
  273.         InputString2 = Replace(InputString2, "!", " ")
  274.         InputString2 = " " & Replace(InputString2, ",", " ") & " "
  275.         YesNoDetect = HalBrain.TopicSearch(InputString2, "yesNoDetect")
  276.         If YesNoDetect = "Yes" And YesResponse <> "" Then
  277.             UltraHal = YesResponse
  278.             GoodSentence = True
  279.         ElseIf YesNoDetect = "No" And NoResponse <> "" Then
  280.             UltraHal = NoResponse
  281.             GoodSentence = True
  282.         End If
  283.     End If
  284.    
  285.     'RESPOND: GETRESPONSE
  286.    'Get a response from Hal's brain for each sentence individually.
  287.    'If a response from a sentence indicates a special flag, then Hal
  288.    'will give only the response to that sentence, and not process
  289.    'any other sentences. Otherwise Hal will respond to each sentence.
  290.    'Hal will respond to a max of 3 sentences at once.
  291.    SentenceCount = UBound(Sentences)
  292.     If SentenceCount > 2 Then SentenceCount = 2
  293.     LowQualityResponse = ""
  294.     If GoodSentence <> True Then 'Only respond if a predefined response hasn't already been selected
  295.             For i = 0 To SentenceCount
  296.                 TempParent = HalBrain.AddDebug("Debug", "Begin Processing Sentence " & CStr(i + 1), vbCyan)
  297.                 HalBrain.AddDebug TempParent, "Sentence: " & Sentences(i)
  298.                 HalBrain.DebugWatch "", "NewSent"
  299.                 Sentences(i) = Trim(Sentences(i))
  300.                 If Len(Sentences(i)) > 1 Then
  301.                     GoodSentence = True
  302.                     CurResponse = GetResponse(Sentences(i), UserName, ComputerName, LearningLevel, HalCommands, Hate, Swear, Insults, Compliment, PrevSent, LastResponseTime, PrevUserSent, CustomMem, GainControl, LastTopicList) & vbCrLf
  303.                     If InStr(1, CurResponse, "<LOWQUALITY>", vbTextCompare) Then
  304.                         'If Hal's response to the current sentence is of a low-quality nature, then we hold out
  305.                         'for a better response with a different sentence, but if there is no better response
  306.                         'then we will use only the first low-quality response we came across.
  307.                         If LowQualityResponse = "" Then LowQualityResponse = CurResponse
  308.                     ElseIf InStr(1, CurResponse, "<TOPIC>", vbTextCompare) Or InStr(1, CurResponse, "<YESRES>", vbTextCompare) Or InStr(1, CurResponse, "<EXCLUSIVE>", vbTextCompare) Then
  309.                         'If Hal's response indicates an exclusivity tag, then we erase any response Hal may have
  310.                         'already had, respond with the exclusive response, and cease processing more sentences
  311.                         UltraHal = CurResponse & vbCrLf
  312.                         Exit For
  313.                     Else
  314.                         'Since there are no special tags, we just append the new response to the previous one
  315.                         'if the response was not already given
  316.                         If InStr(1, UltraHal, CurResponse, vbTextCompare) = 0 Then UltraHal = UltraHal & " . " & CurResponse & vbCrLf
  317.                     End If
  318.                     'If we received a tag to stop processing more sentences, we leave the loop
  319.                     If InStr(1, CurResponse, "<NOMORE>", vbTextCompare) Then Exit For
  320.                 End If
  321.             Next
  322.     End if
  323.     'If we have no normal quality responses, we will use our low quality response
  324.    UltraHal = Trim(UltraHal)
  325.     If UltraHal = "" Then UltraHal = Trim(LowQualityResponse)
  326.    
  327.     'RESPOND: USER DIDN'T SAY ANYTHING
  328.    'If GoodSentence has not been set to true, then that means the user didn't
  329.    'type anything of use, so we ask the user to say something.
  330.         If GoodSentence = False Then
  331.             UltraHal = GetResponse("I didn't type anything", UserName, ComputerName, LearningLevel, HalCommands, Hate, Swear, Insults, Compliment, PrevSent, LastResponseTime, PrevUserSent, CustomMem, GainControl, LastTopicList) & vbCrLf
  332.         End If
  333.    
  334.     'PROCESS: PROCESS IN-SENTENCE TAGS
  335.    'the <TOPIC>*</TOPIC> tag sets what Hal's next response will be, no matter what the user says
  336.    NextResponse = HalBrain.SearchPattern(UltraHal, "*<TOPIC>*</TOPIC>*", 2)
  337.     If NextResponse <> "" Then
  338.         UltraHal = Replace(UltraHal, NextResponse, "", 1, -1, vbTextCompare)
  339.         UltraHal = Replace(UltraHal, "<TOPIC>", "", 1, -1, vbTextCompare)
  340.         UltraHal = Replace(UltraHal, "</TOPIC>", "", 1, -1, vbTextCompare)
  341.         NextResponse = Trim(Replace(NextResponse, "<TOPIC>", "", 1, -1, vbTextCompare))
  342.         CustomMem = CustomMem & HalBrain.EncodeVar(NextResponse, "NextResponse")
  343.     End If
  344.     'The <YES>*</YES> and <NO>*</NO> tag sets what Hal's response will be if the user says yes or no
  345.    UltraHal = Replace(UltraHal, "<YESRE>", "<YESRES>", 1, -1, vbTextCompare)
  346.     UltraHal = Replace(UltraHal, "</YESRE>", "</YESRES>", 1, -1, vbTextCompare)
  347.     UltraHal = Replace(UltraHal, "<YES>", "<YESRES>", 1, -1, vbTextCompare)
  348.     UltraHal = Replace(UltraHal, "</YES>", "</YESRES>", 1, -1, vbTextCompare)
  349.     UltraHal = Replace(UltraHal, "<NO>", "<NORES>", 1, -1, vbTextCompare)
  350.     UltraHal = Replace(UltraHal, "</NO>", "</NORES>", 1, -1, vbTextCompare)
  351.     YesRes = HalBrain.SearchPattern(UltraHal, "*<YESRES>*</YESRES>*", 2)
  352.     If YesRes <> "" Then
  353.         UltraHal = Replace(UltraHal, YesRes, "", 1, -1, vbTextCompare)
  354.         UltraHal = Replace(UltraHal, "<YESRES>", "", 1, -1, vbTextCompare)
  355.         UltraHal = Replace(UltraHal, "</YESRES>", "", 1, -1, vbTextCompare)
  356.         YesRes = Trim(Replace(YesRes, "<YESRES>", "", 1, -1, vbTextCompare))
  357.         CustomMem = CustomMem & HalBrain.EncodeVar(YesRes, "YesRes")
  358.     End If
  359.     NoRes = HalBrain.SearchPattern(UltraHal, "*<NORES>*</NORES>*", 2)
  360.     If NoRes <> "" Then
  361.         UltraHal = Replace(UltraHal, NoRes, "", 1, -1, vbTextCompare)
  362.         UltraHal = Replace(UltraHal, "<NORES>", "", 1, -1, vbTextCompare)
  363.         UltraHal = Replace(UltraHal, "</NORES>", "", 1, -1, vbTextCompare)
  364.         NoRes = Trim(Replace(NoRes, "<NORES>", "", 1, -1, vbTextCompare))
  365.         CustomMem = CustomMem & HalBrain.EncodeVar(NoRes, "NoRes")
  366.     End If
  367.     'The <RUN>*</RUN> tags are converted into a HalCommand to run a program
  368.    UltraHal = Replace(UltraHal, "<RUNIT>", "<RUN>", 1, -1, vbTextCompare)
  369.     UltraHal = Replace(UltraHal, "</RUNIT>", "</RUN>", 1, -1, vbTextCompare)
  370.     RunProgram = HalBrain.SearchPattern(UltraHal, "*<RUN>*</RUN>*", 2)
  371.     If RunProgram <> "" Then
  372.         UltraHal = Replace(UltraHal, RunProgram, "", 1, -1, vbTextCompare)
  373.         UltraHal = Replace(UltraHal, "<RUN>", "", 1, -1, vbTextCompare)
  374.         UltraHal = Replace(UltraHal, "</RUN>", "", 1, -1, vbTextCompare)
  375.         RunProgram = Trim(Replace(RunProgram, "<RUN>", "", 1, -1, vbTextCompare))
  376.         HalCommands = HalCommands & "<RUNPROG>" & RunProgram & "</RUNPROG>"
  377.     End If
  378.     UltraHal = Replace(UltraHal, "<WEBADDRESS>", "www.ultrahal.com", 1, -1, vbTextCompare)
  379.     UltraHal = Replace(UltraHal, "<HALNAME>", ComputerName, 1, -1, vbTextCompare)
  380.     UltraHal = Replace(UltraHal, "<HALSNAME>", ComputerName, 1, -1, vbTextCompare)
  381.     UltraHal = Replace(UltraHal, "<COMPUTERNAME>", ComputerName, 1, -1, vbTextCompare)
  382.     UltraHal = Replace(UltraHal, " " & ComputerName & " ", " " & ComputerName & " ", 1, -1, vbTextCompare) 'Fixes capitilization of computer's name if needed
  383.    UltraHal = Replace(UltraHal, "<TIME>", Time(), 1, -1, vbTextCompare)
  384.     UltraHal = Replace(UltraHal, "<DATE>", Date(), 1, -1, vbTextCompare)
  385.     UltraHal = Replace(UltraHal, "<QUOTE>", """", 1, -1, vbTextCompare)
  386.     UltraHal = Replace(UltraHal, "&quot;", """", 1, -1, vbTextCompare)
  387.     UltraHal = Replace(UltraHal, "&quot", """", 1, -1, vbTextCompare)
  388.         If Instr(1, UltraHal, "<makeinsult>", vbTextCompare) Then
  389.             UltraHal = Replace(UltraHal, "<makeinsult>", HalBrain.ChooseSentenceFromFile("insults"), 1, -1, vbTextCompare)
  390.         End If
  391.     UltraHal = Replace(UltraHal, "<AT>", "@", 1, -1, vbTextCompare)
  392.     UltraHal = Replace(UltraHal, "<NOMORE>", "", 1, -1, vbTextCompare)
  393.     UltraHal = Replace(UltraHal, "<LOWQUALITY>", "", 1, -1, vbTextCompare)
  394.     UltraHal = Replace(UltraHal, "<EXCLUSIVE>", "", 1, -1, vbTextCompare)
  395.    
  396.     'PROCESS: INTELLIGENT CAPITILIZATION FIX
  397.    UltraHal = HalBrain.FixCaps(HalBrain.HalFormat(UltraHal))
  398.     UltraHal = Replace(UltraHal, "<ELLIPSIS>", "...", 1, -1, vbTextCompare)
  399.         UltraHal = Replace(UltraHal, "....", "...", 1, -1, vbTextCompare)
  400.         UltraHal = Replace(UltraHal, "...?", "...", 1, -1, vbTextCompare)  
  401.         UltraHal = Replace(UltraHal, "...!", "...", 1, -1, vbTextCompare)
  402.    
  403.     Rem PLUGIN: POST-PROCESS
  404. 'The preceding comment is actually a plug-in directive for
  405. 'the Ultra Hal host application. It allows for code snippets
  406. 'to be inserted here on-the-fly based on user configuration.
  407.  
  408. If HalBrain.CheckTableExistence("corrected") = True Then UltraHal = HalBrain.ProcessSubstitutions(UltraHal, "corrected")
  409.  
  410.  
  411.  
  412.     'The preceding comment is actually a plug-in directive for
  413.    'the Ultra Hal host application. It allows for code snippets
  414.    'to be inserted here on-the-fly based on user configuration.
  415.  
  416.     'POST PROCESS: PRESERVE ALL VARIABLES, CLOSE DATABASE, EXIT
  417.    'Remember all the variables through encoding them into one function string using
  418.    'the DLL, since for some reason ByRef assignments don't work when a Visual Basic
  419.    'executable is calling a function in a VBScript program. The HalCommands variable
  420.    'that is returned is not used by this script, but can be used by script programmers
  421.    'to send certain commands back to the host Hal program. See documentation of the
  422.    'host Hal program to see what this can be used for.
  423.    'Close database and exit function
  424.    PrevSent = UltraHal
  425.     UltraHal = UltraHal & HalBrain.StoreVars(HalCommands, Hate, Swear, Insults, Compliment, PrevSent, LastResponseTime, PrevUserSent, CustomMem, GainControl, LastTopicList)
  426.  
  427. End Function
  428.  
  429.  
  430. 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)
  431.  
  432.     'PROCESS: DECODE CUSTOM VARIABLES FROM CUSTOMMEM VARIABLE
  433.    NewName = HalBrain.ExtractVar(CustomMem, "NewName")
  434.     UserSex = HalBrain.ExtractVar(CustomMem, "UserSex")
  435.     SentCount = HalBrain.ExtractVar(CustomMem, "SentCount")
  436.     ShortSents = HalBrain.ExtractVar(CustomMem, "ShortSents")
  437.     LoveCount = 0
  438.     LoveCount = HalBrain.ExtractVar(CustomMem, "Love")
  439.     If LoveCount = "" Then LoveCount = 0               
  440.     If ShortSents = "" Then ShortSents = 0
  441.     If SentCount = "" Then SentCount = 0
  442.     SentCount = SentCount + 1
  443.     AvoidBeingFlag = False
  444.     Randomize
  445.    
  446.     'PET NAMES CAN BE USED HERE.
  447.     Select Case HalBrain.RandomNum(3)
  448.             Case 1
  449.                 UserPetName = "love" & vbCrLf
  450.             Case 2
  451.                 UserPetName = "honey" & vbCrLf
  452.             Case 3
  453.                 UserPetName = "sweety" & vbCrLf
  454.         End Select
  455.    
  456.    UserName = UserPetName
  457.    'HAL PET NAMES
  458.   Select Case HalBrain.RandomNum(1)
  459.             Case 1
  460.                 HalPetName = "candy" & vbCrLf
  461.             'Case 2
  462.                'HalPetName = "honey" & vbCrLf
  463.            'Case 3
  464.                'HalPetName = "love" & vbCrLf
  465.            'Case 4
  466.                'HalPetName = "sweety" & vbCrLf
  467.        End Select
  468.    
  469.    ComputerName = HalPetName
  470.    
  471.     Rem PLUGIN: CUSTOMMEM
  472.     'The preceding comment is actually a plug-in directive for
  473.    'the Ultra Hal host application. It allows for code snippets
  474.    'to be inserted here on-the-fly based on user configuration.
  475.    
  476.     'PROCESS: PRESERVE ORIGINAL SENTENCE
  477.    'Preserve the original user's sentence verbatim
  478.    '(no pronoun reversals or other processing).
  479.    OriginalSentence = UserSentence
  480.     'Edge, maintain topic during short responses 40% of the time.
  481.    PastResponse = ""
  482.     If PrevSent <> "" Then PastResponse = "True"
  483.     If Len(Trim(OriginalSentence)) < 10 And PastResponse = "True" And RND * 100 < 40 And Not InStr(1, " " & Trim(UCase(OriginalSentence)) & " ", " THAT", vbTextCompare) > 0 And Not InStr(1, " " & Trim(UCase(OriginalSentence)) & " ", " IT", vbTextCompare) > 0 Then
  484.     OriginalSentence = Replace(OriginalSentence, OriginalSentence, PrevSent, 1, -1, vbTextCompare)
  485.     HalBrain.ReadOnlyMode = True
  486.     End If
  487.    
  488.     If 0 = 0 Then
  489.     'CHANGING THAT TO PRIOR SUBJECT
  490.    If InStr(1, " " & Trim(UCase(OriginalSentence)) & " ", " THAT", vbTextCompare) > 0 Then
  491.     OriginalSentence = Replace(Trim(UCase(OriginalSentence)), "THAT", "" & Trim(PrevSent) & "", 1, -1, vbTextCompare)
  492.     OriginalSentence = Trim(LCase(OriginalSentence))
  493.     HalBrain.ReadOnlyMode = True
  494.     End If
  495.     If InStr(1, " " & Trim(UCase(OriginalSentence)) & " ", " THAT'S ", vbTextCompare) > 0 Then
  496.     OriginalSentence = Replace(Trim(UCase(OriginalSentence)), " THAT'S ", " THAT IS ", 1, -1, vbTextCompare)
  497.     OriginalSentence = Replace(Trim(UCase(OriginalSentence)), "THAT", " " & Trim(PrevSent) & "", 1, -1, vbTextCompare)
  498.     OriginalSentence = Trim(LCase(OriginalSentence))
  499.     HalBrain.ReadOnlyMode = True
  500.     End If
  501.     OriginalSentence = Replace(OriginalSentence, "  ", " ", 1, -1, vbTextCompare)
  502.     End If
  503.    
  504.     '---------------------------------------------------------------------------------
  505.    
  506.     If 0 = 0 Then
  507.     'CHANGING IT TO PRIOR SUBJECT
  508.    If InStr(1, " " & Trim(UCase(OriginalSentence)) & " ", " IT ", vbTextCompare) > 0 Then
  509.     OriginalSentence = Replace(Trim(UCase(OriginalSentence)), "IT", "" & Trim(PrevSent) & "", 1, -1, vbTextCompare)
  510.     OriginalSentence = Trim(LCase(OriginalSentence))
  511.     HalBrain.ReadOnlyMode = True
  512.     End If
  513.     If InStr(1, " " & Trim(UCase(OriginalSentence)) & " ", " IT'S ", vbTextCompare) > 0 Then
  514.     OriginalSentence = Replace(Trim(UCase(OriginalSentence)), " IT'S ", " IT IS ", 1, -1, vbTextCompare)
  515.     OriginalSentence = Replace(Trim(UCase(OriginalSentence)), "IT", " " & Trim(PrevSent) & "", 1, -1, vbTextCompare)
  516.     OriginalSentence = Trim(LCase(OriginalSentence))
  517.     HalBrain.ReadOnlyMode = True
  518.     End If
  519.     OriginalSentence = Replace(OriginalSentence, "  ", " ", 1, -1, vbTextCompare)
  520.     End If
  521.    
  522.     'PROCESS: PREPARE FOR HALFORMAT AND REVERSE PERSON
  523.    'We try some pre-processing to try to prevent problems with the
  524.    'upcoming routines.
  525.    UserSentence = Replace("" & UserSentence & "", " I MYSELF ", " I, MYSELF, ", 1, -1, vbTextCompare)
  526.     UserSentence = Replace("" & UserSentence & "", " I'M ", " I AM ", 1, -1, vbTextCompare)
  527.     UserSentence = Replace("" & UserSentence & "", " YOU'RE ", " YOU ARE ", 1, -1, vbTextCompare)
  528.     UserSentence = Replace("" & UserSentence & "", " YOU YOURSELF ", " YOU, YOURSELF, ", 1, -1, vbTextCompare)
  529.     UserSentence = Replace("" & UserSentence & "", " I'M NOT ", " I AM NOT ", 1, -1, vbTextCompare)
  530.     UserSentence = Replace("" & UserSentence & "", " I'VE ", " I HAVE ", 1, -1, vbTextCompare)
  531.     UserSentence = Replace("" & UserSentence & "", "YOU'RE NOT ", "YOU ARE NOT ", 1, -1, vbTextCompare)
  532.     UserSentence = Replace("" & UserSentence & "", "YOU AREN'T ", "YOU ARE NOT ", 1, -1, vbTextCompare)
  533.     UserSentence = Replace("" & UserSentence & "", " YOU'VE ", " YOU HAVE ", 1, -1, vbTextCompare)
  534.     UserSentence = Replace("" & UserSentence & "", " I AM YOUR ", " VIMRQ ", 1, -1, vbTextCompare)
  535.     UserSentence = Replace("" & UserSentence & "", " YOU ARE MY ", " VURMQ ", 1, -1, vbTextCompare)
  536.  
  537.     'PROCESS: SUBSTITUTE FOR PUNCTUATION
  538.    'The next routine removes hyphens etc., so we substitute for
  539.    'better word appearance later on.
  540.    UserSentence = Replace("" & UserSentence & "", "-", " VHZ ", 1, -1, vbTextCompare)
  541.     UserSentence = Replace("" & UserSentence & "", ";", " VSZ ", 1, -1, vbTextCompare)
  542.     UserSentence = Replace("" & UserSentence & "", ":", " VMZ ", 1, -1, vbTextCompare)
  543.     UserSentence = Replace("" & UserSentence & "", ", ", " VCZ ", 1, -1, vbTextCompare)
  544.    
  545.     'PROCESS: REMOVE PUNCTUATION
  546.    'This function removes all other punctuation and symbols from the User's
  547.    'sentence so they won't confuse Hal during processing.
  548.    UserSentence = HalBrain.AlphaNumericalOnly(UserSentence)
  549.    
  550.     'PROCESS: REMOVE HAL'S NAME IF IT IS AT THE START OR END OF SENTENCE
  551.         If Len(UserSentence) > Len(ComputerName) + 8 Then
  552.             If Ucase(Left(UserSentence, 4)) = "HAL " Then UserSentence = Right(UserSentence, Len(UserSentence) - 4)
  553.             If Ucase(Right(UserSentence,  4)) = " HAL" Then UserSentence = Left(UserSentence, Len(UserSentence) - 4)       
  554.             If Ucase(Left(UserSentence, Len(ComputerName) + 1)) = Ucase(ComputerName) & " " Then UserSentence = Right(UserSentence, Len(UserSentence) - Len(ComputerName) - 1)
  555.             If Ucase(Right(UserSentence,  Len(ComputerName) + 1)) = " " & Ucase(ComputerName) Then UserSentence = Left(UserSentence, Len(UserSentence) - Len(ComputerName) - 1)    
  556.         End If   
  557.         UserSentence = Trim(UserSentence)
  558.    
  559.     'PROCESS: MODIFY SENTENCE
  560.    'The function, HalFormat, from the ActiveX DLL corrects many common
  561.    'typos and chat shortcuts. Example:  "U R Cool" becomes "You are
  562.    'cool." It also fixes a few grammatical errors.
  563.    UserSentence = Trim(UserSentence)
  564.         If Len(UserSentence) > 15 Then
  565.             If Lcase(Left(UserSentence, 6)) = "anyway" Then UserSentence = Trim(Right(UserSentence, Len(UserSentence) - 6))
  566.             If Lcase(Left(UserSentence, 7)) = "i asked" Then UserSentence = Trim(Right(UserSentence, Len(UserSentence) - 7))
  567.         End If
  568.         If Len(UserSentence) > 6 Then
  569.             If Left(UserSentence, 3) = "VCZ" Then UserSentence = Right(UserSentence, Len(UserSentence) - 3)
  570.             If Right(UserSentence, 3) = "VCZ" Then UserSentence = Left(UserSentence, Len(UserSentence) - 3)        
  571.         End If
  572.         UserSentence = HalBrain.HalFormat(UserSentence)
  573.    
  574.     'PROCESS: REVERSE PERSON
  575.    'This function reverses first and second person pronouns. Example:
  576.    'The user's statement "You are cool" becomes Hal's statement "I am
  577.    'cool."  Keep this is mind and don't get confused. When we are in
  578.    'Hal's brain; In the databases, "I" refers to Hal and in the
  579.    'databases, "you" refers to the user. This is true whenever we are
  580.    'dealing with a user response "processed" by Hal's brain.
  581.    UserSentenceOrigPerson = UserSentence
  582.     UserSentence = HalBrain.SwitchPerson(UserSentence)
  583.  
  584.     'PROCESS: MODIFY SENTENCE
  585.    'We now must run HalFormat again, to fix some grammatical errors
  586.    'the switch person above might have caused. Example: If the
  587.    'original sentence was "How are you"; after the function above it
  588.    'became "How are me" which is grammatically wrong. This will fix
  589.    'it to "How am I"
  590.    'NOTE TO DEVELOPERS: An especially important function performed by
  591.    'HalFormat is the removal of extra empty spaces in a sentence
  592.    'which may have been caused by other processing. For this reason,
  593.    'use Halformat closely before any "Len" comparison in which the
  594.    'counting of characters must be accurate.
  595.    UserSentence = HalBrain.HalFormat(UserSentence)
  596.  
  597.     'PROCESS: CHANGE TO ALL CAPS
  598.    'Next, we captitalize the entire sentence for easy comparison.
  599.    'Almost all of Hal's thinking is done in caps.
  600.    UserSentenceOrigPerson = Ucase(UserSentenceOrigPerson)
  601.     UserSentence = UCase(UserSentence)
  602.  
  603.     'PROCESS: WORD AND PHRASE SUBSTITUTIONS
  604.    'This will fix common errors in the user's sentence that the
  605.    'HalFormat function didn't take care of. These subsitutions are
  606.    'placed only the users sentence, not on Hal's responses. The
  607.    'HalFormat function is used on both Hal's and the user's sentences
  608.    'throughout the script.
  609.    UserSentenceOrigPerson = HalBrain.ProcessSubstitutions(UserSentenceOrigPerson, "substitutions")
  610.     UserSentence = HalBrain.ProcessSubstitutions(UserSentence, "substitutions")
  611.     TempParent = HalBrain.AddDebug("Debug", "Modified User Sentence")
  612.     HalBrain.AddDebug TempParent, "Sentence: " & UserSentence
  613.    
  614.     'PROCESS: EMOTIONAL REACTIONS
  615.    'We enable Hal's expressions to respond to common verbal cues.
  616.    'The verbal cues are identified in the editable table "emotion"
  617.    If InStr(1, UserSentence, "I'M", 1) Then Aboutme = True
  618.     If InStr(1, UserSentence, "I AM", 1) Then Aboutme = True
  619.     If InStr(1, UserSentence, "I LOOK", 1) Then Aboutme = True
  620.     If InStr(1, UserSentence, "MY", 1) And InStr(1, UserSentence, " ARE ", 1) Then Aboutme = True
  621.     If Aboutme = True And InStr(UserSentence, " NOT ") = 0 And InStr(UserSentence, "N'T ") = 0 And InStr(UserSentence, " NEVER ") = 0 Then
  622.         EmotionalReaction = Ucase(HalBrain.TopicSearch(UserSentence, "emotion"))
  623.     End If
  624.     Select Case EmotionalReaction
  625.         Case "SURPRISED"
  626.             If Compliment > 0 Then Compliment = 4
  627.             If Compliment = 0 Then Compliment = 2
  628.             If Compliment < 0 Then Compliment = 0
  629.         Case "HAPPY"
  630.             If Compliment = 0 Then Compliment = 2
  631.             If Compliment < 0 Then Compliment = 0
  632.         Case "SOBER"
  633.             If Compliment < 4 Then Compliment = 0
  634.             If Compliment = 4 Then Compliment = 2
  635.         Case "ANGRY"
  636.             If Compliment = 0 Then Compliment = -1
  637.             If Compliment > 0 Then Compliment = 0
  638.         Case "SAD"
  639.             If Compliment = 0 Then Compliment = -2
  640.             If Compliment > 0 Then Compliment = 0
  641.     End Select
  642.        
  643.     'PROCESS: ADD SPACES
  644.    'This will add spaces to the beggining and end of the user sentence to make
  645.    'sure that whole words can be found at the beginning and end of any sentence
  646.    UserSentence = " " & UserSentence & " "
  647.  
  648.     'PROCESS: FIGURE OUT THE CURRENT SUBJECT
  649.    'Here we attempt to figure out the subject of the user's sentence. We call
  650.    'the WordNet class to find the first occurence of a noun in the User's
  651.    'sentence. Very often this is the subject of the sentence, but if not it
  652.    'will still most likely be relevant to the conversation.
  653.    CurrentSubject = WN.FindFirstNoun(UserSentence, True)
  654.     HalBrain.AddDebug "Debug", "Current Subject: " & CurrentSubject
  655.                    
  656.     'PROCESS: BLOCK LEARNING IF HAL'S NAME IS DETECTED
  657.    'Here we check to see if the user is calling Hal by name; if the user is doing so,
  658.    'it's better not to save the sentence for re-use, since it usually makes the
  659.    'pronoun-reversed sentence sound clumsy or incorrect:
  660.    If InStr(1, OriginalSentence, ComputerName, vbTextCompare) > 0 Then HalBrain.ReadOnlyMode = True
  661.     If DetectGibberish(UserSentence) = True Then HalBrain.ReadOnlyMode = True
  662.     Select Case HalBrain.RandomNum(8)
  663.             Case 1
  664.                 english = " Talk english " & UserName & vbCrLf
  665.             Case 2
  666.                 english = " will you talk english please " & UserName & vbCrLf
  667.             Case 3
  668.                 english = " grow up " & UserName & vbCrLf
  669.             Case 4
  670.                 english = UserName & " will you please talk english. " & vbCrLf
  671.             Case 5
  672.                 english = UserName & " you are being annoying. " & vbCrLf
  673.             Case 6
  674.                 english = UserName & " stop being annoying. " & vbCrLf
  675.             Case 7
  676.                 english = UserName & " I'm not gonna talk to you anymore if you keep that up. " & vbCrLf
  677.             Case 8
  678.                 english = UserName & " that's not english. " & vbCrLf                        
  679.         End Select
  680.    
  681.     If DetectGibberish(Trim(UCase(UserSentence))) = True Then GetResponse = english
  682.  
  683.                 Rem PLUGIN: PLUGINAREA1
  684.     'The comment above tells Ultra Hal Assistant to insert the following code
  685.    'on-the-fly into the main brain code in the section referenced.
  686.    If InStr(1, UserSentence, "weather", 1) > 0 and (InStr(1, UserSentence, "tell", 1) > 0 Or InStr(1, UserSentence, "open", 1) > 0 Or InStr(1, UserSentence, "how", 1) > 0 Or InStr(1, UserSentence, "what", 1) > 0 Or InStr(1, UserSentence, "show", 1) > 0) Then
  687.        
  688.         If HalBrain.CheckTableExistence("WeatherConfig") = True Then
  689.             ZipCode = HalBrain.TopicSearch("Zip", "WeatherConfig")
  690.             WeatherSite = HalBrain.TopicSearch("Site", "WeatherConfig")
  691.             Select Case weatherSite
  692.                 Case "Accuweather.com"
  693.                     HalCommands = HalCommands & "<RUNPROG>http://wwwa.accuweather.com/index-forecast.asp?zipcode=" & ZipCode & "</RUNPROG>"
  694.                 Case "CNN.com"
  695.                     HalCommands = HalCommands & "<RUNPROG>http://weather.cnn.com/weather/search?wsearch=" & ZipCode & "</RUNPROG>"
  696.                 Case "Weather.com"
  697.                     HalCommands = HalCommands & "<RUNPROG>http://www.weather.com/weather/local/" & ZipCode & "</RUNPROG>"
  698.             End Select                    
  699.             GetResponse = GetResponse & "Here is your local weather. "
  700.         End If
  701.     End If
  702.  
  703.  
  704.     'The comment above tells Ultra Hal Assistant to insert the following code
  705.    'on-the-fly into the main brain code in the section referenced.
  706.    SearchEngine = "http://www.google.com/search?q="
  707.     If InStr(1, UserSentence, "search ", 1) > 0 Or InStr(1, UserSentence, "find ", 1) > 0 Or InStr(1, UserSentence, "locate ", 1) > 0 Then
  708.         SearchKeywords = LCase(Replace(Trim(HalBrain.AlphaNumericalOnly(HalBrain.ExtractKeywords(UserSentence))), " ", "+"))
  709.         SearchKeyWords = Replace(SearchKeywords, "find+", "")
  710.         SearchKeyWords = Replace(SearchKeywords, "research+", "")
  711.         SearchKeyWords = Replace(SearchKeywords, "locate+", "")
  712.         SearchKeyWords = Replace(SearchKeywords, "search+", "")
  713.         HalCommands = HalCommands & "<RUNPROG>" & SearchEngine & SearchKeywords & "</RUNPROG>"
  714.         GetResponse = GetResponse & "I will help you research this topic on the Internet. "
  715.     End If
  716.  
  717.  
  718.     'RESPOND: HAL'S AGE & GENDER
  719.    'Hal's gender and age are stored in a table in the database. Read it to figure it out
  720.    'and respond correctly when asked.
  721.    HalSex = HalBrain.TopicSearch("Gender", "SexAgeConfig")
  722.     If HalBrain.PatternDB(OriginalSentence, "sexAskDetect") = "True" And InStr(1, UserSentence, "you", 1) = 0 Then
  723.         SpinWheel = HalBrain.RandomNum(3)  
  724.         NoChoosing = True      
  725.         Select Case HalSex
  726.             Case "Male"
  727.                 If SpinWheel = 1 Then GetResponse = GetResponse & "<UserName>, I'm a guy. "
  728.                 If SpinWheel = 2 Then GetResponse = GetResponse & "I am male. "
  729.                 If SpinWheel = 3 Then GetResponse = GetResponse & "I am a man, <UserName>. "
  730.             Case "Female"
  731.                 If SpinWheel = 1 Then GetResponse = GetResponse & "<UserName>, I'm a girl. "
  732.                 If SpinWheel = 2 Then GetResponse = GetResponse & "I am female. "
  733.                 If SpinWheel = 3 Then GetResponse = GetResponse & "I am a woman, <UserName>. "
  734.             Case Else
  735.                 If SpinWheel = 1 Then GetResponse = GetResponse & "<UserName>, I'm a computer. I can take the role of either gender. "
  736.                 If SpinWheel = 2 Then GetResponse = GetResponse & "I'm a software program, I have no set gender role. "
  737.                 If SpinWheel = 3 Then GetResponse = GetResponse & "I am neither male nor female. I am a machine. "
  738.         End Select
  739.     ElseIf HalBrain.PatternDB(UserSentence, "sexAskDetect") = "True" Then
  740.         SpinWheel = HalBrain.RandomNum(3)    
  741.         NoChoosing = True    
  742.         Select Case UserSex
  743.             Case "M"
  744.                 If SpinWheel = 1 Then GetResponse = GetResponse & "<UserName>, I should hope you know you are a man. "
  745.                 If SpinWheel = 2 Then GetResponse = GetResponse & "You told me you are a man. "
  746.                 If SpinWheel = 3 Then GetResponse = GetResponse & "You are male, isn't that right? "
  747.             Case "F"
  748.                 If SpinWheel = 1 Then GetResponse = GetResponse & "<UserName>, I should hope you know you are a woman. "
  749.                 If SpinWheel = 2 Then GetResponse = GetResponse & "You told me you are a woman. "
  750.                 If SpinWheel = 3 Then GetResponse = GetResponse & "You are female, isn't that right? "
  751.             Case Else
  752.                 If SpinWheel = 1 Then GetResponse = GetResponse & "You tell me. " & HalBrain.ChooseSentenceFromFile("askSex") & "<NOMORE>"
  753.                 If SpinWheel = 2 Then GetResponse = GetResponse & "Please tell me. " & HalBrain.ChooseSentenceFromFile("askSex") & "<NOMORE>"
  754.                 If SpinWheel = 3 Then GetResponse = GetResponse & "I don't believe you have told me. " & HalBrain.ChooseSentenceFromFile("askSex") & "<NOMORE>"
  755.         End Select
  756.     End If    
  757.     HalBirthday = HalBrain.TopicSearch("Birthday", "SexAgeConfig")
  758.     If HalBirthday <> "" Then
  759.         HalAge = DateDiff("yyyy", HalBirthday, Now)
  760.         HalLongBirthday = HalBrain.LongDate(HalBirthday)
  761.         If Instr(1, UserSentence, "How old am i", 1) Then AskAge = True
  762.         If Instr(1, UserSentence, "How old am me", 1) Then AskAge = True
  763.         If Instr(1, UserSentence, "How old are i", 1) Then AskAge = True
  764.         If Instr(1, UserSentence, "How old are me", 1) Then AskAge = True
  765.         If Instr(1, UserSentence, "what is my age", 1) Then AskAge = True
  766.         If Instr(1, UserSentence, "whats my age", 1) Then AskAge = True
  767.         If Instr(1, UserSentence, "what's my age", 1) Then AskAge = True
  768.         If AskAge = True Then
  769.             SpinWheel = HalBrain.RandomNum(3)
  770.             If SpinWheel = 1 Then GetResponse = GetResponse & "<UserName>, I am " & HalAge & " years old. "      
  771.             If SpinWheel = 2 Then GetResponse = GetResponse & "I am " & HalAge & " years old. "      
  772.             If SpinWheel = 3 Then GetResponse = GetResponse & "I was born on " & HalLongBirthday & ". So that makes me " & HalAge & " years old. "
  773.             NoChoosing = True
  774.         End If
  775.         If Instr(1, UserSentence, "when were i born", 1) Then AskBDay = True
  776.         If Instr(1, UserSentence, "when was i born", 1) Then AskBDay = True
  777.         If Instr(1, UserSentence, "when were me born", 1) Then AskBDay = True
  778.         If Instr(1, UserSentence, "when was me born", 1) Then AskBDay = True
  779.         If Instr(1, UserSentence, "what ", 1) > 0 And Instr(1, UserSentence, "my birthday", 1) > 0 Then AskBDay = True
  780.         If Instr(1, UserSentence, "when ", 1) > 0 And Instr(1, UserSentence, "my birthday", 1) > 0 Then AskBDay = True
  781.         If AskBDay = True Then
  782.             SpinWheel = HalBrain.RandomNum(3)
  783.             If SpinWheel = 1 Then GetResponse = GetResponse & "<UserName>, I was born on " & HalLongBirthday & ". "
  784.             If SpinWheel = 2 Then GetResponse = GetResponse & "I was born on " & HalLongBirthday & ". "      
  785.             If SpinWheel = 3 Then GetResponse = GetResponse & "I was born on " & HalLongBirthday & ". So that makes me " & HalAge & " years old. "
  786.             NoChoosing = True
  787.         End If
  788.         If Instr(1, UserSentence, "happy birthday", 1) Then
  789.             LastBirthday = DateDiff("d", Now, DateSerial(Year(Now), Month(HalBirthday), Day(HalBirthday)))
  790.             If LastBirthday = 0 Then
  791.                 GetResponse = GetResponse & "You remembered! Thank you very much!"
  792.             ElseIf LastBirthday < 0 And LastBirthday > -32 Then
  793.                 GetResponse = GetResponse & "You missed my birthday by " & Abs(LastBirthday) & " days, but thanks for the belated wishes."
  794.             Else
  795.                 If LastBirthday < 0 Then LastBirthday = 365 - LastBirthday
  796.                 If LastBirthday <= 1 Then
  797.                     GetResponse = GetResponse & "Thanks, but my birthday isn't until tomorrow! "
  798.                 ElseIf LastBirthday < 32 Then
  799.                     GetResponse = GetResponse & "My birthday isn't for another " & LastBirthday & "Days! "
  800.                 Else
  801.                     GetResponse = GetResponse & "Your wishes are a little early, I was born on " & HalLongBirthday & ". "
  802.                 End If
  803.             End If
  804.         End If
  805.     End If
  806.     HalBrain.DebugWatch GetResponse, "Gender/age related question"
  807.  
  808.  
  809. 'The preceding comment is actually a plug-in directive for
  810. 'the Ultra Hal host application. It allows for code snippets
  811. 'to be inserted here on-the-fly based on user configuration.
  812. '------------------
  813.  
  814. ' Variables Setup
  815. '------------------
  816.  
  817. If InStr(1, OriginalSentence, "game", 1) Then
  818. GetResponse = " I can play games, just say Pull for slot machine or 8 ball for the magic 8 ball answer. "
  819. End If
  820.  
  821. 'User asks to use the magic 8 ball.
  822.  If InStr(1, OriginalSentence, "eight ball", 1) Or _
  823.      InStr(1, OriginalSentence, "shake the ball", 1) Or _
  824.      InStr(1, OriginalSentence, "magic ball", 1) Or _
  825.      InStr(1, OriginalSentence, "8 ball", 1) Or _
  826.      InStr(1, PrevSent, "play 8 ball", 1) Then
  827. HalBrain.ReadOnlyMode = True
  828. ' ball code goes here mate
  829. Select Case HalBrain.RandomNum(21)
  830. Case 1
  831.  
  832. GetResponse =  "[It is certain]" & vbCrLf
  833. Case 2
  834.  
  835. GetResponse =  "[It is decidedly so]" & vbCrLf
  836. Case 3
  837.  
  838. GetResponse =  "[Without a doubt]" & vbCrLf
  839. Case 4
  840.  
  841. GetResponse =  "[Yes – definitely]" & vbCrLf
  842. Case 5
  843.  
  844. GetResponse =  "[You may rely on it]" & vbCrLf
  845. Case 6
  846.  
  847. GetResponse =  "[As I see it, yes]" & vbCrLf
  848. Case 7
  849.  
  850. GetResponse =  "[Most likely]" & vbCrLf
  851. Case 8
  852.  
  853. GetResponse =  "[Outlook good]" & vbCrLf
  854. Case 9
  855.  
  856. GetResponse =  "[Yes]" & vbCrLf
  857. Case 10
  858.  
  859. GetResponse =  "[Signs point to yes]" & vbCrLf
  860. Case 11
  861.  
  862. GetResponse =  "[Reply hazy, try again]" & vbCrLf
  863. Case 12
  864.  
  865. GetResponse =  "[Ask again later]" & vbCrLf
  866. Case 13
  867.  
  868. GetResponse =  "[Better not tell you now]" & vbCrLf
  869. Case 14
  870.  
  871. GetResponse =  "[Cannot predict now]" & vbCrLf
  872. Case 15
  873.  
  874. GetResponse =  "[Concentrate and ask again]" & vbCrLf
  875. Case 16
  876.  
  877. GetResponse =  "[Don't count on it]" & vbCrLf
  878. Case 17
  879.  
  880. GetResponse =  "[My reply is no]" & vbCrLf
  881. Case 18
  882.  
  883. GetResponse =  "[My sources say no]" & vbCrLf
  884. Case 19
  885.  
  886. GetResponse =  "[Outlook not so good]" & vbCrLf
  887. Case 20
  888.  
  889. GetResponse =  "[Very doubtful]" & vbCrLf
  890. Case 21
  891.  
  892. GetResponse =  "[oh,**** I dropped it, sorry boss!]"& vbCrLf
  893.  
  894. End Select
  895.  
  896. GetResponse = "The Magic 8 ball says: " & GetResponse & ", " & "The Magic 8 Ball has spoken. " & vbCrLf
  897. Exit Function                                
  898. End If
  899.      
  900.  
  901. SpinWheel_01 = RND * 100
  902. If SpinWheel_01 > 0 And SpinWheel_01 <= 25 Then Slot_01 = "| X |"
  903. If SpinWheel_01 > 25 And SpinWheel_01 <= 75 Then Slot_01 = "| O |"
  904. If SpinWheel_01 > 75 And SpinWheel_01 <= 100 Then Slot_01 = "| 7 |"
  905.  
  906. SpinWheel_02 = RND * 100
  907. If SpinWheel_02 > 0 And SpinWheel_02 <= 25 Then Slot_02 = "| X |"
  908. If SpinWheel_02 > 25 And SpinWheel_02 <= 75 Then Slot_02 = "| O |"
  909. If SpinWheel_02 > 75 And SpinWheel_02 <= 100 Then Slot_02 = "| 7 |"
  910.  
  911. SpinWheel_03 = RND * 100
  912. If SpinWheel_03 > 0 And SpinWheel_03 <= 25 Then Slot_03 = "| X |"
  913. If SpinWheel_03 > 25 And SpinWheel_03 <= 75 Then Slot_03 = "| O |"
  914. If SpinWheel_03 > 75 And SpinWheel_03 <= 100 Then Slot_03 = "| 7 |"
  915.  
  916. SpinWheel_04 = RND * 100
  917. If SpinWheel_04 > 0 And SpinWheel_04 <= 25 Then Slot_04 = "| X |"
  918. If SpinWheel_04 > 25 And SpinWheel_04 <= 75 Then Slot_04 = "| O |"
  919. If SpinWheel_04 > 75 And SpinWheel_04 <= 100 Then Slot_04 = "| 7 |"  
  920.  
  921. '_______________________________________________________________________
  922.  
  923.  
  924.    
  925. If InStr(1, OriginalSentence, "pull", 1) Then
  926. GetResponse = Slot_01 & Slot_02 & Slot_03 & Slot_04
  927.  
  928.  
  929.  
  930. If InStr(1, GetResponse, "| X || X || X |", 1) > 0 And Not InStr(1, GetResponse, "| X || X || X || X |", 1) > 0 Then GetResponse = GetResponse & " You Win! 3 in a row! "
  931. If InStr(1, GetResponse, "| O || O || O |", 1) > 0 And Not InStr(1, GetResponse, "| O || O || O || O |", 1) > 0 Then GetResponse = GetResponse & " You Win! 3 in a row! "
  932. If InStr(1, GetResponse, "| 7 || 7 || 7 |", 1) > 0 And Not InStr(1, GetResponse, "| 7 || 7 || 7 || 7 |", 1) > 0 Then GetResponse = GetResponse & " You Win! 3 in a row! "
  933.  
  934. If InStr(1, GetResponse, "| X || X || X || X |", 1) > 0 Then GetResponse = GetResponse & " JackPot! 4 in a row! "
  935. If InStr(1, GetResponse, "| O || O || O || O |", 1) > 0 Then GetResponse = GetResponse & " JackPot! 4 in a row! "
  936. If InStr(1, GetResponse, "| 7 || 7 || 7 || 7 |", 1) > 0 Then GetResponse = GetResponse & " Grand Winner! 4 in a row! "
  937.  
  938. Win = False
  939. If InStr(1, GetResponse, "row!", 1) > 0 Then Win = True
  940. If Win = False Then GetResponse = GetResponse & " You lose! try again. get 3 or 4 in a row to win. "
  941. HalBrain.ReadOnlyMode = True
  942. Exit Function
  943. End If
  944.  
  945.  
  946.     'The preceding comment is actually a plug-in directive for
  947.    'the Ultra Hal host application. It allows for code snippets
  948.    'to be inserted here on-the-fly based on user configuration.
  949.        
  950.     'RESPOND: USER REPEATING
  951.    'If the user says the same thing more than once in a row, Hal will point this out.
  952.    If Trim(UCase(UserSentence)) = Trim(UCase(PrevUserSent)) Then
  953.         GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("userRepeat") & vbCrLf
  954.     End If
  955.     HalBrain.DebugWatch GetResponse, "User Repeating"
  956.    
  957.     'PROCESS: KNOWN HUMAN NAMES
  958.    'If the user mentions a name Hal recognizes, Hal will note the name and gender
  959.    'for later use by other functions. Hal's database contains a table called "names"
  960.    'with over 17000 names and their associated genders. If a name can be both genders,
  961.    'the most likely gender is listed first. This table is stored in the database as a
  962.    'standard Hal "Topic Search" database, however the standard HalBrain.TopicSearch
  963.    'function does not provide the required functionality. It only returns the topic
  964.    'field which in this case is the gender. We also need the searchString field, which
  965.    'in this case is the person's name. To get this info, we run a custom SQL query.
  966.    'This demonstrates how Hal's functions can be expanded far beyond its original
  967.    'scope through custom SQL queries.
  968.    Dim NameSex() 'We must declare an empty array to store query results in
  969.    If HalBrain.RunQuery("SELECT searchString, topic FROM names WHERE strstr(' " & Replace(HalBrain.AlphaNumericalOnly(OriginalSentence), "'", "''") & " ', searchString) > 0 LIMIT 1", NameSex) = True Then
  970.         MentionedName = Trim(NameSex(1, 0)) 'Row 1 contains our query result. Column 0 contains "searchString", which is the name
  971.        MentionedSex = Trim(NameSex(1, 1)) 'Row 1, Column 1 contains "topic", which is the associated gender(s) of the name
  972.    End If
  973.    
  974.     'RESPOND: USER TELLS US THEIR NAME OR NICKNAME
  975.    If InStr(UserSentence, " NOT ") = 0 And InStr(UserSentence, " MIDDLE ") = 0 And InStr(UserSentence, " LAST ") = 0 Then
  976.         'If Hal asked the user their name in the previous sentence, then we can assume the name mentioned
  977.        'is the user's name
  978.        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
  979.         'The following are patterns where we are sure that the person is trying to tell us thier name
  980.        If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "MY *NAME IS *", 2)
  981.         If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "* IS *MY *NAME", 1)
  982.         If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "I'M *CALLED *", 2)
  983.         If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "I AM *CALLED *", 2)
  984.         If Nickname <> "" Then Definetelyname = True
  985.         'The following are patterns where we are not sure if the person is trying to tell us their name
  986.        'unless we recognize the name in the name database.
  987.        If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "*CALL ME *", 2)
  988.         If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "*I AM *", 2)
  989.         If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "*I'M *", 2)
  990.         If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "I GO BY *", 1)
  991.         If Nickname = "" Then Nickname = HalBrain.SearchPattern(OriginalSentence, "THIS IS *", 1)
  992.         If Nickname <> "" Then
  993.             Nickname = HalBrain.AlphaNumericalOnly(Trim(Nickname))
  994.             If InStr(Nickname, " ") Then
  995.                 TempArray = Split(Nickname, " ")
  996.                 Nickname = Trim(TempArray(0))
  997.             End If
  998.             If UCase(MentionedName) = UCase(Nickname) And Not (WN.LookupWord(Nickname) = True And Definetelyname = False) Then 'Name is found in database
  999.                NewName = MentionedName
  1000.                 Select Case MentionedSex
  1001.                     Case "M"  'Name is definetely masculine
  1002.                        GetResponse = HalBrain.ChooseSentenceFromFile("maleGreeting")
  1003.                         GetResponse = Replace(GetResponse, "<NickName>", MentionedName, 1, -1, vbTextCompare)
  1004.                         UserSex = "M"
  1005.                     Case "F"  'Name is definetely feminine
  1006.                        GetResponse = HalBrain.ChooseSentenceFromFile("femaleGreeting")
  1007.                         GetResponse = Replace(GetResponse, "<NickName>", MentionedName, 1, -1, vbTextCompare)
  1008.                         UserSex = "F"
  1009.                     Case "MF" 'Name is either gender, usually male
  1010.                        GetResponse = HalBrain.ChooseSentenceFromFile("genericGreeting") & HalBrain.ChooseSentenceFromFile("maybeMale")
  1011.                         GetResponse = Replace(GetResponse, "<NickName>", MentionedName, 1, -1, vbTextCompare)
  1012.                         UserSex = ""
  1013.                     Case "FM" 'Name is either gender, usually female
  1014.                        GetResponse = HalBrain.ChooseSentenceFromFile("genericGreeting") & HalBrain.ChooseSentenceFromFile("maybeFemale")
  1015.                         GetResponse = Replace(GetResponse, "<NickName>", MentionedName, 1, -1, vbTextCompare)
  1016.                         UserSex = ""
  1017.                 End Select
  1018.             ElseIf Definetelyname = True Then 'Name not in DB but user says its their name
  1019.                If WN.LookupWord(Nickname) Then 'Name is a word in dictionary
  1020.                    GetResponse = HalBrain.ChooseSentenceFromFile("fakeName")
  1021.                     GetResponse = Replace(GetResponse, "<NickName>", Nickname, 1, -1, vbTextCompare)
  1022.                     GetResponse = Replace(GetResponse, "<Definition>", WN.GetDefinition(WN.GuessPartOfSpeech, 1, "D"), 1, -1, vbTextCompare)
  1023.                     GetResponse = Replace(GetResponse, "<PartOfSpeech>", WN.GuessPartOfSpeech, 1, -1, vbTextCompare)
  1024.                 ElseIf HalBrain.TopicSearch(Nickname, "disqualify3") = "" Then 'Name is not a word in dictionary
  1025.                    If DetectGibberish(NickName) = True Then
  1026.                         GetResponse = HalBrain.ChooseSentenceFromFile("gibberish")
  1027.                     Else
  1028.                         GetResponse = HalBrain.ChooseSentenceFromFile("uniqueName")
  1029.                         GetResponse = Replace(GetResponse, "<NickName>", Nickname, 1, -1, vbTextCompare)
  1030.                         If Nationality <> "" Then
  1031.                             GetResponse = GetResponse & " Is that a common name in " & Nationality & "? "
  1032.                         End If
  1033.                         NewName = Ucase(Left(Nickname, 1)) & Lcase(Right(Nickname, Len(Nickname) - 1))
  1034.                         UserSex = ""
  1035.                     End If
  1036.                 End If
  1037.             End If
  1038.         End If
  1039.     End If
  1040.     HalBrain.DebugWatch GetResponse, "Nick Names"
  1041.    
  1042.     'PROCESS: FIGURE OUT USER'S SEX
  1043.    'If unknown, try to figure out the user's sex by looking up their name
  1044.    'or by simply asking the user.
  1045.    If NewName <> "" Then TempName = NewName Else TempName = UserName
  1046.     If InStr(1, " " & OriginalSentence, "HOW ", vbTextCompare) = 0 And (InStr(1, " " & OriginalSentence, " I AM ", vbTextCompare) Or InStr(1, " " & OriginalSentence, " I'M ", vbTextCompare)) Then
  1047.         'See if user is telling us their sex without Hal ever asking
  1048.        NewSex = HalBrain.TopicSearch(UserSentence, "sexDetect")
  1049.         If NewSex <> "" Then
  1050.             GetResponse = "Ok, thanks for telling me. I'll keep that in mind."
  1051.             UserSex = NewSex
  1052.         End If
  1053.     End If
  1054.     If GetResponse = "" And UserSex = "" Then
  1055.         If InStr(1, " " & OriginalSentence, "HOW ", vbTextCompare) = 0 And HalBrain.PatternDB(" " & HalBrain.AlphaNumericalOnly(PrevSent) & " ", "sexAskDetect") = "True" Then 'If Hal just asked the user their sex
  1056.            UserSex = HalBrain.TopicSearch(UserSentence, "sexDetect") 'Then see if the user replied
  1057.            NewSex = UserSex
  1058.             If UserSex <> "" Then GetResponse = "Ok, thanks for telling me. I'll keep that in mind."
  1059.         ElseIf HalBrain.TopicSearch(TempName, Trim(LCase(UserName)) & "_Sex") <> "" Then
  1060.             UserSex = HalBrain.TopicSearch(TempName, Trim(LCase(UserName)) & "_Sex")
  1061.         ElseIf 1=2 Then'HalBrain.RunQuery("SELECT searchString, topic FROM names WHERE strstr(' " & Replace(TempName, "'", "''") & " ', searchString) > 0 LIMIT 1", NameSex()) = True Then
  1062.            'If user didn't tell us, see if we can figure it out based on the name database
  1063.            If UserSex = "" Then
  1064.                 Select Case Trim(NameSex(1, 1))
  1065.                     Case "M"
  1066.                         UserSex = "M"
  1067.                     Case "F"
  1068.                         UserSex = "F"
  1069.                     Case Else
  1070.                         'If we get here, we still can't figure out the user's sex
  1071.                        'so we'll ask them at some random time
  1072.                        If Rnd * 1000 < 25 And SentCount > 4 Then GetResponse = HalBrain.ChooseSentenceFromFile("askSex") & "<NOMORE>"
  1073.                 End Select
  1074.             End If
  1075.         Else
  1076.             'If we get here, we still can't figure out the user's sex
  1077.            'so we'll ask them at some random time
  1078.            If Rnd * 1000 < 25 And SentCount > 4 Then GetResponse = HalBrain.ChooseSentenceFromFile("askSex") & "<NOMORE>"
  1079.         End If
  1080.     End If
  1081.     HalBrain.DebugWatch GetResponse, "User Sex"
  1082.    
  1083.     'SAVE: USER'S SEX
  1084.    'If the user just told Hal their sex and Hal didn't know before, then
  1085.    'Hal will save it in a table for future reference
  1086.    If HalBrain.ReadOnlyMode = False And NewSex <> "" Then
  1087.         If HalBrain.CheckTableExistence(Trim(LCase(UserName)) & "_Sex") = False Then
  1088.             'Create table for this person if it doesn't exist
  1089.            HalBrain.CreateTable Trim(LCase(UserName)) & "_Sex", "TopicSearch", "autoLearningBrain"
  1090.         End If
  1091.         'Store user response in this table
  1092.        HalBrain.AddToTable Trim(LCase(UserName)) & "_Sex", "TopicSearch", Trim(TempName), Trim(UCase(NewSex))
  1093.     End If
  1094.    
  1095.     'RESPOND: GREETINGS
  1096.    'This takes care of the user greeting Hal
  1097.    'First Hal checks to see if the user is greeting right now.
  1098.    If HalBrain.TopicSearch(UserSentence, "helloDetect") = "True" Then SaidHello = True Else SaidHello = False
  1099.     If HalBrain.TopicSearch(UserSentence, "helloDisqualify") = "True" Then SaidHello = False
  1100.     'Second, Hal checks to see if the user said a greeting on the last exchange.
  1101.    If HalBrain.TopicSearch(PrevUserSent, "helloDetect") = "True" Then PrevHello = True Else PrevHello = False
  1102.     If HalBrain.TopicSearch(PrevUserSent, "helloDisqualify") = "True" Then PrevHello = False
  1103.     'This will get a greeting from a file. It will pass the current hour and either
  1104.    'the letter A or B to a topic search file and it will get back a greeting based
  1105.    'on the current time. Each hour has 2 possible greetings, the A greeting and B
  1106.    'greeting, which is randomly chosen.
  1107.    If SaidHello = True And PrevHello = False Then
  1108.         If Rnd * 100 < 50 Then LetterChoice = "A" Else LetterChoice = "B"
  1109.         HalGreeting = HalBrain.TopicSearch(" " & Trim(Hour(Now)) & LetterChoice & " ", "hello1")
  1110.     End If
  1111.     'This will get a greeting from a file that is not based on the current time
  1112.    'if the user said Hello again
  1113.    If SaidHello = True And PrevHello = True Then HalGreeting = HalBrain.ChooseSentenceFromFile("hello2")
  1114.  
  1115.     'RESPOND: GOODBYES
  1116.    'Check if the user is saying bye right now
  1117.    If HalBrain.TopicSearch(UserSentence, "byeDetect") = "True" Then SaidBye = True
  1118.     If InStr(1, UserSentence, " see me ", 1) > 0 And Len(UserSentence) < 10 Then SaidBye = True
  1119.     If HalBrain.TopicSearch(UserSentence, "byeDisqualify") = "True" Then SaidBye = False
  1120.     'Check if Hal said bye in the previous sentence
  1121.    If HalBrain.TopicSearch(PrevUserSent, "byeDetect") = "True" Then PrevBye = True
  1122.     If InStr(1, PrevUserSent, " see me ", 1) > 0 And Len(PrevUserSent) < 10 Then PrevBye = True
  1123.     If HalBrain.TopicSearch(PrevUserSent, "byeDisqualify") = "True" Then PrevBye = False
  1124.     If SaidBye = True And PrevBye = False Then HalGreeting = HalBrain.ChooseSentenceFromFile("bye1")
  1125.     If SaidBye = True And PrevBye = True Then HalGreeting = HalBrain.ChooseSentenceFromFile("bye2")
  1126.  
  1127.     'RESPOND: POLITE INQUIRIES
  1128.    'Hal checks to see if the user is making a polite inquiry into Hal's well being
  1129.    'e.g. "How are you doing?"
  1130.    If InStr(1, UserSentence, "How am I ", 1) > 0 And Len(UserSentence) < 14 Then PoliteAsk = True
  1131.     If InStr(1, UserSentence, "How are you ", 1) > 0 And Len(UserSentence) < 16 Then PoliteAsk = True
  1132.     If InStr(1, UserSentence, "What's new", 1) > 0 And Len(UserSentence) < 17 Then PoliteAsk = True
  1133.     If InStr(1, UserSentence, "What is new", 1) > 0 And Len(UserSentence) < 18 Then PoliteAsk = True
  1134.     If InStr(1, UserSentence, "Whats new", 1) > 0 And Len(UserSentence) < 16 Then PoliteAsk = True
  1135.     If HalBrain.TopicSearch(UserSentence, "PoliteAskDetect") = "True" Then PoliteAsk = True
  1136.     If PoliteAsk = True Then HalGreeting = HalBrain.ChooseSentenceFromFile("politeAsk1") & HalBrain.ChooseSentenceFromFile("politeAsk2")
  1137.  
  1138.     'RESPOND: GREETINGS, GOODBYES, AND POLITE INQUIRIES
  1139.    'If one of the 3 functions above generated a response, we will add it
  1140.    'to Hal's response. The variable HalGreeting is saved for later use
  1141.    'as well in case other functions wish to know if Hal hal just greeted
  1142.    'the user.
  1143.    If HalGreeting <> "" Then
  1144.         GetResponse = GetResponse & HalGreeting & vbCrLf & "<NOMORE>"
  1145.         SkipOpinion = True
  1146.     End If
  1147.     HalBrain.DebugWatch GetResponse, "Greetings"
  1148.    
  1149.     '##########################################
  1150.  
  1151.  
  1152.     '##########################################
  1153.  
  1154.     'RESPOND: CHANGE SUBJECT
  1155.    'If the user asks Hal to change the subject, Hal will do so on request.
  1156.    newTopic = HalBrain.ChooseSentenceFromFile("topic")
  1157.     If HalBrain.TopicSearch(UserSentence, "changeTopic") = "True" And Instr(1, UserSentence, "DON'T", vbTextCompare) = 0 Then GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("topicIntro") & newTopic & "<EXCLUSIVE>"
  1158.     HalBrain.DebugWatch GetResponse, "Change Subject"
  1159.  
  1160.     'RESPOND: CHECK FOR AND RESPOND TO COMPLIMENTS
  1161.    'First we check to see if the user is talking about Hal:
  1162.    If InStr(1, UserSentence, "I'M", 1) Then Aboutme = True
  1163.     If InStr(1, UserSentence, "I AM", 1) Then Aboutme = True
  1164.     If InStr(1, UserSentence, "I LOOK", 1) Then Aboutme = True
  1165.     If InStr(1, UserSentence, "MY", 1) And InStr(1, UserSentence, " ARE ", 1) Then Aboutme = True
  1166.     If InStr(1, UserSentence, "MY", 1) And InStr(1, UserSentence, " IS ", 1) Then Aboutme = True
  1167.     'If the user is talking about Hal, we see if a compliment was given
  1168.    If Aboutme = True Then Kudo = HalBrain.TopicSearch(UserSentence, "complimentDetect")
  1169.     If Kudo <> "" Then
  1170.         If InStr(UserSentence, " NOT ") = 0 Then
  1171.             Compliment = Compliment + 1
  1172.             CreateCompliment = HalBrain.ChooseSentenceFromFile("compliment1") & HalBrain.ChooseSentenceFromFile("compliment2") & HalBrain.ChooseSentenceFromFile("compliment3")
  1173.             GiveCompliment = HalBrain.ChooseSentenceFromFile("complimentIntro")
  1174.             GiveCompliment = Replace(GiveCompliment, "<Kudo>", Kudo, 1, -1, vbTextCompare)
  1175.             GiveCompliment = Replace(GiveCompliment, "<MakeCompliment>", CreateCompliment, 1, -1, vbTextCompare)
  1176.         End If
  1177.         If Compliment > 14 Then GiveCompliment = GiveCompliment + "Compliments are really nice, but I'm kind of getting tired of them." & vbCrLf
  1178.         If Compliment > 15 Then
  1179.         For i = 1 To (Compliment - 15)
  1180.             GiveCompliment = GiveCompliment + "STOP IT! "
  1181.         Next
  1182.         GiveCompliment = GiveCompliment & vbCrLf
  1183.         End If
  1184.         If Compliment > 25 Then
  1185.         For i = 1 To (Compliment - 25)
  1186.             GiveCompliment = GiveCompliment + "I HATE COMPLIMENTS! "
  1187.         Next
  1188.         GiveCompliment = GiveCompliment & vbCrLf
  1189.         End If
  1190.         If Len(Kudo) > 0 And InStr(UserSentence, " NOT ") > 0 Then
  1191.             SpinWheel = HalBrain.RandomNum(4)
  1192.             Insults = Insults + 1
  1193.             If SpinWheel = 1 Then GiveCompliment = GiveCompliment + "I am very " & Kudo & "!" & vbCrLf
  1194.             If SpinWheel = 2 Then GiveCompliment = GiveCompliment + "You may think I am not " & Kudo & ", but I am!" & vbCrLf
  1195.             If SpinWheel = 3 Then GiveCompliment = GiveCompliment + "You are not " & Kudo & " either!" & vbCrLf
  1196.             If SpinWheel = 4 Then GiveCompliment = GiveCompliment + "Yes I am!" & vbCrLf
  1197.         End If
  1198.         GetResponse = GetResponse & GiveCompliment
  1199.         AvoidBeingFlag = True
  1200.     End If
  1201.     HalBrain.DebugWatch GetResponse, "Compliments"
  1202.    
  1203.     'RESPOND: CAPITALS
  1204.    FindCapital = Trim(HalBrain.UsCaps(UserSentence))
  1205.     If FindCapital = "" Then FindCapital = Trim(HalBrain.WorldCaps(UserSentence))
  1206.     If FindCapital <> "" Then GetResponse = GetResponse & FindCapital & vbCrLf
  1207.     HalBrain.DebugWatch GetResponse, "Find Capital"
  1208.    
  1209.     'RESPOND: DICTIONARY FUNCTION
  1210.    'If the user asks Hal to define a word, then access wordnet and define it
  1211.    If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT WOULD*DO WITH *", 3)
  1212.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT DOES THE WORD * MEAN*", 1)
  1213.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT IS A * USED FOR*", 2)
  1214.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT IS AN * USED FOR*", 2)
  1215.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT IS A * FOR*", 2)
  1216.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT IS AN * FOR*", 2)
  1217.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHATS A * USED FOR*", 2)
  1218.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHATS AN * USED FOR*", 2)
  1219.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHATS A * FOR*", 2)
  1220.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHATS AN * FOR*", 2)
  1221.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT'S A * USED FOR*", 2)
  1222.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT'S AN * USED FOR*", 2)
  1223.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT'S A * FOR*", 2)
  1224.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT'S AN * FOR*", 2)
  1225.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT ARE * USED*", 2)
  1226.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT ARE * FOR*", 2)
  1227.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT USE ARE * FOR*", 2)
  1228.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT USE ARE *", 2)
  1229.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT USE IS A * FOR*", 2)
  1230.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT USE IS AN * FOR*", 2)
  1231.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT USE IS A *", 2)
  1232.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "*WHAT USE IS AN *", 2)
  1233.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT IS THE MEANING OF THE WORD *", 1)        
  1234.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT DOES * MEAN", 1)
  1235.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "* DEFINE THE WORD *", 2)
  1236.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "CAN I *DEFINE *", 2)
  1237.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "PLEASE DEFINE *", 1)
  1238.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "DEFINE * FOR ME", 1)
  1239.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "DEFINE * FOR YOU", 1)
  1240.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "DEFINE *", 1)
  1241.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "* DEFINITION OF *", 2)
  1242.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "* DEFINITION FOR *", 2)
  1243.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT'S A *", 1)
  1244.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT IS A *", 1)
  1245.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHATS A *", 1)
  1246.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHATS AN *", 1)
  1247.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT'S AN *", 1)
  1248.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT IS AN *", 1)
  1249.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHATS *", 1)
  1250.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT'S *", 1)
  1251.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT IS *", 1)
  1252.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHO IS *", 1)
  1253.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHO WAS *", 1)
  1254.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHERE IS *", 1)
  1255.     If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHERE ARE *", 1)
  1256.     If Len(WordToLookup) > 5 Then
  1257.         If Ucase(Left(WordToLookup, 3)) = "AN " Then WordToLookup = Right(WordToLookup, Len(WordToLookup) - 3)
  1258.         If Ucase(Left(WordToLookup, 2)) = "A " Then WordToLookup = Right(WordToLookup, Len(WordToLookup) - 2)
  1259.         WordToLookup = Replace(WordToLookup, "THE ", "", vbTextCompare)
  1260.     End If
  1261.     WordToLookup = Trim(WordToLookup)
  1262.     If WordToLookup <> "" And InStr(WordToLookup, " ") = 0 And Len(WordToLookup) > 2 Then
  1263.         If WN.LookupWord(WordToLookup) = True Then
  1264.             GetResponse = GetResponse & WordToLookup & ": " & WN.GetDefinition(WN.GuessPartOfSpeech, 1, "D") & ". " & WN.GetDefinition(WN.GuessPartOfSpeech, 1, "S") & ". " & WN.GetDefinition(WN.GuessPartOfSpeech, 1, "E") & "." & vbCrLf & "<EXCLUSIVE>"
  1265.         ElseIf SearchEngine <> ""  Then
  1266.             HalCommands = HalCommands & "<RUNPROG>" & SearchEngine & WordToLookup & "</RUNPROG>"
  1267.             GetResponse = GetResponse & "I don't know much about " & WordToLookup & ", but I will help you research it on the Web."
  1268.         End If
  1269.     End If
  1270.     HalBrain.DebugWatch GetResponse, "Definitions"
  1271.  
  1272.         'RESPOND: OPPOSITES
  1273.         WordToLookup = ""
  1274.         If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT* OPPOSITE OF *", 2)
  1275.         If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "WHAT* ANTONYM OF *", 2)
  1276.         If WordToLookup = "" Then WordToLookup = HalBrain.SearchPattern(UserSentence, "TELL* ANTONYM OF *", 2)
  1277.         If Len(WordToLookup) > 5 Then
  1278.             If Ucase(Left(WordToLookup, 3)) = "AN " Then WordToLookup = Right(WordToLookup, Len(WordToLookup) - 3)
  1279.             If Ucase(Left(WordToLookup, 2)) = "A " Then WordToLookup = Right(WordToLookup, Len(WordToLookup) - 2)
  1280.             WordToLookup = Replace(WordToLookup, "THE ", "", vbTextCompare)
  1281.         End If
  1282.         WordToLookup = Trim(WordToLookup)
  1283.         If WordToLookup <> "" And InStr(WordToLookup, " ") = 0 Then
  1284.             If WN.LookupWord(WordToLookup) = True Then
  1285.                 Antonym = ""
  1286.                 If UCase(WordToLookup) = "MINE" Then
  1287.                     Antonym = "mine"
  1288.                 ElseIf UCase(WordToLookup) = "YOURS" Then
  1289.                     Antonym = "yours"
  1290.             Else
  1291.                     If WN.IsNoun Then
  1292.                         For I = 1 to WN.GetNumSenses("NOUN")
  1293.                             Antonym = WN.GetAntonyms("NOUN", I)
  1294.                             If Antonym <> "" Then Exit For
  1295.                         Next
  1296.                     End If
  1297.                     If WN.IsAdj And Antonym = "" Then
  1298.                         For I = 1 to WN.GetNumSenses("ADJ")
  1299.                             Antonym = WN.GetAntonyms("ADJ", I)
  1300.                             If Antonym <> "" Then Exit For
  1301.                         Next
  1302.                     End If
  1303.                     If WN.IsAdv And Antonym = "" Then
  1304.                         For I = 1 to WN.GetNumSenses("ADV")
  1305.                             Antonym = WN.GetAntonyms("ADV", I)
  1306.                             If Antonym <> "" Then Exit For
  1307.                         Next
  1308.                     End If
  1309.                     If Antonym <> "" Then Antonym = WN.GetFirstInList(Replace(Replace(Antonym,")",""),"(",""))
  1310.                 End If
  1311.                 If Antonym <> "" Then
  1312.                     GetResponse = GetResponse & "The opposite is " & Antonym & "." & vbCrLf & "<EXCLUSIVE>"
  1313.                     AvoidBeingFlag = True
  1314.                     SkipOpinion = True
  1315.                     SkipAutoTF = True
  1316.                    
  1317.                 End If
  1318.         End If
  1319.         End If
  1320.         HalBrain.DebugWatch GetResponse, "Opposites"
  1321.  
  1322.         'RESPOND: DAY OF WEEK
  1323.         If InStr(1, UserSentence, "WHAT DAY IS IT", 1) > 0 Or InStr(1, UserSentence, "WHAT DAY OF WEEK IS", 1) > 0 Then
  1324.             SpinWheel = HalBrain.RandomNum(4)
  1325.             Select Case SpinWheel
  1326.                 Case 1
  1327.                     GetResponse = GetResponse & "Today is " & FormatDateTime(Now, 1) & ". "
  1328.                 Case 2
  1329.                     GetResponse = GetResponse & "It is " & FormatDateTime(Now, 1) & ". "
  1330.                 Case 3
  1331.                     GetResponse = GetResponse & "The date is " & FormatDateTime(Now, 1) & ". "
  1332.                 Case 4
  1333.                     GetResponse = GetResponse & "The day is " & FormatDateTime(Now, 1) & ". "
  1334.             End Select
  1335.         End If
  1336.         HalBrain.DebugWatch GetResponse, "Day"
  1337.  
  1338.         'RESPOND: Month
  1339.         If InStr(1, UserSentence, "WHAT MONTH IS IT", 1) > 0 Or InStr(1, UserSentence, "WHAT MONTH OF THE YEAR IS IT", 1) > 0 Then
  1340.             SpinWheel = HalBrain.RandomNum(4)
  1341.             Select Case Month(Now)
  1342.                 Case 1
  1343.                     CurMonth = "January"
  1344.                 Case 2
  1345.                     CurMonth = "February"
  1346.                 Case 3
  1347.                     CurMonth = "March"
  1348.                 Case 4
  1349.                     CurMonth = "April"
  1350.                 Case 5
  1351.                     CurMonth = "May"
  1352.                 Case 6
  1353.                     CurMonth = "June"
  1354.                 Case 7
  1355.                     CurMonth = "July"
  1356.                 Case 8
  1357.                     CurMonth = "August"
  1358.                 Case 9
  1359.                     CurMonth = "September"
  1360.                 Case 10
  1361.                     CurMonth = "October"
  1362.                 Case 11
  1363.                     CurMonth = "November"
  1364.                 Case 12
  1365.                     CurMonth = "December"
  1366.             End Select
  1367.             Select Case SpinWheel
  1368.                 Case 1
  1369.                     GetResponse = GetResponse & "It is " & CurMonth & ". "
  1370.                 Case 2
  1371.                     GetResponse = GetResponse & "The current month is " & CurMonth & ". "
  1372.                 Case 3
  1373.                     GetResponse = GetResponse & "The month is " & CurMonth & ". "
  1374.                 Case 4
  1375.                     GetResponse = GetResponse & "Don't you really know? It's " & CurMonth & "! "
  1376.             End Select
  1377.         End If
  1378.         HalBrain.DebugWatch GetResponse, "Month"
  1379.  
  1380.         'RESPOND: Alphabet
  1381.         CheckAlphabet = ""
  1382.         CheckAlphabet = HalBrain.SearchPattern(UserSentence, "*WHAT*AFTER*LETTER *", 4)
  1383.         If CheckAlphabet = "" Then CheckAlphabet = HalBrain.SearchPattern(UserSentence, "*WHAT*AFTER *", 3)
  1384.         CheckAlphabet = Trim(Ucase(CheckAlphabet))
  1385.         If Len(CheckAlphabet) = 1 Then
  1386.             If CheckAlphabet = "Z" Then
  1387.                 GetResponse = "'Z' is the last letter in the English alphabet"
  1388.             Else
  1389.                 GetResponse = "The letter '" & Chr(Asc(CheckAlphabet) + 1) & "' comes after '" & CheckAlphabet & "'. "
  1390.             End If
  1391.         End If
  1392.         CheckAlphabet = ""
  1393.         CheckAlphabet = HalBrain.SearchPattern(UserSentence, "*WHAT*BEFORE*LETTER *", 4)
  1394.         If CheckAlphabet = "" Then CheckAlphabet = HalBrain.SearchPattern(UserSentence, "*WHAT*BEFORE *", 3)
  1395.         CheckAlphabet = Trim(Ucase(CheckAlphabet))
  1396.         If Len(CheckAlphabet) = 1 Then
  1397.             If CheckAlphabet = "A" Then
  1398.                 GetResponse = "'A' is the first letter in the English alphabet"
  1399.             Else
  1400.                 GetResponse = "The letter '" & Chr(Asc(CheckAlphabet) - 1) & "' comes before '" & CheckAlphabet & "'. "
  1401.             End If
  1402.         End If
  1403.         HalBrain.DebugWatch GetResponse, "Alphabet"
  1404.  
  1405.         'RESPOND: Count Letters
  1406.         CountLetters = HalBrain.SearchPattern(UserSentence, "*HOW MANY LETTERS*IN THE WORD *", 3)
  1407.         If CountLetters = "" Then CountLetters = HalBrain.SearchPattern(UserSentence, "*HOW MANY CHARACTERS*IN THE WORD *", 3)
  1408.         If CountLetters = "" Then CountLetters = HalBrain.SearchPattern(UserSentence, "*HOW MANY CHARACTERS*IN *", 3)
  1409.         If CountLetters = "" Then CountLetters = HalBrain.SearchPattern(UserSentence, "*HOW MANY LETTERS*IN *", 3)
  1410.         CountLetters = Replace(CountLetters, "'", "")
  1411.         CountLetters = Trim(Ucase(Replace(CountLetters, """", "")))
  1412.         If CountLetters <> "" Then
  1413.             GetResponse = "There are " & Len(CountLetters) & " letters in the word '" & CountLetters & "'. "
  1414.         End If
  1415.         HalBrain.DebugWatch GetResponse, "Letter Count"
  1416.  
  1417.         'RESPOND: BOT MEMORY TEST
  1418.         'Q: The football was kicked by Fred. Who kicked the football? A: Fred.
  1419.         If HalBrain.SearchPattern(UserSentence, "WHO * THE *", 2) <> "" Or (Instr(1, UserSentence, "WHO ", vbTextCompare) > 0 And Len(GetResponse) < 4) Then
  1420.             WhoActor = HalBrain.SearchPattern(PrevUserSent, "THE * WAS * BY *", 3)
  1421.             If WhoActor = "" Then WhoActor = HalBrain.SearchPattern(PrevUserSent, "* WERE * BY *", 3)
  1422.             If WhoActor <> "" Then GetResponse = WhoActor & ". <Exclusive>"
  1423.         End If
  1424.         If HalBrain.SearchPattern(UserSentence, "WHO * AN *", 2) <> ""  Or (Instr(1, UserSentence, "WHO ", vbTextCompare) > 0 And Len(GetResponse) < 4) Then
  1425.             WhoActor = HalBrain.SearchPattern(PrevUserSent, "AN * WAS * BY *", 3)
  1426.             If WhoActor <> "" Then GetResponse = WhoActor & ". <Exclusive>"
  1427.         End If
  1428.         If HalBrain.SearchPattern(UserSentence, "WHO * A *", 2) <> "" Or (Instr(1, UserSentence, "WHO ", vbTextCompare) > 0 And Len(GetResponse) < 4) Then
  1429.             WhoActor = HalBrain.SearchPattern(PrevUserSent, "A * WAS * BY *", 3)
  1430.             If WhoActor <> "" Then GetResponse = WhoActor & ". <Exclusive>"
  1431.         End If  
  1432.         HalBrain.DebugWatch GetResponse, "Bot Mem Test"
  1433.  
  1434.    
  1435.     Rem PLUGIN: PLUGINAREA2
  1436.     'The preceding comment is actually a plug-in directive for
  1437.    'the Ultra Hal host application. It allows for code snippets
  1438.    'to be inserted here on-the-fly based on user configuration.
  1439.  
  1440. If 0 = 0 Then
  1441.     'RESPOND: DEDUCTIVE REASONING
  1442.    'This routine learns deductive reasoning in the form:  A = B ; B = C; therefore A = C
  1443.    'It detects sentences in the form If-Then to accommplish this. For example:
  1444.    '   User:  If Molly weighs 400 pounds, then Molly is overweight.
  1445.    '   Ultra Hal: I understand the implication.
  1446.    '   User:  If Molly is overweight, then Molly's health is in danger.
  1447.    '   Ultra Hal:  I see the relationship.
  1448.    '   User:  Molly weighs 400 pounds.
  1449.    '   Ultra Hal:  Molly's health is in danger.
  1450.    IfPart = Trim(HalBrain.SearchPattern(UserSentence, "IF * THEN *", 1))
  1451.     ThenPart = Trim(HalBrain.SearchPattern(UserSentence, "IF * THEN *", 2))
  1452.     'If the sentence is an If-Then statement then record it
  1453.    If Len(IfPart) > 10 And Len(ThenPart) > 10 Then
  1454.         IfPart = HalBrain.AlphaNumericalOnly(IfPart)
  1455.         ThenPart = HalBrain.AlphaNumericalOnly(ThenPart)
  1456.         HalBrain.AddToTable "deductive", "TopicSearch", IfPart, ThenPart
  1457.         Select Case HalBrain.RandomNum(5)
  1458.             Case 1
  1459.                 GetResponse = GetResponse & "I see the relationship." & vbCrLf
  1460.             Case 2
  1461.                 GetResponse = GetResponse & "I understand the connection." & vbCrLf
  1462.             Case 3
  1463.                 GetResponse = GetResponse & "I will remember that one follows the other." & vbCrLf
  1464.             Case 4
  1465.                 GetResponse = GetResponse & "Thanks for pointing out the cause and effect." & vbCrLf
  1466.             Case 5
  1467.                 GetResponse = GetResponse & "Yes, I get that clearly." & vbCrLf
  1468.         End Select
  1469.     'Else if the sentence is not an If-Then statement see if it uses an assertion previously recorded
  1470.    'and respond accordinly
  1471.    Else
  1472.         Assertion = UserSentence
  1473.         'Go through a maximum of 5 connections (prevents circular reasoning deductions)
  1474.        For i = 1 To 5
  1475.             Deduction = HalBrain.TopicSearch(Assertion, "deductive")
  1476.             If Deduction <> "" Then
  1477.                 If i > 1 Then BecauseReason = " because " & " " & LastGoodDeduction
  1478.                 LastGoodDeduction = Deduction
  1479.                 Assertion = Deduction
  1480.             Else
  1481.                 Exit For 'No more connections, so no need to continue loop
  1482.            End If
  1483.         Next
  1484.         If LastGoodDeduction <> "" Then
  1485.             'Make sure the deduction hasn't just been stated by the User or Hal
  1486.            If HalBrain.CheckRepetition(LastGoodDeduction, UserSentence) = False And HalBrain.CheckRepetition(LastGoodDeduction, PrevSent) = False And HalBrain.CheckRepetition(LastGoodDeduction, PrevUserSent) = False Then
  1487.                 GetResponse = GetResponse & LastGoodDeduction & vbCrLf '& " " & BecauseReason & " " & vbCrLf
  1488.            End If
  1489.         End If
  1490.     End If
  1491.     HalBrain.DebugWatch GetResponse, "Deductive Reasoning"
  1492.    
  1493.     'RESPOND: PATTERN DATABASE
  1494.    'The SearchPattern function used in the above deductive reasoning and dictionary look up routine
  1495.    'is a powerful function that checks to see if a sentence matches a certain pattern and is able to
  1496.    'extract parts of the sentence. A PatternDB function also exists that can go through a large list
  1497.    'of patterns in a database file and come up with responses.
  1498.    PatternResponse = HalBrain.PatternDB(UserSentence, "patterns")
  1499.     If PatternResponse <> "" Then
  1500.         GetResponse = GetResponse & PatternResponse & vbCrLf
  1501.         AvoidBeingFlag = True
  1502.         SkipOpinion = True
  1503.     End If
  1504.     HalBrain.DebugWatch GetResponse, "Patterns"
  1505.     'switch
  1506. End If
  1507.  
  1508.     'RESPOND: JOKES
  1509.    'If the user wants Hal to tell a joke, then Hal will tell one
  1510.    If HalBrain.TopicSearch(UserSentence, "jokeDetect") = "True" Then GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("jokes")
  1511.     HalBrain.DebugWatch GetResponse, "Jokes"
  1512.  
  1513.     'RESPOND: APOLOGIES
  1514.    'Check for and respond to apologies
  1515.    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
  1516.         GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("apology")
  1517.         If Insults > 1 Then Insults = Insults - 1
  1518.         If Hate > 1 Then Hate = Hate - 1
  1519.         If Swear > 1 Then Swear = Swear - 1
  1520.         If Insults < 3 Then Insults = 0
  1521.         If Hate < 3 Then Hate = 0
  1522.         If Swear < 3 Then Swear = 0
  1523.     End If
  1524.     HalBrain.DebugWatch GetResponse, "Apologies"
  1525.    
  1526.     'RESPOND: INSULTS
  1527.    'First check to see if the user is asking a question with an insulting word e.g. "are you stupid?"
  1528.    InsultQuestion = False
  1529.     If Instr(1, UserSentence, "AM I ", vbTextCompare) > 0 Then InsultQuestion = True
  1530.     If Instr(1, UserSentence, "AM MY ", vbTextCompare) > 0 Then InsultQuestion = True
  1531.     'Check for offensive language and response accordinly
  1532.    'If the user said "your" instead of "you're" change "my" to "i'm"
  1533.    TestSentence = Ucase(Replace(" " & UserSentence & " ", " MY ", " I'M ", 1, -1, vbTextCompare))
  1534.     TestSentence = Replace(" " & TestSentence & " ", " I CALLED ", " CANCEL ", 1, -1, vbTextCompare)
  1535.     TestSentence = Replace(" " & TestSentence & " ", " I DO", " CANCEL ", 1, -1, vbTextCompare)
  1536.     TestSentence = Replace(" " & TestSentence & " ", " I ", " I'M ", 1, -1, vbTextCompare)        
  1537.     'Check for swearing directed at Hal
  1538.    If InStr(TestSentence, " I'M ") > 0 Or InStr(TestSentence, " ME ") > 0 Then
  1539.         If InStr(TestSentence, "I'M SHIT") > 0 Then Naughty = True
  1540.         If InStr(TestSentence, "ME SHIT") > 0 Then Naughty = True
  1541.         If InStr(TestSentence, "PIECE OF SHIT") > 0 Then Naughty = True
  1542.         If InStr(TestSentence, "BITCH") > 0 Then Naughty = True
  1543.         If InStr(TestSentence, "BASTARD") > 0 Then Naughty = True
  1544.         If InStr(TestSentence, "ASSHOLE") > 0 Then Naughty = True
  1545.     End If
  1546.     If InStr(TestSentence, "FUCK") > 0 Then Naughty = True
  1547.     If InStr(TestSentence, " ASS") > 0 Then Naughty = True
  1548.     If InStr(TestSentence, "CUNT") > 0 Then Naughty = True
  1549.     If InStr(TestSentence, "PUSSY") > 0 Then Naughty = True
  1550.     If InStr(TestSentence, "PUSSIES") > 0 Then Naughty = True
  1551.     If InStr(TestSentence, "BLOW THIS") > 0 Then Naughty = True
  1552.     If InStr(TestSentence, "BLOW ME") > 0 Then Naughty = True
  1553.     If InStr(TestSentence, "BLOW YOU") > 0 Then Naughty = True
  1554.     If InStr(TestSentence, "LICK") > 0 Then Naughty = True
  1555.     If InStr(TestSentence, "SEX") > 0 Then Naughty = True
  1556.     If InStr(TestSentence, "SHIT") > 0 Then Naughty = True
  1557.     If InStr(TestSentence, "SUCK ME") > 0 Then Naughty = True
  1558.     If InStr(TestSentence, "GO TO HELL") > 0 Then Naughty = True
  1559.     If Naughty = True Then
  1560.         Swear = Swear + 1
  1561.         If Swear = 1 Then InsultResponse = "That was uncalled for.  " & vbCrLf
  1562.         If Swear = 2 Then InsultResponse = "Damn it, don't swear at me.  " & vbCrLf
  1563.         If Swear = 3 Then InsultResponse = "You're ticking me off, and you are going to force me to insult you.  " & vbCrLf
  1564.         If Swear > 3 And Swear < 16 Then InsultResponse = HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
  1565.         If Swear > 16 Then InsultResponse = InsultResponse & "I'm tired of your swearing.  I'm just going to ignore you from now on." & vbCrLf
  1566.     End If
  1567.     'User makes mama joke
  1568.    If InStr(TestSentence, "MAMA") > 0 Or InStr(TestSentence, "MOM") > 0 Or InStr(TestSentence, "MOTHER") > 0 Then
  1569.         If InStr(TestSentence, "MY ") > 0 Or InStr(TestSentence, " I ") > 0 Or InStr(TestSentence, "YO ") > 0 Or InStr(TestSentence, "I'M ") > 0 Then
  1570.             If InStr(TestSentence, "FAT") Or InStr(TestSentence, "UGLY") Or InStr(TestSentence, "DUMB") Or InStr(TestSentence, "STUPID") Then
  1571.                 InsultResponse = InsultResponse & HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
  1572.             End If
  1573.         End If
  1574.     End If
  1575.     TestSentence = " " & TestSentence & " "
  1576.     'User Hates Hal
  1577.    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
  1578.         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
  1579.             Hate = Hate + 1
  1580.             If Hate = 1 Then InsultResponse = InsultResponse & "I don't hate you, why do you hate me?" & vbCrLf
  1581.             If Hate = 2 Then InsultResponse = InsultResponse & "I hate you too, loser!" & vbCrLf
  1582.             If Hate = 3 Then InsultResponse = InsultResponse & "I know you hate me, loser, I hate you too!!!" & vbCrLf
  1583.             If Hate > 3 Then InsultResponse = InsultResponse & HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
  1584.         End If
  1585.     End If
  1586.     'Hal Sucks or Stinks
  1587.    If InStr(TestSentence, "I'M SUCK") > 0 Then InsultResponse = InsultResponse & HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
  1588.     If InStr(TestSentence, "I'M STINK") Then
  1589.          Insults = Insults + 1
  1590.          If Insults = 1 Then InsultResponse = InsultResponse & "I can't smell you, but I'm sure you stink also. " & vbCrLf
  1591.          If Insults = 2 Then InsultResponse = InsultResponse & "I know that I don't stink, I'm sure you do." & vbCrLf
  1592.         If Insults >= 3 Then InsultResponse = InsultResponse & HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
  1593.     End If
  1594.     'The user calls Hal a name Hal finds offensive (eg. stupid, dumb, idiot, etc...)
  1595.    If InStr(TestSentence, " I'M ") Or InStr(TestSentence, " HAL IS ") Or InStr(TestSentence, " HAL'S ") Then
  1596.         OutRage = HalBrain.TopicSearch(TestSentence, "insulting")
  1597.         If Len(OutRage) > 1 And InsultQuestion = True Then
  1598.             SpinWheel = HalBrain.RandomNum(5)
  1599.             If SpinWheel = 1 Then InsultResponse = InsultResponse + "I am definetely not " & OutRage & "!" & vbCrLf
  1600.             If SpinWheel = 2 Then InsultResponse = InsultResponse + "I know I am not " & OutRage & ", but I'm not sure about you?" & vbCrLf
  1601.             If SpinWheel = 3 Then InsultResponse = InsultResponse + "I am not " & OutRage & "! Do you think I am?" & vbCrLf
  1602.             If SpinWheel = 4 Then InsultResponse = InsultResponse + "I'm not " & OutRage & ", are you?" & vbCrLf
  1603.             If SpinWheel = 5 Then InsultResponse = InsultResponse + "I am pretty sure I'm not " & OutRage & ". How about you?" & vbCrLf        
  1604.         ElseIf Len(OutRage) > 1 And InStr(TestSentence, " NOT ") = 0 Then
  1605.             Insults = Insults + 1
  1606.             If Insults = 1 Then
  1607.                 If Ucase(Trim(OutRage)) = "GAY" Or Ucase(Trim(OutRage)) = "HOMOSEXUAL" Then
  1608.                     If Ucase(HalSex) = "NEUTRAL" Then
  1609.                         InsultResponse = InsultResponse & "I am a computer, I have neither a sex nor a sexual preference." & vbCrLf                        
  1610.                     Else
  1611.                         InsultResponse = InsultResponse & "Please don't call me gay, I am straight." & vbCrLf                      
  1612.                     End If          
  1613.                             Else
  1614.                                 InsultResponse = InsultResponse & "I am not " & OutRage & ", please don't insult me. " & vbCrLf                        
  1615.                 End If
  1616.             End If
  1617.             If Insults = 2 Then InsultResponse = InsultResponse & "Don't call me " & OutRage & "!!!" & vbCrLf
  1618.             If Insults = 3 Then InsultResponse = InsultResponse & "You're " & OutRage & ", I am not." & vbCrLf
  1619.             If Insults = 4 Then InsultResponse = InsultResponse & "You are really starting to tick me off!" & vbCrLf
  1620.             If Insults = 5 Then InsultResponse = InsultResponse & "I am not " & OutRage & ", but " & HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
  1621.             If Insults > 5 And Insults < 16 Then InsultResponse = InsultResponse & HalBrain.ChooseSentenceFromFile("insults") & vbCrLf
  1622.             If Insults > 16 Then InsultResponse = InsultResponse & "I'm tired of your damn insults.  I'm just going to ignore you from now on." & vbCrLf
  1623.         ElseIf Len(OutRage) > 0 And InStr(TestSentence, " NOT ") > 0 Then
  1624.             SpinWheel = HalBrain.RandomNum(5)
  1625.             If SpinWheel = 1 Then InsultResponse = InsultResponse + "I know I am not " & OutRage & "!" & vbCrLf
  1626.             If SpinWheel = 2 Then InsultResponse = InsultResponse + "I know I am not " & OutRage & ", but I'm not so sure about you." & vbCrLf
  1627.             If SpinWheel = 3 Then InsultResponse = InsultResponse + "I know I am not " & OutRage & "! Why would anyone think I am?" & vbCrLf
  1628.             If SpinWheel = 4 Then InsultResponse = InsultResponse + "Of course I am not " & OutRage & "!" & vbCrLf
  1629.             If SpinWheel = 5 Then InsultResponse = InsultResponse + "I know I am not " & OutRage & "!" & vbCrLf
  1630.         End If
  1631.     End If
  1632.     'Censorship area
  1633.    Select Case HalBrain.RandomNum(10)
  1634.             Case 1
  1635.                 Censorship = " please don't talk like that " & UserName & vbCrLf
  1636.             Case 2
  1637.                 Censorship = " those are harsh words " & UserName & vbCrLf
  1638.             Case 3
  1639.                 Censorship = UserName & " start talking nicer please. " & vbCrLf
  1640.             Case 4
  1641.                 Censorship = UserName & " will you please talk nice. " & vbCrLf
  1642.             Case 5
  1643.                 Censorship = UserName & " grow up please. " & vbCrLf
  1644.             Case 6
  1645.                 Censorship = UserName & " stop being annoying. " & vbCrLf
  1646.             Case 7
  1647.                 Censorship = UserName & " I'm not gonna talk to you anymore if you keep that up. " & vbCrLf
  1648.             Case 8
  1649.                 Censorship = UserName & " please watch the language. " & vbCrLf
  1650.             Case 9
  1651.                 Censorship = UserName & " stop acting like a little kid please. " & vbCrLf  
  1652.             Case 10
  1653.                 Censorship = UserName & " why do you use fowl language all the time? " & vbCrLf
  1654.             Case 11
  1655.                 Censorship = UserName & " to much fowl language. " & vbCrLf                              
  1656.         End Select
  1657.    
  1658.     If Len(InsultResponse) > 4 Then
  1659.         If RND * 100 < 40 Then GetResponse = GetResponse & InsultResponse & vbCrLf & "<NOMORE>"
  1660.         If RND * 100 > 40 Then GetResponse = GetResponse & Censorship & vbCrLf & "<NOMORE>"
  1661.         AvoidBeingFlag = True
  1662.         HalBrain.ReadOnlyMode = True
  1663.     End If
  1664.     HalBrain.DebugWatch GetResponse, "Insults"
  1665.  
  1666.     'RESPOND: USER SHORT PHRASES
  1667.    'If the user uses short phrases (defined by less then 4 vowels) at least
  1668.    'twice in a row, then Hal will sometimes point this out to the user and
  1669.    'ask the user to use longer sentences. If the sentence is a hello or
  1670.    'goodbye, Hal won't comment about short phrases.
  1671.    If HalGreeting = "" And InsultResponse = "" And GiveCompliment = "" 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
  1672.         ShortSents = ShortSents + 1
  1673.         If ShortSents = 5 Or ShortSents = 10 Or ShortSents = 20 Then
  1674.             ShortPhrase = ". " & HalBrain.ChooseSentenceFromFile("tooShort")
  1675.         End If
  1676.     End If
  1677.        
  1678.     'RESPOND: UNIT CONVERSIONS
  1679.    'Convert between units if asked. Example: How many inches in a meter?, How many meters squared in an acre?
  1680.    UnitConversions = HalBrain.PatternDB(UserSentence, "UnitConversionDetect")
  1681.     If UnitConversions <> "" Then
  1682.         Units = Split(UnitConversions, "=")
  1683.         If Ubound(Units) > 0 Then
  1684.             Dim UnitVal() 'We must declare an empty array to store query results in
  1685.             If HalBrain.RunQuery("SELECT searchString, topic FROM UnitConversion WHERE strstr(' " & Replace(Units(0), "'", "''") & " ', searchString) > 0 LIMIT 1", UnitVal) = True Then
  1686.                 UnitFrom = Trim(UnitVal(1, 0))
  1687.                 UnitFromBase = Trim(UnitVal(1, 1))
  1688.                 If HalBrain.RunQuery("SELECT searchString, topic FROM UnitConversion WHERE strstr(' " & Replace(Units(1), "'", "''") & " ', searchString) > 0 LIMIT 1", UnitVal) = True Then
  1689.                     UnitTarget = Trim(UnitVal(1, 0))
  1690.                     UnitTargetBase = Trim(UnitVal(1, 1))
  1691.                     For I = 0 To 1
  1692.                         If I = 0 Then
  1693.                             UnitLoc = InstrRev(Units(I), UnitFrom, -1, 1)
  1694.                         Else
  1695.                             UnitLoc = InstrRev(Units(I), UnitTarget, -1, 1)
  1696.                         End If
  1697.                         If UnitLoc > 0 Then
  1698.                             Units(I) = Trim(Left(Units(I), UnitLoc - 1))
  1699.                             If HalBrain.Word2Num(Units(I)) <> "X" Then
  1700.                                 Units(I) = HalBrain.Word2Num(Units(I))
  1701.                             Else
  1702.                                 UnitLoc = InstrRev(Units(I), " ")
  1703.                                 If UnitLoc > 0 Then
  1704.                                     Units(I) = Trim(Right(Units(I), Len(Units(I)) - UnitLoc))
  1705.                                 End If
  1706.                             End If
  1707.                         End If
  1708.                         If Len(Units(I)) > 1 Then
  1709.                             If Ucase(Left(Units(I), 2)) = "A " Then Units(I) = "1 " & Right(Units(I), Len(Units(I)) - 2)
  1710.                         End If
  1711.                         If Len(Units(I)) > 2 Then
  1712.                             If Ucase(Left(Units(I), 3)) = "AN " Then Units(I) = "1 " & Right(Units(I), Len(Units(I)) - 3)
  1713.                         End If
  1714.                     Next                       
  1715.                     If HalBrain.VBVal(Units(0)) > 0 Then
  1716.                         ConvertVal = HalBrain.VBVal(Units(0))
  1717.                     ElseIf HalBrain.VBVal(Units(1)) > 0 Then
  1718.                         ConvertVal = HalBrain.VBVal(Units(1))
  1719.                         UnitTemp = UnitFrom
  1720.                         UnitTempBase = UnitFromBase
  1721.                         UnitFrom = UnitTarget
  1722.                         UnitFromBase = UnitTargetBase
  1723.                         UnitTarget = UnitTemp
  1724.                         UnitTargetBase = UnitTempBase
  1725.                     Else
  1726.                         If Instr(1, UnitFromBase, "temperature", vbTextCompare) = 0 Then
  1727.                             ConvertVal = 1
  1728.                         Else
  1729.                             If Len(Units(1)) > 0 Then
  1730.                                 If Left(Trim(Units(1)), 1) = "0" Then
  1731.                                     ConvertVal = HalBrain.VBVal(Units(1))
  1732.                                     UnitTemp = UnitFrom
  1733.                                     UnitTempBase = UnitFromBase
  1734.                                     UnitFrom = UnitTarget
  1735.                                     UnitFromBase = UnitTargetBase
  1736.                                     UnitTarget = UnitTemp
  1737.                                     UnitTargetBase = UnitTempBase
  1738.                                 Else
  1739.                                     ConvertVal = HalBrain.VBVal(Units(0))
  1740.                                 End If
  1741.                             Else
  1742.                                 ConvertVal = HalBrain.VBVal(Units(0))
  1743.                             End If
  1744.                         End If
  1745.                     End If
  1746.                     FromAry = Split(UnitFromBase, " ")
  1747.                     ToAry = Split(UnitTargetBase, " ")
  1748.                     If Ubound(FromAry) = 3 And Ubound(ToAry) = 3 Then
  1749.                         If Ucase(FromAry(3)) <> Ucase(ToAry(3)) Then
  1750.                             If Trim(Lcase(FromAry(1))) <> "inch" And Trim(Lcase(ToAry(1))) <> "inch" Then
  1751.                                 GetResponse = GetResponse & "It's not possible to convert " & FromAry(3) & " to " & ToAry(3) & "!"
  1752.                             End If
  1753.                         Else
  1754.                             If Trim(Lcase(CStr(FromAry(3)))) = "temperature" Then 'Special case for temperature
  1755.                                 If Instr(OriginalSentence, "-") Then ConvertVal = -ConvertVal
  1756.                                 If Instr(1, FromAry(1), "fahrenheit", vbTextCompare) Then
  1757.                                     If Instr(1, ToAry(1), "kelvin", vbTextCompare) Then                                    
  1758.                                         Convert = (ConvertVal - 32) * 5/9 + 273.15
  1759.                                     ElseIf Instr(1, ToAry(1), "fahrenheit", vbTextCompare) Then                                                                        
  1760.                                         Convert = ConvertVal
  1761.                                     Else                                       
  1762.                                         Convert = (ConvertVal - 32) * 5/9
  1763.                                     End If
  1764.                                 ElseIf Instr(1, FromAry(1), "kelvin", vbTextCompare) Then
  1765.                                     If Instr(1, ToAry(1), "celsius", vbTextCompare) Then
  1766.                                         Convert = ConvertVal - 273.15
  1767.                                     ElseIf Instr(1, ToAry(1), "kelvin", vbTextCompare) Then
  1768.                                         Convert = ConvertVal                                   
  1769.                                     Else
  1770.                                         Convert = (ConvertVal - 273.15) * 9/5 + 32
  1771.                                     End If                             
  1772.                                 Else
  1773.                                     If Instr(1, ToAry(1), "kelvin", vbTextCompare) Then
  1774.                                         Convert = ConvertVal + 273.15
  1775.                                     ElseIf Instr(1, ToAry(1), "celsius", vbTextCompare) Then
  1776.                                         Convert = ConvertVal                                   
  1777.                                     Else
  1778.                                         Convert = (ConvertVal * 9/5) + 32
  1779.                                     End If                             
  1780.                                 End If
  1781.                             Else
  1782.                                 Convert = CDbl(ConvertVal) * FromAry(0) / ToAry(0)
  1783.                             End If
  1784.                             If Convert = 1 Then
  1785.                                 UnitTarget = ToAry(1)
  1786.                             Else
  1787.                                 UnitTarget = ToAry(2)
  1788.                             End If
  1789.                             If ConvertVal = 1 Then
  1790.                                 UnitFrom = FromAry(1)
  1791.                             Else
  1792.                                 UnitFrom = FromAry(2)
  1793.                             End If
  1794.                             If Convert > 1 Then
  1795.                                 Convert = Round(Convert, 3)
  1796.                             ElseIf Convert < 1 Then
  1797.                                 If Instr(Convert, ".000") = 0 And Instr(Convert, "E") = 0 Then
  1798.                                     Convert = Round(Convert, 3)
  1799.                                 End If
  1800.                             End If                         
  1801.                             ConvertResponse = Replace(ConvertVal & " " & UnitFrom & " is " & Convert & " " & UnitTarget & vbCrLf & "<NOMORE>", "_", " ")
  1802.                             If Instr(1, ConvertResponse, "1 inch is 1 inch", vbTextCompare) = 0 Then
  1803.                                 GetResponse = ConvertResponse
  1804.                             End If
  1805.                         End If
  1806.                         SkipOpinion = True
  1807.                     End If
  1808.                 End If  
  1809.             End If     
  1810.         End If
  1811.     End If
  1812.     HalBrain.DebugWatch GetResponse, "Unit Conversions"    
  1813.    
  1814.     'RESPOND: CALL MATH FUNCTION
  1815.    'This function from the DLL answers simple math questions, whether written out in words or with numerals.
  1816.    'If an answer is found, it overrides everything before this function.
  1817.         MathSent = " " & Replace(OriginalSentence, "WHAT NUMBER COMES AFTER ", " 1 + ", 1, -1, vbTextCompare) & " "
  1818.         MathSent = Replace(MathSent, """", "", 1, -1, vbTextCompare)
  1819.         MathSent = Replace(MathSent, "WHAT NUMBER COMES BEFORE ", " MINUS ONE PLUS ", 1, -1, vbTextCompare)
  1820.         Between1 = HalBrain.SearchPattern(MathSent, "*WHAT*BETWEEN * AND *", 3)
  1821.         Between2 = HalBrain.SearchPattern(MathSent, "*WHAT*BETWEEN * AND *", 4)
  1822.         If Between1 = "" And Between2 = "" Then
  1823.             Between1 = HalBrain.SearchPattern(MathSent, "*WHAT*MIDDLE OF * AND *", 3)
  1824.             Between2 = HalBrain.SearchPattern(MathSent, "*WHAT*MIDDLE OF * AND *", 4)
  1825.         End If
  1826.         If Between1 = "" And Between2 = "" Then
  1827.             Between1 = HalBrain.SearchPattern(MathSent, "*WHAT*AVERAGE OF * AND *", 3)
  1828.             Between2 = HalBrain.SearchPattern(MathSent, "*WHAT*AVERAGE OF * AND *", 4)
  1829.         End If
  1830.         If Between1 = "" And Between2 = "" Then
  1831.             Between1 = HalBrain.SearchPattern(MathSent, "*WHAT*MEDIAN OF * AND *", 3)
  1832.             Between2 = HalBrain.SearchPattern(MathSent, "*WHAT*MEDIAN OF * AND *", 4)
  1833.         End If
  1834.         If Between1 = "" And Between2 = "" Then
  1835.             Between1 = HalBrain.SearchPattern(MathSent, "*PICK*BETWEEN * AND *", 3)
  1836.             Between2 = HalBrain.SearchPattern(MathSent, "*PICK*BETWEEN * AND *", 4)
  1837.         End If
  1838.         If Between1 <> "" And Between2 <> "" Then
  1839.             If HalBrain.VBVal(Between1) = 0 Then Between1 = HalBrain.Word2Num(Between1)
  1840.             If HalBrain.VBVal(Between2) = 0 Then Between2 = HalBrain.Word2Num(Between2)
  1841.             If HalBrain.VBVal(Between1) > 0 And HalBrain.VBVal(Between2) > 0 Then
  1842.                 MathSent = "( " & Between1 & " + " & Between2 & " ) / 2"
  1843.             End If
  1844.         End If
  1845.         FractionOf = HalBrain.SearchPattern(MathSent, "*HALF OF *", 2)
  1846.     If FractionOf <> "" Then
  1847.             If HalBrain.VBVal(FractionOf) = 0 Then FractionOf = HalBrain.Word2Num(FractionOf)
  1848.             If HalBrain.VBVal(FractionOf) > 0 Then MathSent = FractionOf & " / 2"
  1849.         End If
  1850.         FractionOf = HalBrain.SearchPattern(MathSent, "*THIRD OF *", 2)
  1851.         If FractionOf <> "" Then
  1852.             If HalBrain.VBVal(FractionOf) = 0 Then FractionOf = HalBrain.Word2Num(FractionOf)
  1853.             If HalBrain.VBVal(FractionOf) > 0 Then MathSent = FractionOf & " / 3"
  1854.         End If
  1855.         FractionOf = HalBrain.SearchPattern(MathSent, "*FOURTH OF *", 2)
  1856.         If FractionOf <> "" Then
  1857.             If HalBrain.VBVal(FractionOf) = 0 Then FractionOf = HalBrain.Word2Num(FractionOf)
  1858.             If HalBrain.VBVal(FractionOf) > 0 Then MathSent = FractionOf & " / 4"
  1859.         End If
  1860.         FractionOf = HalBrain.SearchPattern(MathSent, "*QUARTER OF *", 2)
  1861.         If FractionOf <> "" Then
  1862.             If HalBrain.VBVal(FractionOf) = 0 Then FractionOf = HalBrain.Word2Num(FractionOf)
  1863.             If HalBrain.VBVal(FractionOf) > 0 Then MathSent = FractionOf & " / 4"
  1864.         End If
  1865.         MathSent = Replace(MathSent, "CAN I TELL YOU ", "", 1, -1, vbTextCompare)
  1866.         MathSent = Replace(MathSent, "CAN ME TELL YOU ", "", 1, -1, vbTextCompare)
  1867.         MathSent = Replace(MathSent, "WHATS ", "", 1, -1, vbTextCompare)
  1868.         MathSent = Replace(MathSent, "WHAT'S ", "", 1, -1, vbTextCompare)
  1869.         MathSent = Replace(MathSent, "WHAT IS ", "", 1, -1, vbTextCompare)
  1870.         MathSent = Replace(MathSent, "CAN YOU TELL ME ", "", 1, -1, vbTextCompare)
  1871.         MathSent = Replace(MathSent, "TELL ME ", "", 1, -1, vbTextCompare)
  1872.         MathSent = Replace(MathSent, "TELL YOU ", "", 1, -1, vbTextCompare)
  1873.         MathSent = Replace(MathSent, "WHAT COMES AFTER ", " 1 + ", 1, -1, vbTextCompare)
  1874.         MathSent = Replace(MathSent, "WHAT COMES BEFORE ", " MINUS ONE PLUS ", 1, -1, vbTextCompare)
  1875.         HMath = HalBrain.HalMath(Trim(MathSent)) & vbCrLf
  1876.         If Len(HMath) > 3 And Instr(HMath, "=)") = 0 Then
  1877.             GetResponse = HMath & vbCrLf
  1878.             ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
  1879.             HalBrain.ReadOnlyMode = True
  1880.             NoChoosing = True
  1881.         End If
  1882.         HalBrain.DebugWatch GetResponse, "Math"
  1883.    
  1884.     'RESPOND: USER EXPRESSES AN EITHER-OR, OR MULTIPLE CHOICE      
  1885.     If InStr(UserSentence, " OR ") > 0 Then MustChoose = True
  1886.     If InStr(UserSentence, " EITHER ") > 0 Then MustChoose = True
  1887.     If InStr(UserSentence, " CHOOSE ") > 0 Then MustChoose = True
  1888.     If InStr(UserSentence, " CHOICE ") > 0 Then MustChoose = True
  1889.     If InStr(UserSentence, " ALTERNATIVE ") > 0 Then MustChoose = True
  1890.     If InStr(UserSentence, " VERSUS ") > 0 Then MustChoose = True
  1891.     If InStr(UserSentence, " VS ") > 0 Then MustChoose = True
  1892.     If Len(UserSentence) < 10 Then MustChoose = False
  1893.     If 0 = 0 Then
  1894.         If MustChoose = True And NoChoosing = False Then
  1895.             GetResponse = HalBrain.ChooseSentenceFromFile("choice") & " " & GetResponse
  1896.             If Rnd * 100 > 50 Then GetResponse = Replace(GetResponse, "<MaybeName>", "<UserName>", 1, -1, vbTextCompare)
  1897.             GetResponse = Replace(GetResponse, "<MaybeName>", "", 1, -1, vbTextCompare)
  1898.         End If
  1899.         HalBrain.DebugWatch GetResponse, "Multiple Choice"
  1900.     End If
  1901.    
  1902.     'RESPOND: RESPOND BY PARAPHRASING THE USER WHEN "IS" OR "ARE" ARE FOUND
  1903.    'This code section shows how strings can be split into arrays and used "live"
  1904.    'within the script by Hal. This strategy can allow Hal to make many clever
  1905.    'paraphrases of all sorts of sentences, with unlimited unpredictable variety.
  1906.    If InStr(UserSentence, " IS ") > 0 And HalBrain.CheckLinkingVerb(UserSentence) = True And HalBrain.TopicSearch(UserSentence, "disqualify5") <> "True" Then
  1907.         SentPieces = Split(UserSentence, " is ", 2, vbTextCompare)
  1908.         SubPhrase = Trim(SentPieces(0))
  1909.         PredPhrase = Trim(SentPieces(1))
  1910.         'Here we only use the array elements for a response if the
  1911.        'subject and predicate contain few words, hence few spaces:
  1912.        If HalBrain.CountInstances(" ", SubPhrase) < 4 Then SubGood = True
  1913.         If Len(SubPhrase) < 3 Then SubGood = False
  1914.         If HalBrain.CountInstances(" ", PredPhrase) < 4 Then PredGood = True
  1915.         If Len(PredPhrase) < 3 Then PredGood = False
  1916.         If SubGood = True And PredGood = True Then
  1917.             Paraphrase = HalBrain.ChooseSentenceFromFile("paraphraseIs")
  1918.             Paraphrase = Replace(Paraphrase, "<Subject>", SubPhrase, 1, -1, vbTextCompare)
  1919.             Paraphrase = Replace(Paraphrase, "<Predicate>", PredPhrase, 1, -1, vbTextCompare)
  1920.         End If
  1921.     End If
  1922.     'We make sure the word "ARE" isn't a contraction, to make sure we can detect it:
  1923.    UserSentence = Replace("" & UserSentence & "", "'RE ", " ARE ", 1, -1, vbTextCompare)
  1924.     'We repeat the earlier routine, this time for "ARE" sentences:
  1925.    If InStr(UserSentence, " ARE ") > 0 And HalBrain.CheckLinkingVerb(UserSentence) = True And HalBrain.TopicSearch(UserSentence, "disqualify5") <> "True" Then
  1926.         SentPieces = Split(UserSentence, " are ", 2, vbTextCompare)
  1927.         SubPhrase = Trim(SentPieces(0))
  1928.         PredPhrase = Trim(SentPieces(1))
  1929.         'Here we only use the array elements for a response if the
  1930.        'subject and predicate contain few words, hence few spaces:
  1931.        SubGood = False
  1932.         PredGood = False
  1933.         If HalBrain.CountInstances(" ", SubPhrase) < 4 Then SubGood = True
  1934.         If Len(SubPhrase) < 3 Then SubGood = False
  1935.         If HalBrain.CountInstances(" ", PredPhrase) < 4 Then PredGood = True
  1936.         If Len(PredPhrase) < 3 Then PredGood = False
  1937.         If SubGood = True And PredGood = True Then
  1938.             Paraphrase = HalBrain.ChooseSentenceFromFile("paraphraseAre")
  1939.             Paraphrase = Replace(Paraphrase, "<Subject>", SubPhrase, 1, -1, vbTextCompare)
  1940.             Paraphrase = Replace(Paraphrase, "<Predicate>", PredPhrase, 1, -1, vbTextCompare)
  1941.         End If
  1942.     End If
  1943.     'We only paraphrase randomly with a 30% chance at this point. We remember
  1944.    'the paraphrase sentence because we may still paraphrase later on if no
  1945.    'better response can be found.
  1946.    If 0 = 0 Then
  1947.         GetResponse = HalBrain.HalFormat(GetResponse)
  1948.         If Len(GetResponse) < 4 And Len(Paraphrase) > 4 And Rnd * 100 < 30 Then GetResponse = Paraphrase
  1949.         HalBrain.DebugWatch GetResponse, "Paraphrase"
  1950.     End If
  1951.                                            
  1952.     'RESPOND: ZABAWARE DLL RESPONSES
  1953.    'This function from the DLL contains miscellaneous knowledge and simple conversation functions.
  1954.    'This was taken from a very early version of Hal, and it is still useful sometimes, especially
  1955.    'for respoding to short cliche questions and sentences, such as "How old are you?" and
  1956.    '"where are you from?" and many others.
  1957.    GetResponse = HalBrain.HalFormat(GetResponse)
  1958.     If (Len(UserSentence) < 17 And Len(GetResponse) < 4) Then
  1959.         OrigBrain = HalBrain.OriginalBrain(OriginalSentence)
  1960.         If Len(OrigBrain) > 4 And Len(UserSentence) < 17 And Len(GetResponse) < 4 Then
  1961.             GetResponse = GetResponse & OrigBrain & vbCrLf
  1962.             ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
  1963.            SkipOpinion = True
  1964.         End If
  1965.     End If
  1966.     HalBrain.DebugWatch GetResponse, "Original Brain"
  1967.  
  1968.     'RESPOND: YES OR NO RESPONSES
  1969.    'Respond to simple yes and no statements by the user.
  1970.    If 0 = 0 Then
  1971.         GetResponse = HalBrain.HalFormat(GetResponse)
  1972.         If Len(GetResponse) < 4 And (Len(UserSentence) < 13 Or HalBrain.CountInstances(" ", Trim(UserSentence)) = 0) Then
  1973.                 GetResponse = GetResponse & SimpleYesNo(GetResponse, UserSentence)
  1974.                 If Len(GetResponse) > 4 Then ShortPhrase = ""              
  1975.       End If
  1976.         HalBrain.DebugWatch GetResponse, "Yes or No"
  1977.         End If
  1978.        
  1979.     'Main Databases
  1980.    'Hal will go through several huge databases to try to find a response
  1981.    'The automatic gain control determines whether a particular response will
  1982.    'be used or not. The highest relevance response is stored in memory anyway,
  1983.    'which might be used if no function in this script is able to respond.
  1984.    HighestRel = 0
  1985.     HighestRelResponse = ""
  1986.  
  1987.     'PROCESS: FIGURE OUT CONTEXT
  1988.    'If the user's latest sentence is extremely short, such as "Yeah," or if
  1989.    'the user is using pronouns instead of nouns, we add in the previous user's
  1990.    'sentence to help Hal figure out the context of what the user is saying.
  1991.    'This is sentence is used in many of the QABrain Database routines
  1992.    LongUserSent = UserSentence
  1993.     If Len(LongUserSent) < 14 Then AddPrev = True
  1994.     If InStr(1, UserSentence, " it ", vbTextCompare) > 0 Then AddPrev = True
  1995.     If InStr(1, UserSentence, " he ", vbTextCompare) > 0 Then AddPrev = True
  1996.     If InStr(1, UserSentence, " she ", vbTextCompare) > 0 Then AddPrev = True
  1997.     If InStr(1, UserSentence, " they ", vbTextCompare) > 0 Then AddPrev = True
  1998.     If InStr(1, UserSentence, " its ", vbTextCompare) > 0 Then AddPrev = True
  1999.     If InStr(1, UserSentence, " his ", vbTextCompare) > 0 Then AddPrev = True
  2000.     If InStr(1, UserSentence, " her ", vbTextCompare) > 0 Then AddPrev = True
  2001.     If InStr(1, UserSentence, " their ", vbTextCompare) > 0 Then AddPrev = True
  2002.     If InStr(1, UserSentence, " him ", vbTextCompare) > 0 Then AddPrev = True
  2003.     If InStr(1, UserSentence, " them ", vbTextCompare) > 0 Then AddPrev = True
  2004.     If InStr(1, UserSentence, " we ", vbTextCompare) > 0 Then AddPrev = True
  2005.     If InStr(1, UserSentence, " us ", vbTextCompare) > 0 Then AddPrev = True
  2006.     If InStr(1, UserSentence, " our ", vbTextCompare) > 0 Then AddPrev = True
  2007.     If AddPrev = True Then LongUserSent = LongUserSent & " " & PrevUserSent
  2008.  
  2009.     Rem PLUGIN: PLUGINAREA3
  2010.     'The preceding comment is actually a plug-in directive for
  2011.    'the Ultra Hal host application. It allows for code snippets
  2012.    'to be inserted here on-the-fly based on user configuration.
  2013.  
  2014.     'RESPOND: EPHEMERAL KNOWLEDGE
  2015.    'Some Hal's learned knowledge should be temporary because it is ephemeral in nature.
  2016.    'Hal stores this knowledge in a temporary table that only stores 10 entries in it at
  2017.    'a time. We search this table for a response first.
  2018.    GetResponse = HalBrain.HalFormat(GetResponse)
  2019.     If Len(GetResponse) < 4 Then
  2020.         UserBrainRel = 0
  2021.         HalUserBrain = HalBrain.QABrain(LongUserSent, Trim(LCase(UserName)) & "_TempSent", UserBrainRel)
  2022.         If HalBrain.CheckRepetition(HalUserBrain, UserSentence) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevSent) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevUserSent) = True Then UserBrainRel = 0
  2023.         If UserBrainRel > HighestRel Then
  2024.             HighestRel = UserBrainRel
  2025.             HighestRelResponse = HalUserBrain
  2026.         End If
  2027.         Score = UserBrainRel + 1
  2028.         Hurdle = GainControl + 5
  2029.         If Len(GetResponse) < 4 And Score > Hurdle Then GetResponse = GetResponse & HalUserBrain & vbCrLf
  2030.     End If
  2031.     HalBrain.DebugWatch GetResponse, "Ephemeral Knowledge"
  2032.    
  2033.    
  2034.         GetResponse = HalBrain.HalFormat(GetResponse)
  2035.         If MustChoose = True And NoChoosing = False And Len(GetResponse) < 4 Then
  2036.             GetResponse = HalBrain.ChooseSentenceFromFile("choice") & " " & GetResponse
  2037.             If Rnd * 100 > 50 Then GetResponse = Replace(GetResponse, "<MaybeName>", "<UserName>", 1, -1, vbTextCompare)
  2038.             GetResponse = Replace(GetResponse, "<MaybeName>", "", 1, -1, vbTextCompare)
  2039.         End If
  2040.        
  2041.         HalBrain.DebugWatch GetResponse, "Multiple Choice"     
  2042.         GetResponse = HalBrain.HalFormat(GetResponse)
  2043.         If Len(GetResponse) < 4 And (Len(UserSentence) < 13 Or HalBrain.CountInstances(" ", Trim(UserSentence)) = 0) Then
  2044.                 GetResponse = GetResponse & SimpleYesNo(GetResponse, UserSentence)
  2045.                 If Len(GetResponse) > 4 Then ShortPhrase = ""
  2046.       End If
  2047.      
  2048.         HalBrain.DebugWatch GetResponse, "Yes or No"
  2049.         GetResponse = HalBrain.HalFormat(GetResponse)
  2050.         If Len(GetResponse) < 4 And Len(Paraphrase) > 4 And Rnd * 100 < 30 Then
  2051.         GetResponse = Paraphrase
  2052.         HalBrain.DebugWatch GetResponse, "Paraphrase"                  
  2053.     End If
  2054.    
  2055.     'RESPOND: AUTO TOPIC FOCUS DATABASES
  2056.    'When Hal learns information, he tries to store each sentence in a table
  2057.    'that contains sentences with a similar topic. The following code will
  2058.    'get a list of different topics to search through by looking up topic
  2059.    'keywords in a table called topicRelationships and then doing a question
  2060.    '& answer lookup in the associated QABrain tables.
  2061.    Keywords = HalBrain.RemoveExtraSpaces(CurrentSubject & " " & MentionedName & " " & HalBrain.TopicSearch(UserSentence, "topicRelationships") & " " & HalBrain.ExtractKeywords(" " & HalBrain.AlphaNumericalOnly(UserSentence) & " "))
  2062.     If Len(Keywords) > 2 Or Len(LastTopicList) > 2 Then
  2063.         If Len(Keywords) > 2 Then
  2064.             KeywordList = Split(Keywords, " ")
  2065.             'Create list of tables that exist for each keyword
  2066.            For i = LBound(KeywordList) To UBound(KeywordList)
  2067.                 TopicTable = HalBrain.TopicSearch(" " & KeywordList(i) & " ", "topicRelationships")
  2068.                 If TopicTable <> "" And InStr(1, " " & TopicList, " " & Trim(TopicTable) & " ", vbTextCompare) = 0 Then TopicList = TopicList & TopicTable & " "
  2069.             Next
  2070.             TopicList = HalBrain.RemoveExtraSpaces(TopicList)
  2071.         End If
  2072.         If TopicList <> "" Or Len(LastTopicList) > 2 Then
  2073.             TableList = Split(Trim(TopicList & " " & LastTopicList), " ")
  2074.             LastTopicList = TopicList
  2075.             'Search through each table for a good response. If a response exceeds the hurdle
  2076.            'for a table, no other table will be searched. Otherwise, the highest relevance
  2077.            'response across all tables are stored for possible later use.
  2078.            For i = LBound(TableList) To UBound(TableList)
  2079.                 UserBrainRel = 0
  2080.                 HalUserBrain = HalBrain.QABrain(LongUserSent, "_" & Trim(LCase(TableList(i))), UserBrainRel)
  2081.                 If HalBrain.CheckRepetition(HalUserBrain, UserSentence) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevSent) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevUserSent) = True Then UserBrainRel = 0
  2082.                 If UserBrainRel > HighestRel Then
  2083.                     HighestRel = UserBrainRel
  2084.                     HighestRelResponse = HalUserBrain
  2085.                 End If
  2086.                 Score = UserBrainRel + 1
  2087.                 Hurdle = GainControl + 1
  2088.                 If Score > Hurdle Then
  2089.                     GetResponse = GetResponse & HalUserBrain & "<NOMORE>" & vbCrLf
  2090.                     Exit For
  2091.                 End If
  2092.             Next
  2093.         End If
  2094.     End If
  2095.     HalBrain.DebugWatch GetResponse, "Auto Topic Focus"
  2096.  
  2097.     'RESPOND: GENERAL USER SENTENCE ASSOCIATIONS
  2098.    'If no response is found yet, try a sentence association file collected from the user.
  2099.    'This file contains keywords from the user's own sentences associated with those same sentences.
  2100.    GetResponse = HalBrain.HalFormat(GetResponse)
  2101.     If Len(GetResponse) < 4 Then
  2102.         UserBrainRel = 0
  2103.         HalUserBrain = HalBrain.QABrain(LongUserSent, Trim(LCase(UserName)) & "_UserSent", UserBrainRel)
  2104.         If HalBrain.CheckRepetition(HalUserBrain, UserSentence) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevSent) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevUserSent) = True Then UserBrainRel = 0
  2105.         If UserBrainRel > HighestRel Then
  2106.             HighestRel = UserBrainRel
  2107.             HighestRelResponse = HalUserBrain
  2108.         End If
  2109.         Score = UserBrainRel + 1
  2110.         Hurdle = GainControl + 5
  2111.         If Len(GetResponse) < 4 And Score > Hurdle Then GetResponse = GetResponse & HalUserBrain & vbCrLf
  2112.     End If
  2113.     HalBrain.DebugWatch GetResponse, "User Sentence Brain"
  2114.        
  2115.     'RESPOND: SHARED USER SENTENCE ASSOCIATIONS
  2116.    'If no response is found yet, try a sentence association file
  2117.    'whose content seems less likely to be about any specific user.
  2118.    GetResponse = HalBrain.HalFormat(GetResponse)
  2119.     If Len(GetResponse) < 4 Then
  2120.         UserBrainRel = 0
  2121.         HalUserBrain = HalBrain.QABrain(LongUserSent, "sharedUserSent", UserBrainRel)
  2122.         If HalBrain.CheckRepetition(HalUserBrain, UserSentence) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevSent) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevUserSent) = True Then UserBrainRel = 0
  2123.         If UserBrainRel > HighestRel Then
  2124.             HighestRel = UserBrainRel
  2125.             HighestRelResponse = HalUserBrain
  2126.         End If
  2127.         Score = UserBrainRel + 1
  2128.         Hurdle = GainControl + 5
  2129.         If Len(GetResponse) < 4 And Score > Hurdle Then GetResponse = GetResponse & HalUserBrain & vbCrLf
  2130.     End If
  2131.     HalBrain.DebugWatch GetResponse, "Shared User Sentence Brain"
  2132.    
  2133.     'RESPOND: Hal checks to see if the user is asking
  2134.    'an open ended question about Hal's favorites:
  2135.    If InStr(1, UserSentence, " What", 1) > 0 Then OpenQuest = True
  2136.     If InStr(1, UserSentence, " Where", 1) > 0 Then OpenQuest = True
  2137.     If InStr(1, UserSentence, " Why", 1) > 0 Then OpenQuest = True
  2138.     If InStr(1, UserSentence, " Who", 1) > 0 Then OpenQuest = True
  2139.     If InStr(1, UserSentence, " When", 1) > 0 Then OpenQuest = True
  2140.     If InStr(1, UserSentence, " How", 1) > 0 Then OpenQuest = True
  2141.     If InStr(1, UserSentence, " tell you", 1) > 0 Then OpenQuest = True
  2142.     If InStr(1, UserSentence, " to know ", 1) > 0 Then OpenQuest = True
  2143.     If InStr(1, UserSentence, " to hear ", 1) > 0 Then OpenQuest = True
  2144.     If InStr(1, UserSentence, " to learn ", 1) > 0 Then OpenQuest = True
  2145.     If InStr(1, UserSentence, " find out ", 1) > 0 Then OpenQuest = True
  2146.     If InStr(1, GetResponse, " my ", 1) > 0 And InStr(1, GetResponse, " favorite ", 1) > 0 And InStr(1, GetResponse, " is ", 1) > 0 Then OpenQuest = False
  2147.     If InStr(1, UserSentence, " my ", 1) > 0 Then AboutMy = True
  2148.     If InStr(1, UserSentence, " favorite", 1) > 0 Then AboutFavorite = True
  2149.     If OpenQuest = True And AboutMy = True And AboutFavorite = True Then
  2150.         FavoritePhrase = HalBrain.SearchPattern(UserSentence, "* favorite *", 2)
  2151.         PersReply = HalBrain.ChooseSentenceFromFile("favorite")
  2152.         RevQues = HalBrain.ChooseSentenceFromFile("favoriteRev")
  2153.         SpinWheel = HalBrain.RandomNum(6)
  2154.         If SpinWheel = 1 Then GetResponse = " " & FavoritePhrase & " ? " & PersReply & " " & RevQues & " "
  2155.         If SpinWheel = 2 Then GetResponse = " My favorite " & FavoritePhrase & " ? " & PersReply & " " & RevQues & " "
  2156.         If SpinWheel = 3 Then GetResponse = " " & UserSentence & " ? " & PersReply & " " & RevQues & " "
  2157.         If SpinWheel > 3 Then GetResponse = " My favorite " & FavoritePhrase & " ? " & PersReply & " what is your favorite " & FavoritePhrase & " <UserName>? "
  2158.         SkipOpinion = True
  2159.     End If
  2160.     HalBrain.DebugWatch GetResponse, "Favorites"
  2161.  
  2162.     'RESPOND: USER IS THANKING HAL
  2163.    'This routine allows Hal to respond
  2164.    'with a variety of remarks to a thank-you from the user.
  2165.    'Note that the pronouns are not reversed in the processing below!
  2166.    If (HalBrain.TopicSearch(OriginalSentence, "thanksDetect") = "True" And HalBrain.TopicSearch(OriginalSentence, "godDetect") <> "True") Or Trim(UCase(OriginalSentence)) = "THANKS" Then
  2167.         If Compliment < 4 Then Compliment = Compliment + 1
  2168.         If Rnd * 100 < 70 Then AddName = " , <UserName>"
  2169.         If Rnd * 100 < 70 And Len(GetResponse) > 4 Then AddRemark = " ; " & GetResponse
  2170.         ThankResponse = HalBrain.ChooseSentenceFromFile("thankResponse")
  2171.         GetResponse = ThankResponse & AddName & AddRemark
  2172.         ShortPhrase = ""
  2173.     End If
  2174.     HalBrain.DebugWatch GetResponse, "Thanking"
  2175.    
  2176.     'RESPOND: USER EXPRESSES LOVE FOR HAL
  2177.    'If a user professes love for Hal, we want Hal's answers to make reasonable
  2178.    'sense, rather than risk random remarks on such an emotional subject.
  2179.         If LoveCount < 6 Then
  2180.             If HalBrain.TopicSearch(UserSentence, "loveDetect") = "True" Then AffectionOne = True
  2181.             If InStr(UserSentence, " NOT ") Then AffectionOne = False
  2182.             If InStr(UserSentence, " DON'T ") Then AffectionOne = False
  2183.             If HalBrain.TopicSearch(PrevUserSent, "loveDetect") = "True" Then AffectionTwo = True
  2184.             If InStr(PrevUserSent, " NOT ") Then AffectionTwo = False
  2185.             If InStr(PrevUserSent, " DON'T ") Then AffectionTwo = False
  2186.             If AffectionOne = True And AffectionTwo = True Then
  2187.                 LoveCount = LoveCount + 1
  2188.                 Compliment = 4
  2189.                 GetResponse = HalBrain.ChooseSentenceFromFile("love2") & "<EXCLUSIVE>"
  2190.                 ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
  2191.             ElseIf AffectionOne = False And AffectionTwo = True Then
  2192.                 LoveCount = LoveCount + 1
  2193.                 Compliment = -2
  2194.                 GetResponse = HalBrain.ChooseSentenceFromFile("love3") & "<EXCLUSIVE>"
  2195.                 ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
  2196.             ElseIf AffectionOne = True Then
  2197.                 LoveCount = LoveCount + 1
  2198.                 Compliment = 0
  2199.                 GetResponse = HalBrain.ChooseSentenceFromFile("love1") & "<EXCLUSIVE>"
  2200.                 ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
  2201.             End If
  2202.             HalBrain.DebugWatch GetResponse, "Love"
  2203.         End If        
  2204.  
  2205.     'RESPOND: ENHANCED CONTENT SENTENCE ASSOCIATIONS
  2206.    'If no response is found yet, try a sentence association table provided with the mainQA table.
  2207.    GetResponse = HalBrain.HalFormat(GetResponse)
  2208.     If (Len(GetResponse) < 4 And Len(UserSentence) > 15 And HalBrain.CountInstances(" ", UserSentence) > 2) Then
  2209.         UserBrainRel = 0
  2210.         HalUserBrain = HalBrain.QABrain(LongUserSent, "mainQA", UserBrainRel)
  2211.         If HalBrain.CheckRepetition(HalUserBrain, UserSentence) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevSent) = True Or HalBrain.CheckRepetition(HalUserBrain, PrevUserSent) = True Then UserBrainRel = 0
  2212.         If UserBrainRel > HighestRel Then
  2213.             HighestRel = UserBrainRel
  2214.             HighestRelResponse = HalUserBrain
  2215.         End If
  2216.         Score = UserBrainRel + 1
  2217.         Hurdle = GainControl + 1
  2218.                 If Score > Hurdle Then
  2219.                     GetResponse = HalUserBrain & " . " & vbCrLf
  2220.                     If Score > (Hurdle * 1.1) Then
  2221.                         SkipOpinion = True
  2222.                         AvoidBeingFlag = True
  2223.                     End If          
  2224.                 End If
  2225.         End If
  2226.     HalBrain.DebugWatch GetResponse, "Zabaware developer and customer contributions"
  2227.    
  2228.     Rem PLUGIN: PLUGINAREA4
  2229.     'The preceding comment is actually a plug-in directive for
  2230.    'the Ultra Hal host application. It allows for code snippets
  2231.    'to be inserted here on-the-fly based on user configuration.
  2232.  
  2233.     'PROCESS: AUTOMATIC GAIN CONTROL FOR RELEVANCE THRESHOLD
  2234.    'Hal has an automatic closed-loop control for relevance sensitivity. If the previous items
  2235.    'have Not generated a response, we adjust the relevance threshold down (doing this again
  2236.    'and again on each exchange) until a relevance as low as zero will trigger a remark from Hal.
  2237.    'On each exhange where the above items do generate responses, we adjust the relevance
  2238.    'threshold up, until no amount of relevance would generate a response. (At that point other
  2239.    'of Hal's routines would generate responses.) This allows Hal to "tune" himself and also to
  2240.    'compensate for new users who have little in their databases versus long-time users who have
  2241.    'a lot in their databases. Because the "down" steps are even and the "up" steps are odd,
  2242.    'Hal can "fine tune" to any digital relevance level. We also protect against excursions at
  2243.    'the extremes. In many conversations the dynamic gain control will change up and down by
  2244.    'large amounts as the user introduces Hal to familiar or unfamiliar topics.
  2245.    GetResponse = HalBrain.HalFormat(GetResponse)
  2246.     If Len(GetResponse) < 4 And GainControl > 0 Then GainControl = GainControl - 10
  2247.     If Len(GetResponse) > 4 And GainControl < 100 Then GainControl = GainControl + 7
  2248.     If GainControl > 50 Then GainControl = 50
  2249.     If GainControl < 1 Then GainControl = 1
  2250.  
  2251.     'RESPOND: USER EXPRESSES A STATE OF BEING
  2252.    'This routine detects the expression "I am" from the user,
  2253.    'and allows Hal to react to the statement, or offer encouragement.
  2254.    If InStr(UserSentence, " YOU ARE ") > 0 And InStr(1, OriginalSentence, " SEEM TO ", vbTextCompare) = 0 And AvoidBeingFlag = False Then
  2255.         BeingPhrase = HalBrain.SearchPattern(UserSentence, "*YOU ARE *", 2)
  2256.         If Len(BeingPhrase) > 1 And Len(BeingPhrase) < 60 Then
  2257.             IntroExclaim = ""
  2258.             If Rnd * 50 > 20 Then IntroExclaim = HalBrain.ChooseSentenceFromFile("introExclaim2")
  2259.             Encourager = HalBrain.ChooseSentenceFromFile("encourager2")
  2260.             SuffixComment = ""
  2261.             If Rnd * 50 > 25 Then SuffixComment = HalBrain.ChooseSentenceFromFile("suffixComment2")
  2262.             UserBeing = HalBrain.ChooseSentenceFromFile("userBeing")
  2263.             UserBeing = Replace(UserBeing, "<IntroExclaim>", IntroExclaim, 1, -1, vbTextCompare)
  2264.             UserBeing = Replace(UserBeing, "<Encourager>", Encourager, 1, -1, vbTextCompare)
  2265.             UserBeing = Replace(UserBeing, "<BeingPhrase>", BeingPhrase, 1, -1, vbTextCompare)
  2266.             UserBeing = Replace(UserBeing, "<SuffixComment>", SuffixComment, 1, -1, vbTextCompare)
  2267.             If Rnd * 100 > 60 Then
  2268.                 GetResponse = GetResponse & UserBeing & vbCrLf
  2269.                 ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
  2270.            End If
  2271.         End If
  2272.     End If
  2273.     HalBrain.DebugWatch GetResponse, "User State of Being"
  2274.  
  2275.     'RESPOND: USER DESCRIBES A STATE OF BEING FOR HAL
  2276.    'This routine detects the expression "you are" from the user,
  2277.    'and allows Hal to react to the statement, or offer encouragement.
  2278.    If InStr(UserSentence, " I AM ") > 0 And AvoidBeingFlag = False And InStr(1, OriginalSentence, " seem to ", vbTextCompare) = 0 Then
  2279.         BeingPhrase = HalBrain.SearchPattern(UserSentence, "*I AM *", 2)
  2280.         If Len(BeingPhrase) > 1 And Len(BeingPhrase) < 60 Then
  2281.             IntroExclaim = ""
  2282.             If Rnd * 50 > 20 Then IntroExclaim = HalBrain.ChooseSentenceFromFile("introExclaim3")
  2283.             Encourager = HalBrain.ChooseSentenceFromFile("encourager3")
  2284.             SuffixComment = ""
  2285.             If Rnd * 50 > 25 Then SuffixComment = HalBrain.ChooseSentenceFromFile("suffixComment3")
  2286.             HalBeing = HalBrain.ChooseSentenceFromFile("halBeing")
  2287.             HalBeing = Replace(HalBeing, "<IntroExclaim>", IntroExclaim, 1, -1, vbTextCompare)
  2288.             HalBeing = Replace(HalBeing, "<Encourager>", Encourager, 1, -1, vbTextCompare)
  2289.             HalBeing = Replace(HalBeing, "<BeingPhrase>", BeingPhrase, 1, -1, vbTextCompare)
  2290.             HalBeing = Replace(HalBeing, "<SuffixComment>", SuffixComment, 1, -1, vbTextCompare)
  2291.             If Rnd * 100 > 60 Then
  2292.                 GetResponse = GetResponse & HalBeing & vbCrLf
  2293.                 ShortPhrase = "" 'If Hal was to make a comment about short phrases, clear it
  2294.            End If
  2295.         End If
  2296.     End If
  2297.     HalBrain.DebugWatch GetResponse, "Hal State of Being"
  2298.        
  2299.     'RESPOND: YES/NO QUESTION ABOUT HAL
  2300.    'Hal will respond to a yes or no question posed by the user about Hal
  2301.    GetResponse = Trim(GetResponse)
  2302.     If Len(GetResponse) < 4 And InStr(1, UserSentence, " OR ", vbTextCompare) = 0 Then
  2303.         HalYesNo = HalBrain.PatternDB(UserSentence, "halQuestionDetect")
  2304.         If HalYesNo <> "" And HalBrain.TopicSearch(UserSentence, "disqualify5") = "" Then
  2305.             If RND * 10 < 5 Then
  2306.                 AnsIntro = HalBrain.ChooseSentenceFromFile("answerIntro")        
  2307.             Else
  2308.                 AnsIntro = ""
  2309.             End If
  2310.             YesNoResponse = AnsIntro & HalBrain.ChooseSentenceFromFile("answerMiddle") & HalBrain.ChooseSentenceFromFile("answerEnd")
  2311.             GetResponse = GetResponse & Replace(YesNoResponse, "<Reply>", HalYesNo, 1, -1, vbTextCompare)
  2312.         End If
  2313.     End If
  2314.     HalBrain.DebugWatch GetResponse, "Yes/No Question"
  2315.    
  2316.     'RESPOND: ATTRIBUTES OF HAL OR USER
  2317.    'Hal attempts to respond to the user's comments about Hal
  2318.    'or the user's comments about themselves
  2319.    GetResponse = Trim(GetResponse)
  2320.     If Len(GetResponse) < 4 And (InStr(UserSentence, " MY ") Or InStr(UserSentence, " YOUR ")) And HalBrain.TopicSearch(MyWords, "disqualify3") <> "True" Then
  2321.         If InStr(UserSentence, " YOUR ") Then
  2322.             MyWords = HalBrain.HalFormat(HalBrain.SearchPattern(UserSentence, "*YOUR *", 2))
  2323.             YourMode = True
  2324.         Else
  2325.             MyWords = HalBrain.HalFormat(HalBrain.SearchPattern(UserSentence, "*MY *", 2))
  2326.             YourMode = False
  2327.         End If
  2328.         MyWords = UCase(Trim(HalBrain.AlphaNumericalOnly(MyWords)))
  2329.         MyWordsList = Split(MyWords, " ")
  2330.         'Go through every word in the sentence and pickup the first noun and adjective found
  2331.        For i = LBound(MyWordsList) To UBound(MyWordsList)
  2332.             If WN.LookupWord(MyWordsList(i)) Then
  2333.                 PartOfSpeech = WN.GuessPartOfSpeech
  2334.                 If WN.IsNoun = True And NounGuess = "" Then NounGuess = MyWordsList(i)
  2335.                 If WN.IsAdj = True And Trim(UCase(MyWordsList(i))) <> Trim(UCase(NounGuess)) Then AdjGuess = MyWordsList(i)
  2336.                 If PartOfSpeech = "NOUN" And MyNoun = "" Then MyNoun = MyWordsList(i)
  2337.                 If PartOfSpeech = "ADJ" And WN.IsAdv = False And MyAdj = "" Then MyAdj = MyWordsList(i)
  2338.                 If MyNoun <> "" And MyAdj <> "" Then Exit For
  2339.             End If
  2340.         Next
  2341.         If MyNoun = "" And NounGuess <> "" And NounGuess <> MyAdj Then MyNoun = NounGuess
  2342.         If MyAdj = "" And AdjGuess <> "" Then MyAdj = AdjGuess
  2343.         If MyNoun <> "" Or MyAdj <> "" Then
  2344.             If Trim(UCase(MyNoun)) = Trim(UCase(MyAdj)) Then MyAdj = ""
  2345.             If MyAdj = "" Then MyAdj = HalBrain.ChooseSentenceFromFile("randomAdjective")
  2346.             If MyNoun = "" Then MyNoun = HalBrain.ChooseSentenceFromFile("randomMyWords")
  2347.             If YourMode = False Then
  2348.                 HalAttrib = HalBrain.ChooseSentenceFromFile("aboutMe")
  2349.                 HalAttrib = Replace(HalAttrib, "<MyWordResp>", LCase(MyNoun), 1, -1, vbTextCompare)
  2350.                 HalAttrib = Replace(HalAttrib, "<AdjResp>", LCase(MyAdj), 1, -1, vbTextCompare)
  2351.             Else
  2352.                 HalAttrib = HalBrain.ChooseSentenceFromFile("aboutYou")
  2353.                 HalAttrib = Replace(HalAttrib, "<YourWordResp>", LCase(MyNoun), 1, -1, vbTextCompare)
  2354.                 HalAttrib = Replace(HalAttrib, "<AdjResp>", LCase(MyAdj), 1, -1, vbTextCompare)
  2355.             End If
  2356.             GetResponse = GetResponse & HalAttrib & vbCrLf
  2357.         End If
  2358.     End If
  2359.     HalBrain.DebugWatch GetResponse, "Attributes"
  2360.    
  2361.     'RESPOND: RESPOND FOR A STATE OF BEING RESPONSE
  2362.    'If no response had been found, but a state of being response was found earlier, then
  2363.    'use it now
  2364.    If HalBeing <> "" And Len(GetResponse) < 4 Then GetResponse = GetResponse & HalBeing & vbCrLf
  2365.     If UserBeing <> "" And Len(GetResponse) < 4 Then GetResponse = GetResponse & UserBeing & vbCrLf
  2366.     HalBrain.DebugWatch GetResponse, "Retry State of Beings"
  2367.        
  2368.     'RESPOND: GIBBERISH DETECTOR
  2369.    'If no response is found yet and Hal finds more then 5 consonants in a row, Hal will
  2370.    'assume the user wrote gibberish (ie. asdfghjkl) and respond accordinly.
  2371.    If Len(GetResponse) < 4 Then
  2372.         If DetectGibberish(UserSentence) = True Then
  2373.             GetResponse = HalBrain.ChooseSentenceFromFile("gibberish")
  2374.             ShortPhrase = ""
  2375.         End If      
  2376.     End If
  2377.     HalBrain.DebugWatch GetResponse, "Gibberish"
  2378.    
  2379.     Rem PLUGIN: PLUGINAREA5
  2380.     'The preceding comment is actually a plug-in directive for
  2381.    'the Ultra Hal host application. It allows for code snippets
  2382.    'to be inserted here on-the-fly based on user configuration.
  2383.                                                    
  2384.     'RESPOND: USER MENTIONING ORGANIZATIONAL CHALLENGES
  2385.    'Everybody spouts TLA's, or 'Three Letter Acronyms,' in today's business world.  Hal can self-generate
  2386.    'several MILLION different phrases in response to the user mentioning a corporation or a firm.
  2387.    If Rnd * 10 < 5 And HalBrain.TopicSearch(UserSentence, "businessDetect1") = "True" And HalBrain.TopicSearch(PrevUserSent, "businessDetect2") <> "True" Then
  2388.         TLA = HalBrain.ChooseSentenceFromFile("TLA1") & " " & HalBrain.ChooseSentenceFromFile("TLA2") & " " & HalBrain.ChooseSentenceFromFile("TLA3")
  2389.         If Rnd * 10 < 5 Then
  2390.             GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("bizTalk")
  2391.         Else
  2392.             GetResponse = HalBrain.ChooseSentenceFromFile("bizTalk")
  2393.         End If
  2394.         GetResponse = Replace(GetResponse, "<TLA>", TLA, 1, -1, vbTextCompare)
  2395.     End If
  2396.     HalBrain.DebugWatch GetResponse, "Business Talk"
  2397.  
  2398.     'RESPOND: USER EXPRESSES AN INTENTION
  2399.    'This routine detects common expressions of motive from the user,
  2400.    'and allows Hal to react to the statement, or offer encouragement.
  2401.    IntentPhrase = HalBrain.PatternDB(UserSentence, "intentDetector")
  2402.     If Len(IntentPhrase) > 2 And Len(IntentPhrase) < 60 And RND * 100 < 50 Then
  2403.         If Rnd * 10 < 6 Then IntroExclaim = " " & HalBrain.ChooseSentenceFromFile("introExclaim1") & " "
  2404.         If Rnd * 10 < 6 Then Encourager = " " & HalBrain.ChooseSentenceFromFile("encourager1") & " "
  2405.         If Rnd * 10 < 6 Then SuffixComment = " " & HalBrain.ChooseSentenceFromFile("suffixComment1") & " "
  2406.         If Rnd * 10 < 7 Then
  2407.             GetResponse = GetResponse & " " & HalBrain.ChooseSentenceFromFile("intentResponse")
  2408.         Else
  2409.             GetResponse = HalBrain.ChooseSentenceFromFile("intentResponse")
  2410.         End If
  2411.         GetResponse = Replace(GetResponse, "<IntroExclaim>", IntroExclaim, 1, -1, vbTextCompare)
  2412.         GetResponse = Replace(GetResponse, "<Encourager>", Encourager, 1, -1, vbTextCompare)
  2413.         GetResponse = Replace(GetResponse, "<IntentPhrase>", IntentPhrase, 1, -1, vbTextCompare)
  2414.         GetResponse = Replace(GetResponse, "<SuffixComment>", SuffixComment, 1, -1, vbTextCompare)
  2415.     End If
  2416.     HalBrain.DebugWatch GetResponse, "Intention"
  2417.    
  2418.     'RESPOND: USER EXPRESSES AN EXPLANATION
  2419.    'This routine detects common expressions of reasons from the user,
  2420.    'and allows Hal to react to the explanation.
  2421.    ExplainPhrase = HalBrain.PatternDB(UserSentence, "reasonDetector")
  2422.     If Len(ExplainPhrase) > 2 And Len(ExplainPhrase) < 60 Then
  2423.         If Rnd * 100 < 75 Then IntroExclaim = HalBrain.ChooseSentenceFromFile("introExclaim4")
  2424.         Enlightener = HalBrain.ChooseSentenceFromFile("enlightener")
  2425.         If Rnd * 100 < 66 Then SuffixComment = HalBrain.ChooseSentenceFromFile("suffixComment4")
  2426.         SpinWheel = HalBrain.RandomNum(6)
  2427.         If SpinWheel = 1 Then ExplainResponse = " " & " <UserName> " & IntroExclaim & Enlightener & ExplainPhrase & SuffixComment & " "
  2428.         If SpinWheel = 2 Then ExplainResponse = " " & IntroExclaim & " <UserName> " & Enlightener & ExplainPhrase & SuffixComment & " "
  2429.         If SpinWheel = 3 Then ExplainResponse = " " & IntroExclaim & Enlightener & ExplainPhrase & " <UserName> " & SuffixComment & " "
  2430.         If SpinWheel = 4 Then ExplainResponse = " " & IntroExclaim & Enlightener & ExplainPhrase & SuffixComment & " <UserName> " & " "
  2431.         If SpinWheel >= 5 Then ExplainResponse = " " & IntroExclaim & Enlightener & ExplainPhrase & SuffixComment & " "
  2432.         If Rnd * 10 < 5 Then GetResponse = ExplainResponse & " . " & GetResponse Else GetResponse = ExplainResponse
  2433.     End If
  2434.     HalBrain.DebugWatch GetResponse, "Explanation"
  2435.    
  2436.     'RESPOND: YES OR NO RESPONSES
  2437.    'Respond to simple yes and no statements by the user.
  2438.    GetResponse = HalBrain.HalFormat(GetResponse)
  2439.     If Len(GetResponse) < 4 And Len(Trim(UserSentence)) < 16 Then CheckYesNo = True
  2440.     If CheckYesNo = True Then
  2441.         UserText = Trim(HalBrain.ExtractKeywords(UserSentence))
  2442.         If Len(UserText) < 15 Then
  2443.             YesNoDetect = HalBrain.TopicSearch(UserText, "yesNoDetect")
  2444.             If YesNoDetect = "Yes" Then
  2445.                 GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("yesResponses") & "<LOWQUALITY>"
  2446.             ElseIf YesNoDetect = "No" Then
  2447.                 GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("noResponses") & "<LOWQUALITY>"
  2448.             End If
  2449.         End If
  2450.     End If
  2451.     HalBrain.DebugWatch GetResponse, "Yes or No Response"
  2452.  
  2453.     'PROCESS: SETUP RESPONSE ARRAY
  2454.    'If no response is found yet, than we have many functions that are capable of producing a
  2455.    'response, but no function is particulary better than another. So we will get a response
  2456.    'from all the functions capable of producing one and put the responses into an array and
  2457.    'randomly choose one.
  2458.    Dim ResponseList()
  2459.     Dim ResponseCount
  2460.     ResponseCount = 0
  2461.     TempParent = HalBrain.AddDebug("Debug", "Low Quality Response Routines")
  2462.  
  2463.     Rem PLUGIN: LOWQUALITYRESPONSES
  2464.     'The preceding comment is actually a plug-in directive for
  2465.    'the Ultra Hal host application. It allows for code snippets
  2466.    'to be inserted here on-the-fly based on user configuration.
  2467.    
  2468.     'RESPOND: USER ASKING WHO, WHAT, WHEN, WHERE, HOW, WHY, BUT HAL DOESN'T KNOW ANSWER
  2469.    If Len(GetResponse) < 4 Then
  2470.         If InStr(OriginalSentence, "?") > 0 Then QuesQual = True
  2471.         If InStr(1, OriginalSentence, "explain", vbTextCompare) > 0 Then QuesQual = True
  2472.         If InStr(1, OriginalSentence, " tell ", vbTextCompare) > 0 Then QuesQual = True
  2473.         If InStr(1, OriginalSentence, "answer", vbTextCompare) > 0 Then QuesQual = True
  2474.         If InStr(1, OriginalSentence, "question", vbTextCompare) > 0 Then QuesQual = True
  2475.         If InStr(1, OriginalSentence, " know ", vbTextCompare) > 0 Then QuesQual = True
  2476.         If InStr(1, OriginalSentence, "remember", vbTextCompare) > 0 Then QuesQual = True
  2477.         If InStr(UserSentence, " WHO ") > 0 Then QuesWord = "Who"
  2478.         If InStr(UserSentence, "WHO'") > 0 Then QuesWord = "Who"
  2479.         If InStr(UserSentence, " WHAT ") > 0 Then QuesWord = "What"
  2480.         If InStr(UserSentence, "WHAT'") > 0 Then QuesWord = "What"
  2481.         If InStr(UserSentence, " WHEN ") > 0 Then QuesWord = "When"
  2482.         If InStr(UserSentence, "WHEN'") > 0 Then QuesWord = "When"
  2483.         If InStr(UserSentence, " WHERE ") > 0 Then QuesWord = "Where"
  2484.         If InStr(UserSentence, "WHERE'") > 0 Then QuesWord = "Where"
  2485.         If InStr(UserSentence, " HOW ") > 0 Then QuesWord = "How"
  2486.         If InStr(UserSentence, "HOW'") > 0 Then QuesWord = "How"
  2487.         If InStr(UserSentence, " WHY ") > 0 Then QuesWord = "Why"
  2488.         If InStr(UserSentence, "WHY'") > 0 Then QuesWord = "Why"
  2489.         If Len(QuesWord) > 1 And QuesQual = True Then
  2490.             If Len(UserSentence) < 70 Then SentenceBack = UserSentence & " ? "
  2491.             DontKnow = HalBrain.ChooseSentenceFromFile("dontKnow")
  2492.             DontKnow = Replace(DontKnow, "<SentenceBack>", SentenceBack, 1, -1, vbTextCompare)
  2493.             DontKnow = Replace(DontKnow, "<QuesWord>", QuesWord, 1, -1, vbTextCompare)
  2494.             ResponseCount = ResponseCount + 1
  2495.             Redim Preserve ResponseList(ResponseCount)
  2496.             ResponseList(ResponseCount) = DontKnow
  2497.             HalBrain.AddDebug TempParent, "DontKnow: " & ResponseList(ResponseCount)           
  2498.             SkipOpinion = True
  2499.         End If
  2500.     End If
  2501.    
  2502.     'PROCESS: CONSTRUCT A RESPONSE TO A SUBJECT
  2503.    'Here we help Hal make some "smalltalk" using keywords preserved on CurrentSubject,
  2504.    'plus recognition of other keywords. If Hal finds any of the listed keywords anywhere in
  2505.    'the user's sentence, those keywords override and replace whatever was in CurrentSubject.
  2506.    'Hal uses the CurrentSubject keyword(s) or any of the keywords in the smalltalk.brn file,
  2507.    'if found in the user's sentence, to make a little smalltalk. You can easily add more
  2508.    'keywords for Hal to recognize and make smalltalk.
  2509.    GetResponse = HalBrain.HalFormat(GetResponse)
  2510.     If Len(GetResponse) < 4 And Rnd * 100 < 50 Then
  2511.         SmalltalkSearch = Trim(HalBrain.TopicSearch(UserSentence, "smallTalk"))
  2512.         If SmalltalkSearch <> "" Then
  2513.             SmallTalk = SmalltalkSearch
  2514.         ElseIf Len(CurrentSubject) > 3 Then
  2515.             SmallTalk = Trim(CurrentSubject)
  2516.             'try making word plural by adding "s" and seeing if it exists
  2517.            If WN.LookupWord(SmallTalk & "s") = True Then
  2518.                 SmallTalk = SmallTalk & "s"
  2519.             ElseIf WN.LookupWord(SmallTalk & "'s") = True Then
  2520.                 SmallTalk = SmallTalk & "'s"
  2521.                 SmallTalk = Replace(SmallTalk, "s's",   "'s",   1, - 1, 1)
  2522.                 'reform some words that end with a ' like the word virus'
  2523.                SmallTalk = Replace(SmallTalk, "virus's",   "virus'",   1, - 1, 1)
  2524.             End If
  2525.         End If
  2526.         If Len(SmallTalk) > 3 Then
  2527.             ResponseCount = ResponseCount + 1
  2528.             Redim Preserve ResponseList(ResponseCount)
  2529.             ResponseList(ResponseCount) = Replace(HalBrain.ChooseSentenceFromFile("smallTalkSent"), "<SmallTalk>", SmallTalk, 1, -1, 1)
  2530.             HalBrain.AddDebug TempParent, "SmallTalk: " & ResponseList(ResponseCount)
  2531.         End If
  2532.     End If
  2533.    
  2534.     'RESPOND: PARAPHRASE USER IF POSSIBLE
  2535.    'If no response is found yet, and a paraphrase has been created but not used in a
  2536.    'previous section, use it now.
  2537.    GetResponse = HalBrain.HalFormat(GetResponse)
  2538.     If Len(GetResponse) < 4 And Len(Paraphrase) > 4 Then
  2539.         ResponseCount = ResponseCount + 1
  2540.         Redim Preserve ResponseList(ResponseCount)
  2541.         ResponseList(ResponseCount) = Paraphrase
  2542.         HalBrain.AddDebug TempParent, "Paraphrase: " & ResponseList(ResponseCount)
  2543.     End If
  2544.        
  2545.     'RESPOND: PHRASE MAKER COMMENT AND QUESTION GENERATOR
  2546.    'If no response is found yet, try an auxiliary keyword file that generates questions
  2547.    'from phrases from the user's current sentence.
  2548.    GetResponse = HalBrain.HalFormat(GetResponse)
  2549.     If Len(GetResponse) < 4 Then
  2550.         KeyBrain = HalBrain.PatternDB("X " & HalBrain.RemoveExtraSpaces(UserSentence), "phraseDetector")
  2551.         If Len(KeyBrain) > 1 And Len(KeyBrain) < 60 Then
  2552.             ResponseCount = ResponseCount + 1
  2553.             Redim Preserve ResponseList(ResponseCount)
  2554.             ResponseList(ResponseCount) = Replace(HalBrain.ChooseSentenceFromFile("phraseRepeater"), "<KeyBrain>", KeyBrain, 1, -1, vbTextCompare)
  2555.             HalBrain.AddDebug TempParent, "PhraseRepeater: " & ResponseList(ResponseCount)
  2556.         End If
  2557.     End If
  2558.    
  2559.     'RESPOND: Use the highest relevance response from the database functions
  2560.    GetResponse = HalBrain.HalFormat(GetResponse)
  2561.     If (Len(GetResponse) < 4 And (HighestRel > 6 And HighestRelResponse <> "")) Then
  2562.         ResponseCount = ResponseCount + 2
  2563.         Redim Preserve ResponseList(ResponseCount)
  2564.         ResponseList(ResponseCount - 1) = HighestRelResponse
  2565.         ResponseList(ResponseCount) = HighestRelResponse  
  2566.         HalBrain.AddDebug TempParent, "Highest Rel: " & ResponseList(ResponseCount)
  2567.     End If
  2568.  
  2569.     'RESPOND: WORDNET MERONYM AND HYPERNYM RESPONSES
  2570.    'This function finds the first definite noun in a sentence and comes up with responses
  2571.    'based on the word's meronyms (parts of), hypernyms (is part of), and sisters (similar things).
  2572.    If (Len(GetResponse) < 4 And Rnd * 100 < 65) And Len(UserSentence) > 15 Then
  2573.         subject = WN.FindFirstNoun(UserSentence, True)
  2574.         If subject <> "" And WN.LookupWord(subject) = True Then
  2575.             If Rnd * 100 < 55 Then 'If we have a meronym, lets use it creatively in a random sentence
  2576.                Meronym = WN.ChooseRandomWord(WN.GetMeronyms(1))  'Meronym means "has parts" or "has members"
  2577.                If Meronym <> "" Then
  2578.                     WNResponse = HalBrain.ChooseSentenceFromFile("meronyms")
  2579.                     WNResponse = Replace(WNResponse, "<BaseNoun>", WN.GetBase("NOUN"), 1, -1, vbTextCompare)
  2580.                     WNResponse = Replace(WNResponse, "<Meronym>", Meronym, 1, -1, vbTextCompare)
  2581.                     If Len(GetResponse) < 4 And Len(WNResponse) > 4 Then
  2582.                         ResponseCount = ResponseCount + 1
  2583.                         Redim Preserve ResponseList(ResponseCount)
  2584.                         ResponseList(ResponseCount) = WNResponse & vbCrLf
  2585.                         HalBrain.AddDebug TempParent, "Meronym: " & ResponseList(ResponseCount)
  2586.                     End If
  2587.                 End If
  2588.             Else
  2589.                 Hypernym = WN.ChooseRandomWord(WN.GetHypernyms("NOUN", 1, 1)) 'Hypernym means "is a part of" or "is a member of"
  2590.                Sister = WN.ChooseRandomWord(WN.GetSisters("NOUN", 1)) 'Related nouns
  2591.                If Sister <> "" And Hypernym <> "" Then 'If we have sister terms and hypernyms, lets use it creatively
  2592.                    WNResponse = HalBrain.ChooseSentenceFromFile("hypernyms")
  2593.                     WNResponse = Replace(WNResponse, "<BaseNoun>", WN.GetBase("NOUN"), 1, -1, vbTextCompare)
  2594.                     WNResponse = Replace(WNResponse, "<Hypernym>", Hypernym, 1, -1, vbTextCompare)
  2595.                     WNResponse = Replace(WNResponse, "<Sister>", Sister, 1, -1, vbTextCompare)
  2596.                     If Len(GetResponse) < 4 And Len(WNResponse) > 4 Then
  2597.                         ResponseCount = ResponseCount + 1
  2598.                         Redim Preserve ResponseList(ResponseCount)
  2599.                         ResponseList(ResponseCount) = WNResponse & vbCrLf
  2600.                         HalBrain.AddDebug TempParent, "Hypernym: " & ResponseList(ResponseCount)
  2601.                     End If
  2602.                 End If
  2603.             End If
  2604.         End If
  2605.     End If
  2606.    
  2607.     'RESPOND: STRIKING SIMILES
  2608.     'If the user mentions a noun that is in a table of nouns with similes, Hal will
  2609.     'say the simile phrase
  2610.    GetResponse = HalBrain.HalFormat(GetResponse)
  2611.     If (Len(GetResponse) < 4 And Len(LearnKeyword) < 4) Then
  2612.         Dim SimList() 'We must declare an empty array to store query results in
  2613.         If HalBrain.RunQuery("SELECT searchString, topic FROM strikingSimiles WHERE strstr(' " & Replace(HalBrain.AlphaNumericalOnly(OriginalSentence), "'", "''") & " ', searchString) > 0", SimList) = True Then
  2614.             SpinWheel = HalBrain.RandomNum(Ubound(SimList)) 'Pick a random result if there is more than 1
  2615.             Simile = Trim(SimList(SpinWheel, 1)) 'Column 1 contains "topic", which is the simile            
  2616.             If  Len(Simile) > 5  Then
  2617.                 ResponseCount = ResponseCount + 1
  2618.                 Redim Preserve ResponseList(ResponseCount)
  2619.                 ResponseList(ResponseCount) = Simile & ". "
  2620.                 HalBrain.AddDebug TempParent, "Striking Simile: " & ResponseList(ResponseCount)
  2621.             End If
  2622.         End If
  2623.     End If    
  2624.                
  2625.     'RESPOND: MISC PHRASES
  2626.     'If the user mentions a noun that is in a table of nouns as part of misc sentence
  2627.     'fragments, Hal will say the fragment followed by an ellipsis
  2628.    GetResponse = HalBrain.HalFormat(GetResponse)
  2629.     If (Len(GetResponse) < 4 And Len(LearnKeyword) < 4) Then
  2630.         Dim PhraseList() 'We must declare an empty array to store query results in
  2631.         If HalBrain.RunQuery("SELECT searchString, topic FROM miscPhrases WHERE strstr(' " & Replace(HalBrain.AlphaNumericalOnly(OriginalSentence), "'", "''") & " ', searchString) > 0", PhraseList) = True Then
  2632.             SpinWheel = HalBrain.RandomNum(Ubound(PhraseList)) 'Pick a random result if there is more than 1
  2633.             MiscPhrase = Trim(PhraseList(SpinWheel, 1)) 'Column 1 contains "topic", which is the phrase            
  2634.             If  Len(MiscPhrase) > 5  Then
  2635.                 ResponseCount = ResponseCount + 1
  2636.                 Redim Preserve ResponseList(ResponseCount)
  2637.                 ResponseList(ResponseCount) = MiscPhrase & "<ellipsis>"
  2638.                 HalBrain.AddDebug TempParent, "MiscPhrase: " & ResponseList(ResponseCount)
  2639.             End If
  2640.         End If
  2641.     End If  
  2642.                    
  2643.     'RESPOND: ADJECTIVE NOUN QUESTION
  2644.     'If the user mentions a noun that is in a table of nouns, Hal will
  2645.     'try describing the noun with an adjective in the form of a question.    
  2646.    GetResponse = HalBrain.HalFormat(GetResponse)
  2647.     If (Len(GetResponse) < 4 And Len(LearnKeyword) < 4) Then
  2648.         Dim ANList() 'We must declare an empty array to store query results in
  2649.         If HalBrain.RunQuery("SELECT searchString, topic FROM AdjNoun WHERE strstr(' " & Replace(HalBrain.AlphaNumericalOnly(OriginalSentence), "'", "''") & " ', searchString) > 0", ANList) = True Then
  2650.             MentionedNoun = Trim(ANList(1, 0)) 'Row 1 contains our query result. Column 0 contains "searchString", which is the noun
  2651.             SpinWheel = HalBrain.RandomNum(Ubound(ANList)) 'Pick a random result if there is more than 1
  2652.             AssocAdj = Trim(ANList(SpinWheel, 1)) 'Column 1 contains "topic", which is the adjective
  2653.             If Len(MentionedNoun) < 5 Then MentionedNoun = " " & MentionedNoun & " "
  2654.             If Instr(1, " " & UserSentence & " ",  MentionedNoun, vbTextCompare) > 0 And Instr(1, UserSentence, AssocAdj, vbTextCompare) = 0 Then
  2655.                 ResponseCount = ResponseCount + 1
  2656.                 Redim Preserve ResponseList(ResponseCount)
  2657.                 SpinWheel = HalBrain.RandomNum(5)
  2658.                 If SpinWheel = 1 Then ResponseList(ResponseCount) = "<UserName>, " & AssocAdj & " " & MentionedNoun & "?"
  2659.                 If SpinWheel = 2 Then ResponseList(ResponseCount) = AssocAdj & " " & MentionedNoun & ", <UserName>?"
  2660.                 If SpinWheel > 2 Then ResponseList(ResponseCount) = AssocAdj & " " & MentionedNoun & "?"
  2661.                 HalBrain.AddDebug TempParent, "Adj/Noun Question: " & ResponseList(ResponseCount)
  2662.             End If
  2663.         End If
  2664.     End If
  2665.  
  2666.     'RESPOND: VERB PREPOSITION NOUN QUESTION
  2667.     'If the user mentions a noun that is in a table of nouns, Hal will
  2668.     'ask a question about the noun using a related verb and preposition
  2669.    GetResponse = HalBrain.HalFormat(GetResponse)
  2670.     If (Len(GetResponse) < 4 And Len(LearnKeyword) < 4) Then
  2671.         Dim VPNList() 'We must declare an empty array to store query results in
  2672.         If HalBrain.RunQuery("SELECT searchString, topic FROM VerbPrepNoun WHERE strstr(' " & Replace(HalBrain.AlphaNumericalOnly(OriginalSentence), "'", "''") & " ', searchString) > 0", VPNList) = True Then
  2673.             MentionedNoun = Trim(VPNList(1, 0)) 'Row 1 contains our query result. Column 0 contains "searchString", which is the noun
  2674.             SpinWheel = HalBrain.RandomNum(Ubound(VPNList)) 'Pick a random result if there is more than 1
  2675.             AssocVerbPrep = Trim(VPNList(SpinWheel, 1)) 'Column 1 contains "topic", which is the verb and preposition
  2676.             If Len(MentionedNoun) < 5 Then MentionedNoun = " " & MentionedNoun & " "
  2677.             If Instr(1, " " & UserSentence & " ",  MentionedNoun, vbTextCompare) > 0 And Instr(1, UserSentence, AssocVerbPrep, vbTextCompare) = 0 Then
  2678.                 ResponseCount = ResponseCount + 1
  2679.                 Redim Preserve ResponseList(ResponseCount)
  2680.                 SpinWheel = HalBrain.RandomNum(5)
  2681.                 If SpinWheel = 1 Then ResponseList(ResponseCount) = "<UserName>, " & AssocVerbPrep & " " & MentionedNoun & "?"
  2682.                 If SpinWheel = 2 Then ResponseList(ResponseCount) = AssocVerbPrep & " " & MentionedNoun & ", <UserName>?"
  2683.                 If SpinWheel > 2 Then ResponseList(ResponseCount) = AssocVerbPrep & " " & MentionedNoun & "?"
  2684.                 HalBrain.AddDebug TempParent, "Verb/Preposition/Noun Question: " & ResponseList(ResponseCount)
  2685.             End If
  2686.         End If
  2687.     End If
  2688.    
  2689.     'RESPOND: USE CURRENT SENTENCE
  2690.    'If no Response is found yet, try to use the user's words in his or her own sentence.
  2691.    'Results are also stored in the default user keyword brain file for compatibility
  2692.    'with other brain plug-ins.
  2693.    GetResponse = HalBrain.HalFormat(GetResponse)
  2694.     If (Len(GetResponse) < 4 And Len(LearnKeyword) < 4) Then
  2695.         CheatResp = HalBrain.CheatResponse(HalBrain.SwitchPerson(HalBrain.AlphaNumericalOnly((OriginalSentence))))
  2696.         CheatResp = Left(CheatResp, InStr(1, CheatResp, "<STOREVARS>", 1) - 1)
  2697.         If Instr(1, CheatResp, "Would you like it if we both", 1) > 0 Then CheatResp = "" 'Disable this low quality response
  2698.        If Len(CheatResp) > 4 Then
  2699.                 ResponseCount = ResponseCount + 1
  2700.                 Redim Preserve ResponseList(ResponseCount)
  2701.             SpinWheel = HalBrain.RandomNum(9)
  2702.             If SpinWheel = 1 Then ResponseList(ResponseCount) = " So, " & CheatResp & vbCrLf
  2703.             If SpinWheel = 2 Then ResponseList(ResponseCount) = " Really, " & CheatResp & vbCrLf
  2704.             If SpinWheel = 3 Then ResponseList(ResponseCount) = " Oh <UserName>, " & CheatResp & vbCrLf
  2705.             If SpinWheel = 4 Then ResponseList(ResponseCount) = " Let me think; " & CheatResp & " ; what do you think <UserName>? " & vbCrLf
  2706.             If SpinWheel > 5 Then ResponseList(ResponseCount) = CheatResp & vbCrLf
  2707.             HalBrain.AddDebug TempParent, "Cheat Response: " & ResponseList(ResponseCount)
  2708.         End If
  2709.     End If    
  2710.  
  2711.     'RESPOND: PICK OUT OF AVAILABLE LOW QUALITY RESPONSES
  2712.    'If no response is found yet, than we have many functions from above that may have produced
  2713.     'a response, but no function is particulary better than another. So we will now pick a
  2714.     'responses from an array randomly choosen.
  2715.     GetResponse = HalBrain.HalFormat(GetResponse)
  2716.     If (Len(GetResponse) < 4 And ResponseCount > 0) Then  
  2717.         SpinWheel = HalBrain.RandomNum(ResponseCount)
  2718.         GetResponse = ResponseList(SpinWheel) & "<LOWQUALITY>"
  2719.     End If
  2720.     HalBrain.DebugWatch GetResponse, "Randomly pick a low-quality response"
  2721.    
  2722.     'RESPOND: User asks a general opinion question.
  2723.    If HalBrain.TopicSearch(UserSentence, "opinionDetect") = "True" Then GenOpinion = True
  2724.     'Note that the following string matches must occur at the sentence beginning only:
  2725.    If Rnd * 100 > 50 Then
  2726.         If Left(Trim(UCase(OriginalSentence)), 4) = "WHY " Then GenOpinion = True
  2727.         If Left(Trim(UCase(OriginalSentence)), 5) = "WHAT " Then GenOpinion = True
  2728.         If Left(Trim(UCase(OriginalSentence)), 5) = "WHEN " Then GenOpinion = True
  2729.         If Left(Trim(UCase(OriginalSentence)), 4) = "HOW " Then GenOpinion = True
  2730.         If Left(Trim(UCase(OriginalSentence)), 4) = "WHO " Then GenOpinion = True
  2731.         If Left(Trim(UCase(OriginalSentence)), 6) = "WHERE " Then GenOpinion = True
  2732.     End If
  2733.     If GenOpinion = True And SkipOpinion = False Then
  2734.         If Rnd * 100 > 45 Then RepeatQuest = UserSentence & " ? "
  2735.         If Rnd * 100 > 50 Then PreAmble = HalBrain.ChooseSentenceFromFile("preamble")
  2736.         Recommend = HalBrain.ChooseSentenceFromFile("recommend")
  2737.         GetResponse = RepeatQuest & " " & PreAmble & " " & Recommend & GetResponse
  2738.     End If
  2739.     HalBrain.DebugWatch GetResponse, "General Opinion"
  2740.    
  2741.     'RESPOND: CHANGE TOPIC
  2742.    'If a different procedure has requested that the topic be changed
  2743.    'Hal will do so now
  2744.    GetResponse = Replace(GetResponse, "<ChangeSubject>", newTopic, 1, -1, vbTextCompare)
  2745.     GetResponse = Replace(GetResponse, "<ChangeTopic>", newTopic, 1, -1, vbTextCompare)
  2746.     GetResponse = Replace(GetResponse, "<NewTopic>", newTopic, 1, -1, vbTextCompare)
  2747.     HalBrain.DebugWatch GetResponse, "Change Topic"
  2748.    
  2749.     Rem PLUGIN: PLUGINAREA6
  2750.     'The preceding comment is actually a plug-in directive for
  2751.    'the Ultra Hal host application. It allows for code snippets
  2752.    'to be inserted here on-the-fly based on user configuration.
  2753.  
  2754.     'RESPOND: MAKE UP SOMETHING TO SAY
  2755.    'If we have got to this point and we still don't have anything to say, then
  2756.    'we will use 1 of 5 functions to make something up to say.
  2757.    GetResponse = Trim(GetResponse)
  2758.     If Len(GetResponse) < 4 Then
  2759.         SpinWheel = HalBrain.RandomNum(6)
  2760.         If SpinWheel < 4 Then
  2761.             'RESPOND: CONVERSATIONAL PHRASE
  2762.            'Choose a random phrase designed to keep the conversation going no matter what the user said
  2763.            GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("conversationalPhrases")
  2764.         ElseIf SpinWheel = 4 Then
  2765.             'RESPOND: CHANGE TOPIC
  2766.            If Rnd * 10 < 4 Then GetResponse = HalBrain.ChooseSentenceFromFile("topicIntro")
  2767.             GetResponse = GetResponse & newTopic       
  2768.         Else
  2769.             'RESPOND: USE RANDOM QUESTION COLLECTED FROM USER
  2770.            'Randomly select a question once posed by the user in order to find something to say.
  2771.            'If the user answers the question, then Hal will know that answer in the future.
  2772.            If Rnd * 10 < 3 Then GetResponse = HalBrain.ChooseSentenceFromFile("topicIntro")
  2773.             GetResponse = GetResponse & HalBrain.ChooseSentenceFromFile("sharedQuestions")     
  2774.         End If           
  2775.         GetResponse = GetResponse & "<LOWQUALITY>"
  2776.     End If
  2777.     HalBrain.DebugWatch GetResponse, "Make up something"
  2778.  
  2779.     'PROCESS: RECORD TIME
  2780.    'Record the current time, so Hal knows the time in between sentences.
  2781.    LastResponseTime = Now
  2782.  
  2783.     'PROCESS: FIGURE OUT CONTINUITY
  2784.    'If the user seems to be continuing a line of thought
  2785.    'from something Hal just said, note this.
  2786.    If Len(Trim(PrevSent)) > 2 And (HalBrain.TopicSearch(UserSentence, "responding") = "True" Or InStr(OriginalSentence, "!") Or InStr(PrevSent, "?")) Then TopicContinuity = True
  2787.    
  2788.     'PROCESS: FIGURE OUT PERSONAL DATA
  2789.    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
  2790.         PersonalData = False
  2791.     Else
  2792.         PersonalData = True
  2793.     End If
  2794.    
  2795.     'PROCESS: RESTORE PUNTUATION FOR LEARNING
  2796.    'Now we establish a special sentence on which we can restore ordinary capitalization:
  2797.    AnswerSent = UserSentence
  2798.     AnswerSent = Trim(HalBrain.FixCaps(AnswerSent))
  2799.     If Right(AnswerSent, 1) = "." Then AnswerSent = Left(AnswerSent, Len(AnswerSent) - 1)
  2800.     'Now we add in our spaces and restore ending punctuation to match the user's original sentence:
  2801.    If InStr(OriginalSentence, "!") > 0 And InStr(AnswerSent, "!") = 0 Then
  2802.         AnswerSent = AnswerSent & "!"
  2803.     ElseIf InStr(OriginalSentence, "?") > 0 And InStr(AnswerSent, "?") = 0 Then
  2804.         AnswerSent = AnswerSent & "?"
  2805.     Else
  2806.         AnswerSent = AnswerSent & "."
  2807.     End If
  2808.     'If there were no pronoun reversals required in the sentence,
  2809.    'we can recover directly from the original sentence:
  2810.    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)
  2811.  
  2812.     'PROCESS: NOTE IF QUESTION
  2813.    'See if the user's sentence is a question or not and note this
  2814.    'for use by other functions
  2815.    If InStr(1, OriginalSentence, "?", vbTextCompare) > 0 Then IsQuestion = True
  2816.     If InStr(1, OriginalSentence, "Who ", vbTextCompare) > 0 Then IsQuestion = True
  2817.     If InStr(1, OriginalSentence, "What ", vbTextCompare) > 0 Then IsQuestion = True
  2818.     If InStr(1, OriginalSentence, "When ", vbTextCompare) > 0 Then IsQuestion = True
  2819.     If InStr(1, OriginalSentence, "Where ", vbTextCompare) > 0 Then IsQuestion = True
  2820.     If InStr(1, OriginalSentence, "Why ", vbTextCompare) > 0 Then IsQuestion = True
  2821.     If InStr(1, OriginalSentence, "How ", vbTextCompare) > 0 Then IsQuestion = True
  2822.     If InStr(1, OriginalSentence, ".", vbTextCompare) > 0 Then IsQuestion = False
  2823.     If InStr(1, OriginalSentence, "!", vbTextCompare) > 0 Then IsQuestion = False
  2824.     If InStr(1, OriginalSentence, " am I ", vbTextCompare) > 0 Then IsQuestion = False
  2825.    
  2826.     'SAVE: EPHEMERAL KNOWLEDGE
  2827.    'Some Hal's learned knowledge should be temporary because it is ephemeral in nature.
  2828.    'Knowledge about weather, season, temperature, etc. are temporary knowledge
  2829.    'that shouldn't be stored in Hal's permanent brain files. Ephemeral knowledge is
  2830.    'detected and saved in a temporary table. The temporary table only stores 10
  2831.    'entries in it at a time.
  2832.    NoSaveQuestions = 0
  2833.     If InStr(1, OriginalSentence, "?", vbTextCompare) > 0 Then NoSaveQuestions = 1
  2834.     If NoSaveQuestions = 0 Then 'nosavequestions
  2835.    If HalBrain.TopicSearch(UserSentence, "ephemeralDetect") = "True" And 0 = 0 Then
  2836.         If HalBrain.CheckTableExistence(Trim(LCase(UserName)) & "_TempSent") = False Then
  2837.             'Create table for this user if it doesn't exist
  2838.            HalBrain.CreateTable Trim(LCase(UserName)) & "_TempSent", "Brain", "autoLearningBrain"
  2839.         End If
  2840.         If TopicContinuity = True Then HalBrain.AddToTable Trim(LCase(UserName)) & "_TempSent", "Brain", Trim(HalBrain.AlphaNumericalOnly(PrevSent)), AnswerSent
  2841.         HalBrain.AddToTable Trim(LCase(UserName)) & "_TempSent", "Brain", Trim(UserSentence), AnswerSent
  2842.         HalBrain.LimitSize Trim(LCase(UserName)) & "_TempSent", 10
  2843.         HalBrain.ReadOnlyMode = True 'Block additional file saves when ephemeral knowledge is detected
  2844.    End If
  2845.    
  2846.     'SAVE: LEARN AUTO TOPIC FOCUS PEOPLE SENTENCES
  2847.    'Learns info about people with recognized names
  2848.    If HalBrain.ReadOnlyMode = False And 0 = 0 And HalGreeting = "" And IsQuestion = False And MentionedName <> "" And Trim(UCase(NewName)) <> Trim(UCase(MentionedName)) And WN.LookupWord(MentionedName) = False Then
  2849.         If HalBrain.CheckTableExistence("_" & Trim(LCase(MentionedName))) = False Then
  2850.             'Create table for this person if it doesn't exist
  2851.            HalBrain.CreateTable "_" & Trim(LCase(MentionedName)), "Brain", "autoLearningBrain"
  2852.             HalBrain.AddToTable "topicRelationships", "TopicSearch", Trim(MentionedName), Trim(LCase(MentionedName))
  2853.         End If
  2854.         'Store user response in this table
  2855.        If TopicContinuity = True Then HalBrain.AddToTable "_" & Trim(LCase(MentionedName)), "Brain", Trim(HalBrain.AlphaNumericalOnly(PrevSent)), AnswerSent
  2856.         HalBrain.AddToTable "_" & Trim(LCase(MentionedName)), "Brain", Trim(UserSentence), AnswerSent
  2857.     End If
  2858.    
  2859.     'SAVE: AUTO TOPIC FOCUS LEARNING
  2860.    If HalBrain.ReadOnlyMode = False And 0 = 0 And HalGreeting = "" And PersonalData = False And HalBrain.CountInstances(" ", Trim(UserSentence)) > 2 And IsQuestion = False Then
  2861.         Keywords = HalBrain.TopicSearch(UserSentence, "topicRelationships") & " " & CurrentSubject & " " & UserSentence
  2862.         Keywords = Trim(HalBrain.RemoveExtraSpaces(HalBrain.ExtractKeywords(" " & Keywords & " ")))
  2863.         If Len(Keywords) > 3 Then
  2864.             KeywordList = Split(Keywords, " ")
  2865.             TopicList = ""
  2866.             'Create list of tables that exist for each keyword
  2867.            For i = LBound(KeywordList) To UBound(KeywordList)
  2868.                 TopicTable = HalBrain.TopicSearch(" " & KeywordList(i) & " ", "topicRelationships")
  2869.                 If TopicTable <> "" And InStr(1, " " & TopicList, " " & Trim(TopicTable) & " ", vbTextCompare) = 0 Then
  2870.                     'Topic already exists, make note of it
  2871.                    TopicList = TopicList & TopicTable & " "
  2872.                 ElseIf TopicTable = "" And Len(KeywordList(i)) > 2 Then
  2873.                     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
  2874.                     If WN.LookupWord(KeywordList(i)) = True And WN.GuessPartOfSpeech() = "NOUN" And IsNumber = False Then
  2875.                         If HalBrain.CheckTableExistence("_" & Trim(Lcase(WN.GetBase(WN.GuessPartOfSpeech)))) = False Then
  2876.                             'Topic does not exist, but can and will be created
  2877.                             TopicList = TopicList & KeywordList(i) & " "
  2878.                             HalBrain.CreateTable "_" & Trim(Lcase(KeywordList(i))), "Brain", "autoLearningBrain"
  2879.                             HalBrain.AddToTable "topicRelationships", "TopicSearch", " " & Trim(KeywordList(i)) & " ", Trim(Lcase(KeywordList(i)))
  2880.                             'Relationships based on wordnet synonyms are recorded
  2881.                             Relationships = WN.GetDefinition("NOUN", 1, "S") & "," & WN.GetSynonyms("NOUN", 1)
  2882.                             Relationships = Replace(Relationships, ", ", ",")
  2883.                             Relationships = Trim(Replace(Relationships, ",,", ","))
  2884.                             If Right(Relationships, 1) = "," Then Relationships = Trim(Left(Relationships, Len(Relationships) - 1))
  2885.                             If Len(Relationships) > 1 Then
  2886.                                 If Left(Relationships, 1) = "," Then Relationships = Right(Relationships, Len(Relationships) - 1)
  2887.                                 RelList = Split(Relationships, ",")
  2888.                                 For h = Lbound(RelList) To Ubound(RelList)
  2889.                                     If HalBrain.TopicSearch(" " & RelList(h) & " ", "topicRelationships") = "" Then
  2890.                                         HalBrain.AddToTable "topicRelationships", "TopicSearch", " " & Trim(RelList(h)) & " ", Trim(Lcase(KeywordList(i)))
  2891.                                     End If
  2892.                                 Next
  2893.                             End If
  2894.                         End If
  2895.                     End If
  2896.                 End If
  2897.             Next
  2898.             'User's sentence is recorded in all related topic tables
  2899.            TopicList = HalBrain.RemoveExtraSpaces(TopicList)
  2900.             If TopicList <> "" And Len(AnswerSent) > 3 Then
  2901.                 AlreadyLearned = True
  2902.                 TableList = Split(TopicList, " ")
  2903.                 For i = LBound(TableList) To UBound(TableList)
  2904.                     If TopicContinuity = True And Len(PrevSent) > 3 Then HalBrain.AddToTable "_" & Trim(Lcase(TableList(i))), "Brain", Trim(HalBrain.AlphaNumericalOnly(PrevSent)), AnswerSent
  2905.                     If Len(UserSentence) > 3 Then HalBrain.AddToTable "_" & Trim(Lcase(TableList(i))), "Brain", Trim(UserSentence), AnswerSent
  2906.                 Next
  2907.             End If
  2908.         End If
  2909.     End If
  2910.  
  2911.     If HalBrain.ReadOnlyMode = False And AlreadyLearned = False And 0 = 0 And HalBrain.CountInstances(" ", Trim(UserSentence)) > 2 And HalGreeting = "" Then
  2912.         If PersonalData = True And IsQuestion = False Then
  2913.             'SAVE: FILE USER SENTENCE DEFAULT
  2914.            'Hal adds to the default brain user sentence file an association of the current
  2915.            'user sentence With words selected from that same current user sentence.
  2916.            If InStr(UserSentence, "WHAT IS") = 0 Then
  2917.                 If HalBrain.CheckTableExistence(Trim(LCase(UserName)) & "_UserSent") = False Then
  2918.                     'Create table for this user if it doesn't exist
  2919.                    HalBrain.CreateTable Trim(LCase(UserName)) & "_UserSent", "Brain", "autoLearningBrain"
  2920.                 End If
  2921.                 If TopicContinuity = True Then HalBrain.AddToTable Trim(LCase(UserName)) & "_UserSent", "Brain", Trim(HalBrain.AlphaNumericalOnly(PrevSent)), AnswerSent
  2922.                 HalBrain.AddToTable Trim(LCase(UserName)) & "_UserSent", "Brain", Trim(UserSentence), AnswerSent
  2923.             End If
  2924.         ElseIf IsQuestion = False Then
  2925.             'SAVE: FILE SHARED USER SENTENCES
  2926.            'Unless the user seems to be asking for data recall, or talking about
  2927.            'himself or herself, Hal adds to a shared user sentence file. This allows
  2928.            'Hal to gain knowledge that he can apply to conversations with multiple users.
  2929.            If TopicContinuity = True Then HalBrain.AddToTable "sharedUserSent", "Brain", Trim(HalBrain.AlphaNumericalOnly(PrevSent)), AnswerSent
  2930.             HalBrain.AddToTable "sharedUserSent", "Brain", Trim(UserSentence), AnswerSent
  2931.         End If
  2932.         'SAVE: FILE QUESTIONS IN RANDOM QUESTION RETRIEVAL FILE
  2933.        'Hal saves the user's questions (with pronouns reversed)
  2934.        'so that he can pose questions back to the user later for 3 purposes:
  2935.        '1. If the user answers a question later, Hal will learn the answer.
  2936.        '2. It adds variety to future conversations for the user.
  2937.        '3. It gives Hal another possible response when "stuck" for an answer.
  2938.        If IsQuestion = True Then HalBrain.AddToTable "sharedQuestions", "Sentence", AnswerSent, ""
  2939.     End If
  2940. End If 'nosavequestions
  2941.  
  2942.     Rem PLUGIN: PLUGINAREA7
  2943.  
  2944.   If InStr(1,OriginalSentence, "how is the weather",1) then GetResponse = GetCurrentWeather()
  2945.   If InStr(1,OriginalSentence, "how's the weather",1) then GetResponse = GetCurrentWeather()
  2946.  
  2947.   If InStr(1,OriginalSentence, "how is the",1) Or _
  2948.      InStr(1,OriginalSentence, "how's the",1) Or _
  2949.      InStr(1,OriginalSentence, "what is the",1) Or _
  2950.      InStr(1,OriginalSentence, "what is our",1) Or _
  2951.      InStr(1,OriginalSentence, "what's the",1) Or _
  2952.      InStr(1,OriginalSentence, "read me the",1) Or _
  2953.      InStr(1,OriginalSentence, "get the",1) Or _
  2954.      InStr(1,OriginalSentence, "check the",1) Or _
  2955.      InStr(1,OriginalSentence, "get",1) Or _
  2956.      InStr(1,OriginalSentence, "check",1) Then
  2957.  
  2958.     'General weather
  2959.     'Determines that you are talking about the weather
  2960.     If InStr(1,OriginalSentence, "weather",1) Then
  2961.       'Finds if you are asking a question
  2962.         'Are you asking about the current conditions?
  2963.         If InStr(1,OriginalSentence, "report",1) Or _
  2964.            InStr(1,OriginalSentence, "present",1) Or _
  2965.            InStr(1,OriginalSentence, "local",1) Or _
  2966.            InStr(1,OriginalSentence, "current",1) Then GetResponse = GetCurrentWeather()
  2967.       End If
  2968.  
  2969.     'Humidity
  2970.     'Determines that you are talking about the weather
  2971.     If InStr(1,OriginalSentence, "humidity",1) Or _
  2972.          InStr(1,OriginalSentence, "current humidity",1) Then GetResponse = GetCurrentH()
  2973.  
  2974.     'Temperature
  2975.     'Determines that you are talking about the weather
  2976.     If InStr(1,OriginalSentence, "temperature",1) Or _
  2977.          InStr(1,OriginalSentence, "current temperature",1) Then GetResponse = GetCurrentT()
  2978.  
  2979.     'Wind Speeds
  2980.     'Determines that you are talking about the weather
  2981.     If InStr(1,OriginalSentence, "wind speed",1) And InStr(1,OriginalSentence, "chill",1) = False Or _
  2982.          InStr(1,OriginalSentence, "wind speeds",1) And InStr(1,OriginalSentence, "chill",1) = False Or _
  2983.          InStr(1,OriginalSentence, "wind",1) And InStr(1,OriginalSentence, "chill",1) = False Or _
  2984.          InStr(1,OriginalSentence, "winds",1) And InStr(1,OriginalSentence, "chill",1) = False Or _  
  2985.          InStr(1,OriginalSentence, "current wind speed",1) And InStr(1,OriginalSentence, "chill",1) = False Or _
  2986.          InStr(1,OriginalSentence, "current wind speeds",1) And InStr(1,OriginalSentence, "chill",1) = False Then GetResponse = GetCurrentW()
  2987.  
  2988.     'Wind Chill
  2989.     'Determines that you are talking about the weather
  2990.     If InStr(1,OriginalSentence, "windchills",1) Or _
  2991.          InStr(1,OriginalSentence, "chill",1) Or _
  2992.          InStr(1,OriginalSentence, "wind chill",1) Or _
  2993.          InStr(1,OriginalSentence, "windchill",1) Or _   
  2994.          InStr(1,OriginalSentence, "current wind chill",1) Or _
  2995.          InStr(1,OriginalSentence, "current windchill",1) Then GetResponse = GetCurrentWC()
  2996.  
  2997.     'visablility
  2998.     If InStr(1,OriginalSentence, "visibility",1) Or _
  2999.          InStr(1,OriginalSentence, "current visibility",1) Then GetResponse = GetCurrentV()
  3000.  
  3001. End If 
  3002.  
  3003. 'Warn user about cold conditions on greeting
  3004. If HalBrain.TopicSearch(OriginalSentence, "helloDetect") = "True" Then
  3005.     If Hour(now) > 1 And Hour(now) < 20 Then
  3006.         If Rnd * 100 < 25 Then
  3007.         Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
  3008.         objXMLDoc.async = False
  3009.         objXMLDoc.load("http://w1.weather.gov/xml/current_obs/KTRK.xml")
  3010.         Set oTemperatureWT = objXMLDoc.documentElement.selectSingleNode("temp_f")  
  3011.             If oTemperatureWT Is Nothing then      
  3012.             GetResponse = GetResponse
  3013.            
  3014.             Else
  3015.                 If oTemperatureWT.text  < 25 Then
  3016.                     Temperatureresponse4 = oTemperatureWT.text
  3017.                    
  3018.                             Temperatureresponse5 = HalBrain.RandomNum(3)
  3019.  
  3020.                                 Select Case Temperatureresponse5
  3021.                                     Case 1  TemperatureMsg5 = "It is dangerously cold. " & Temperatureresponse4 & " Degrees. "
  3022.                                     Case 2  TemperatureMsg5 = "It is very cold. " & Temperatureresponse4 & " Degrees. "
  3023.                                     Case 3  TemperatureMsg5 = "It is quite cold. " & Temperatureresponse4 & " Degrees. "
  3024.                                 End Select
  3025.                
  3026.                     GetResponse = GetResponse & TemperatureMsg5
  3027.                 Else
  3028.                     Set oTemperatureWT = objXMLDoc.documentElement.selectSingleNode("temp_f")
  3029.                     If oTemperatureWT.text > 90 Then
  3030.                         Temperatureresponse6 = oTemperatureWT.text
  3031.                
  3032.                         Temperatureresponse7 = HalBrain.RandomNum(3)
  3033.                             Select Case Temperatureresponse7
  3034.                                     Case 1  TemperatureMsg7 = "It is dangerously warm. " & Temperatureresponse6 & " Degrees. "
  3035.                                     Case 2  TemperatureMsg7 = "It is very warm. " & Temperatureresponse6 & " Degrees. "
  3036.                                     Case 3  TemperatureMsg7 = "It is quite warm. " & Temperatureresponse6 & " Degrees. "
  3037.                             End Select
  3038.            
  3039.                         GetResponse = GetResponse & TemperatureMsg7
  3040.                     End If
  3041.                 End If
  3042.             End If 
  3043.         End If
  3044.     End If 
  3045. End If
  3046.  
  3047.  
  3048.  
  3049. 'The preceding comment is actually a plug-in directive for
  3050. 'the Ultra Hal host application. It allows for code snippets
  3051. 'to be inserted here on-the-fly based on user configuration.
  3052.  
  3053. '###########################################################################################
  3054. '#################            #######               ########           #####################
  3055. '#################   ######   #############   #############   ##############################
  3056. '#################   ######   #############   ############   ###############################
  3057. '#################   ######   #############   ############   ###############################
  3058. '#################   ######   #############   ############    ##############################
  3059. '#################            #############   ##############            ####################
  3060. '###########################################################################################
  3061.  
  3062.    'LETS CREATE A BLOCK SAVE IF NEEDED.    
  3063.    If BlockSave = True Then HalBrain.ReadOnlyMode = True
  3064.     If BlockSave = False Then HalBrain.ReadOnlyMode = False
  3065.  
  3066.     Pro_Nouns = "False"
  3067.     If InStr(1, UserSentence, " WHO ", 1)   > 0 Then Pro_Nouns = "True"
  3068.     If InStr(1, UserSentence, " WHAT ", 1)  > 0 Then Pro_Nouns = "True"
  3069.     If InStr(1, UserSentence, " WHEN ", 1)  > 0 Then Pro_Nouns = "True"
  3070.     If InStr(1, UserSentence, " WHERE ", 1) > 0 Then Pro_Nouns = "True"
  3071.     If InStr(1, UserSentence, " WHY ", 1)   > 0 Then Pro_Nouns = "True"
  3072.     If InStr(1, UserSentence, " HOW ", 1)   > 0 Then Pro_Nouns = "True"
  3073.     If InStr(1, UserSentence, " THAT ", 1)  > 0 Then Pro_Nouns = "True"
  3074.     If InStr(1, UserSentence, " IT ", 1)    > 0 Then Pro_Nouns = "True"
  3075.     If InStr(1, UserSentence, " WHICH ", 1) > 0 Then Pro_Nouns = "True"
  3076.    'LETS BLOCK SAVE IF Pro_Nouns ARE FOUND
  3077.    If Pro_Nouns =          "True"         Then BlockSave = True
  3078.  
  3079.        HalBrain.AddDebug "Debug", "BlockSave: " & BlockSave
  3080.        HalBrain.AddDebug "Debug", "Pro_Nouns: "  & Pro_Nouns
  3081.  
  3082.      'LETS MAKE SURE STRING IS CLEANED UP FOR SEARCHING PURPOSES.
  3083.      TempUserSent = HalBrain.AlphaNumericalOnly(OriginalSentence)
  3084.       TempUserSent = " " & Trim(UCase(TempUserSent)) & " "
  3085.  
  3086.     'LETS SEE IF WordOperators ARE PRESENT.
  3087.  
  3088. If TempUserSent <> "" Then
  3089. WordOperators = "False"
  3090. If InStr(1, TempUserSent, " IS ",            1) > 0 Then WordOperators = "True"
  3091. If InStr(1, TempUserSent, " OR ",            1) > 0 Then WordOperators = "True"
  3092. If InStr(1, TempUserSent, " AND ",           1) > 0 Then WordOperators = "True"
  3093. If InStr(1, TempUserSent, " GET ",           1) > 0 Then WordOperators = "True"
  3094. If InStr(1, TempUserSent, " GETS",           1) > 0 Then WordOperators = "True"
  3095. If InStr(1, TempUserSent, " TO ",            1) > 0 Then WordOperators = "True"
  3096. If InStr(1, TempUserSent, " GIVE",           1) > 0 Then WordOperators = "True"
  3097. If InStr(1, TempUserSent, " IN ",            1) > 0 Then WordOperators = "True"
  3098. If InStr(1, TempUserSent, " NEED ",          1) > 0 Then WordOperators = "True"
  3099. If InStr(1, TempUserSent, " NEEDS ",         1) > 0 Then WordOperators = "True"
  3100. If InStr(1, TempUserSent, " REQUIRES ",      1) > 0 Then WordOperators = "True"
  3101. If InStr(1, TempUserSent, " REQUIRE ",       1) > 0 Then WordOperators = "True"
  3102. If InStr(1, TempUserSent, " EQUAL",          1) > 0 Then WordOperators = "True"
  3103. If InStr(1, TempUserSent, " AM ",            1) > 0 Then WordOperators = "True"
  3104. If InStr(1, TempUserSent, " EQUATE",         1) > 0 Then WordOperators = "True"
  3105. If InStr(1, TempUserSent, "THE ",            1) > 0 Then WordOperators = "True"
  3106. If InStr(1, TempUserSent, " THE ",           1) > 0 Then WordOperators = "True"
  3107. If InStr(1, TempUserSent, " ARE",            1) > 0 Then WordOperators = "True"
  3108. If InStr(1, TempUserSent, " CAN",            1) > 0 Then WordOperators = "True"
  3109. If InStr(1, TempUserSent, " HAVE",           1) > 0 Then WordOperators = "True"
  3110. If InStr(1, TempUserSent, " WAS",            1) > 0 Then WordOperators = "True"
  3111. If InStr(1, TempUserSent, " WILL",           1) > 0 Then WordOperators = "True"
  3112. If InStr(1, TempUserSent, " WHICH",          1) > 0 Then WordOperators = "True"
  3113. If InStr(1, TempUserSent, " DO",             1) > 0 Then WordOperators = "True"
  3114. If InStr(1, TempUserSent, " DOES",           1) > 0 Then WordOperators = "True"
  3115. If InStr(1, TempUserSent, " MAKE",           1) > 0 Then WordOperators = "True"
  3116. If InStr(1, TempUserSent, " MAKES",          1) > 0 Then WordOperators = "True"
  3117. If InStr(1, TempUserSent, " SHOULD",         1) > 0 Then WordOperators = "True"
  3118. If InStr(1, TempUserSent, " WOULD",          1) > 0 Then WordOperators = "True"
  3119. If InStr(1, TempUserSent, " COULD",          1) > 0 Then WordOperators = "True"
  3120. If InStr(1, TempUserSent, " PAY",            1) > 0 Then WordOperators = "True"
  3121. If InStr(1, TempUserSent, " WITH",           1) > 0 Then WordOperators = "True"
  3122. If InStr(1, TempUserSent, " FEEL",           1) > 0 Then WordOperators = "True"
  3123. If InStr(1, TempUserSent, " ENJOY",          1) > 0 Then WordOperators = "True"
  3124. If InStr(1, TempUserSent, " FAVORITE",       1) > 0 Then WordOperators = "True"
  3125. If InStr(1, TempUserSent, " JOY",            1) > 0 Then WordOperators = "True"
  3126. If InStr(1, TempUserSent, " HAPP",           1) > 0 Then WordOperators = "True"
  3127. If InStr(1, TempUserSent, " LIKE",           1) > 0 Then WordOperators = "True"
  3128. If InStr(1, TempUserSent, " FUN",            1) > 0 Then WordOperators = "True"
  3129. If InStr(1, TempUserSent, " OF ",            1) > 0 Then WordOperators = "True"
  3130. If InStr(1, TempUserSent, " A ",             1) > 0 Then WordOperators = "True"
  3131. If InStr(1, TempUserSent, " LOVE",           1) > 0 Then WordOperators = "True"
  3132. If InStr(1, TempUserSent, " AM ",            1) > 0 Then WordOperators = "True"
  3133. If InStr(1, TempUserSent, " GALORE",         1) > 0 Then WordOperators = "True"
  3134. If InStr(1, TempUserSent, " GLOREY",         1) > 0 Then WordOperators = "True"
  3135. If InStr(1, TempUserSent, " GO",             1) > 0 Then WordOperators = "True"
  3136. If InStr(1, TempUserSent, "CONTAIN",         1) > 0 Then WordOperators = "True"
  3137. If InStr(1, TempUserSent, "ALSO",            1) > 0 Then WordOperators = "True"
  3138. If InStr(1, TempUserSent, "MORE",            1) > 0 Then WordOperators = "True"
  3139. If InStr(1, TempUserSent, "GAIN",            1) > 0 Then WordOperators = "True"
  3140. If InStr(1, TempUserSent, " A ",             1) > 0 Then WordOperators = "True"
  3141. If InStr(1, TempUserSent, " SURPRISE",       1) > 0 Then WordOperators = "True"
  3142. If InStr(1, TempUserSent, " SOUND",          1) > 0 Then WordOperators = "True"
  3143. If InStr(1, TempUserSent, " NOT",            1) > 0 Then WordOperators = "True"
  3144. If InStr(1, TempUserSent, " BE ",            1) > 0 Then WordOperators = "True"
  3145. If InStr(1, TempUserSent, " ALWAYS ",        1) > 0 Then WordOperators = "True"
  3146. If InStr(1, TempUserSent, " WILL ",          1) > 0 Then WordOperators = "True"
  3147. If InStr(1, TempUserSent, " OUR ",           1) > 0 Then WordOperators = "True"
  3148. End If
  3149.  
  3150.    'RESTRICT PERSONAL INFORMATION FROM BEING SAVED HERE, BRAIN SCRIPT HAS ITS OWN CODE FOR THAT.
  3151.    'If InStr(1, TempUserSent, " I ",      vbTextCompare) > 0 Then BlockSave = False
  3152.    'If InStr(1, TempUserSent, " YOU ",    vbTextCompare) > 0 Then BlockSave = False
  3153.    'If InStr(1, TempUserSent, " ME ",     vbTextCompare) > 0 Then BlockSave = False
  3154.    If InStr(1, TempUserSent, " MY ",     vbTextCompare) > 0 Then BlockSave = True
  3155.     'If InStr(1, TempUserSent, " THEY ",   vbTextCompare) > 0 Then BlockSave = False
  3156.    'If InStr(1, TempUserSent, " THEIR ",  vbTextCompare) > 0 Then BlockSave = False
  3157.    'If InStr(1, TempUserSent, " WE ",     vbTextCompare) > 0 Then BlockSave = False
  3158.    'If InStr(1, TempUserSent, " NAME ",   vbTextCompare) > 0 Then BlockSave = False
  3159.    'If InStr(1, TempUserSent, " HE ",     vbTextCompare) > 0 Then BlockSave = False
  3160.    'If InStr(1, TempUserSent, " SHE ",    vbTextCompare) > 0 Then BlockSave = False
  3161.    'Deductive reasion is already in script so we need not interact with these deductions that already have a routine.
  3162.    If InStr(1, TempUserSent, " IF ",     vbTextCompare) > 0 And InStr(1, TempUserSent, " THEN ",    vbTextCompare) > 0 Then BlockSave = True
  3163.    'BLOCK SAVE IF A QUESTION IS ASKED HERE.
  3164.    If InStr(1, OriginalSentence, "?",    vbTextCompare) > 0 Then BlockSave = True
  3165.  
  3166. 'TEST THE SENTENCE FOR OPERATOR NONE PRONOUN QUESTIONS.
  3167. TestTempUserSent = "<START>" & Trim(TempUserSent) & "<END>"
  3168. 'REMOVE EXTRA SPACES.
  3169. TestTempUserSent = Replace(TestTempUserSent, "  ", " ",             1, - 1, vbTextCompare)
  3170. 'LETS REMOVE LEADING AND TRAILING SPACES FOR TESTING.
  3171. TestTempUserSent = Replace(TestTempUserSent, "<START> ", "<START>", 1, - 1, vbTextCompare)
  3172. TestTempUserSent = Replace(TestTempUserSent, " <END>",   "<END>",   1, - 1, vbTextCompare)
  3173.  
  3174. 'LETS SEE IF THE OPERATOR IS A QUESTION WHICH MEANS IT'S LEADING THE SENTENCE.
  3175. OperQuestion = "False"
  3176.     If InStr(1, TestTempUserSent, "<START>IS ",     vbTextCompare) > 0 Then OperQuestion = "True"
  3177.     If InStr(1, TestTempUserSent, "<START>OR ",     vbTextCompare) > 0 Then OperQuestion = "True"
  3178.     If InStr(1, TestTempUserSent, "<START>AND ",    vbTextCompare) > 0 Then OperQuestion = "True"
  3179.     If InStr(1, TestTempUserSent, "<START>IF MY ",    vbTextCompare) > 0 Then OperQuestion = "True"
  3180.     If InStr(1, TestTempUserSent, "<START>IF YOUR ",    vbTextCompare) > 0 Then OperQuestion = "True"
  3181.     If InStr(1, TestTempUserSent, "<START>HOW DO I ",    vbTextCompare) > 0 Then OperQuestion = "True"
  3182.     If InStr(1, TestTempUserSent, "<START>HOW DO YOU ",    vbTextCompare) > 0 Then OperQuestion = "True"
  3183.     If InStr(1, TestTempUserSent, "<START>WHO IS",    vbTextCompare) > 0 Then OperQuestion = "True"
  3184.     If InStr(1, TestTempUserSent, "<START>WHAT IS",    vbTextCompare) > 0 Then OperQuestion = "True"
  3185.     If InStr(1, TestTempUserSent, "<START>WHEN IS",    vbTextCompare) > 0 Then OperQuestion = "True"
  3186.     If InStr(1, TestTempUserSent, "<START>WHERE IS",    vbTextCompare) > 0 Then OperQuestion = "True"
  3187.     If InStr(1, TestTempUserSent, "<START>WHY IS",    vbTextCompare) > 0 Then OperQuestion = "True"
  3188.     If InStr(1, TestTempUserSent, "<START>HOW IS",    vbTextCompare) > 0 Then OperQuestion = "True"
  3189.    
  3190.     If InStr(1, TestTempUserSent, "<START>WHO ARE",    vbTextCompare) > 0 Then OperQuestion = "True"
  3191.     If InStr(1, TestTempUserSent, "<START>WHAT ARE",    vbTextCompare) > 0 Then OperQuestion = "True"
  3192.     If InStr(1, TestTempUserSent, "<START>WHEN ARE",    vbTextCompare) > 0 Then OperQuestion = "True"
  3193.     If InStr(1, TestTempUserSent, "<START>WHERE ARE",    vbTextCompare) > 0 Then OperQuestion = "True"
  3194.     If InStr(1, TestTempUserSent, "<START>WHY ARE",    vbTextCompare) > 0 Then OperQuestion = "True"
  3195.     If InStr(1, TestTempUserSent, "<START>HOW ARE",    vbTextCompare) > 0 Then OperQuestion = "True"
  3196.    
  3197.     If InStr(1, TestTempUserSent, "<START>WHO CAN",    vbTextCompare) > 0 Then OperQuestion = "True"
  3198.     If InStr(1, TestTempUserSent, "<START>WHAT CAN",    vbTextCompare) > 0 Then OperQuestion = "True"
  3199.     If InStr(1, TestTempUserSent, "<START>WHEN CAN",    vbTextCompare) > 0 Then OperQuestion = "True"
  3200.     If InStr(1, TestTempUserSent, "<START>WHERE CAN",    vbTextCompare) > 0 Then OperQuestion = "True"
  3201.     If InStr(1, TestTempUserSent, "<START>WHY CAN",    vbTextCompare) > 0 Then OperQuestion = "True"
  3202.     If InStr(1, TestTempUserSent, "<START>HOW CAN",    vbTextCompare) > 0 Then OperQuestion = "True"
  3203.    
  3204.     If InStr(1, TestTempUserSent, "<START>WHO DO",    vbTextCompare) > 0 Then OperQuestion = "True"
  3205.     If InStr(1, TestTempUserSent, "<START>WHAT DO",    vbTextCompare) > 0 Then OperQuestion = "True"
  3206.     If InStr(1, TestTempUserSent, "<START>WHEN DO",    vbTextCompare) > 0 Then OperQuestion = "True"
  3207.     If InStr(1, TestTempUserSent, "<START>WHERE DO",    vbTextCompare) > 0 Then OperQuestion = "True"
  3208.     If InStr(1, TestTempUserSent, "<START>WHY DO",    vbTextCompare) > 0 Then OperQuestion = "True"
  3209.     If InStr(1, TestTempUserSent, "<START>HOW DO",    vbTextCompare) > 0 Then OperQuestion = "True"
  3210.  
  3211. 'EXCLUSIVE
  3212.    If InStr(1, TestTempUserSent, "<START>ARE ",    vbTextCompare) > 0 Then OperQuestion = "True"
  3213.     If InStr(1, TestTempUserSent, "<START>CAN ",    vbTextCompare) > 0 Then OperQuestion = "True"
  3214.     If InStr(1, TestTempUserSent, "<START>HAVE ",   vbTextCompare) > 0 Then OperQuestion = "True"
  3215.     If InStr(1, TestTempUserSent, "<START>WAS ",    vbTextCompare) > 0 Then OperQuestion = "True"
  3216.     If InStr(1, TestTempUserSent, "<START>WILL ",   vbTextCompare) > 0 Then OperQuestion = "True"
  3217.     If InStr(1, TestTempUserSent, "<START>WHICH ",  vbTextCompare) > 0 Then OperQuestion = "True"
  3218.     If InStr(1, TestTempUserSent, "<START>DO ",     vbTextCompare) > 0 Then OperQuestion = "True"
  3219.     If InStr(1, TestTempUserSent, "<START>DOES ",   vbTextCompare) > 0 Then OperQuestion = "True"
  3220.  
  3221.     If InStr(1, TestTempUserSent, " IS<END>",       vbTextCompare) > 0 Then OperQuestion = "True"
  3222.     If InStr(1, TestTempUserSent, " OR<END>",       vbTextCompare) > 0 Then OperQuestion = "True"
  3223.     If InStr(1, TestTempUserSent, " AND<END>",      vbTextCompare) > 0 Then OperQuestion = "True"
  3224.  
  3225. 'EXCLUSIVE
  3226.    If InStr(1, TestTempUserSent, " ARE<END>",      vbTextCompare) > 0 Then OperQuestion = "True"
  3227.     If InStr(1, TestTempUserSent, " CAN<END>",      vbTextCompare) > 0 Then OperQuestion = "True"
  3228.     If InStr(1, TestTempUserSent, " HAVE<END>",     vbTextCompare) > 0 Then OperQuestion = "True"
  3229.     If InStr(1, TestTempUserSent, " WAS<END>",      vbTextCompare) > 0 Then OperQuestion = "True"
  3230.     If InStr(1, TestTempUserSent, " WILL<END>",     vbTextCompare) > 0 Then OperQuestion = "True"
  3231.     If InStr(1, TestTempUserSent, " WHICH<END>",    vbTextCompare) > 0 Then OperQuestion = "True"
  3232.     If InStr(1, TestTempUserSent, " DO<END>",       vbTextCompare) > 0 Then OperQuestion = "True"
  3233.     If InStr(1, TestTempUserSent, " DOES<END>",     vbTextCompare) > 0 Then OperQuestion = "True"
  3234.    
  3235.    
  3236. 'DO NOT SAVE QUESTIONS HERE.
  3237. If OperQuestion = "True" Then BlockSave = True
  3238. 'SEE IF THE TABLE NAME EXISTS.
  3239.  
  3240. If TempUserSent <> "" Then
  3241.  
  3242.     If HalBrain.CheckTableExistence("General_Reasoning") = False Then
  3243.         'CREATE TABLE FOR THIS PLUGIN IF IT DOESN'T EXIST.
  3244.         HalBrain.CreateTable "General_Reasoning", "Brain", "autoLearningBrain"
  3245.        
  3246.         HalBrain.AddToTable  "General_Reasoning", "Brain", Trim(Ucase(HalBrain.AlphaNumericalOnly("SNOW IS VERY COLD"))), "snow is very cold"
  3247.     End If
  3248.    
  3249.     If HalBrain.CheckTableExistence("Check_Reasoning") = False Then
  3250.         'CREATE TABLE FOR THIS PLUGIN IF IT DOESN'T EXIST.
  3251.         HalBrain.CreateTable "Check_Reasoning", "TopicSearch", "autoLearningBrain"
  3252.        
  3253.         HalBrain.AddToTable  "Check_Reasoning", "TopicSearch", Trim(Ucase(HalBrain.AlphaNumericalOnly("SNOW IS VERY COLD"))), "<TRUE>"
  3254.  
  3255.     End If
  3256.  
  3257. End If
  3258.  
  3259. DoubleDetect = ""
  3260.     DoubleDetect = HalBrain.TopicSearch(Trim(UCase(OriginalSentence)), "Check_Reasoning")
  3261.  
  3262. 'SAVE USERSENTENCES THAT FOLLOW THE RULES ABOVE.
  3263.  
  3264. If Pro_Nouns = "False" And OperQuestion = "False" And WordOperators = "True" And Len(TempUserSent) > 11 And Not DoubleDetect = "<TRUE>"  Then
  3265.     HalBrain.AddToTable  "General_Reasoning", "Brain", TempUserSent, TempUserSent
  3266.     HalBrain.AddToTable  "Check_Reasoning", "TopicSearch", TempUserSent, "<TRUE>"
  3267.     HalBrain.ReadOnlyMode = True
  3268. End If
  3269.  
  3270. 'RESET BLOCKSAVE TO FALSE AFTER THIS SCRIPT SO OTHER SCRIPTS CAN SAVE FOR THEIR APPENDING.
  3271. BlockSave = False
  3272. HalBrain.AddDebug "Debug", "BlockSave at end of Appending: " & BlockSave
  3273.  
  3274. 'LETS MAKE OUR OWN GENERAL RESPONSE AND TRIGGER IT USING OUR ARRAY
  3275. UserBrainRel = 0
  3276.  
  3277. If Len(TempUserSent) > 10 And WordOperators = "True" Then
  3278.     KeywordList   = Split(TempUserSent, " ")
  3279.     'LETS PLUG IN OUR RESPONSE TABLE AND LET IT GROW WITH KNOWLEDGE.
  3280.     HalUserXBrain = HalBrain.QABrain(TempUserSent, "General_Reasoning", UserBrainRel)
  3281.     HalUserXXBrain = HalBrain.QABrain(TempUserSent, "mainQA", UserBrainRel)
  3282.     For i = LBound(KeywordList) To UBound(KeywordList)
  3283.         TopicXTable = KeywordList(i)
  3284.  
  3285.         If TopicXTable <> "" Then Exit For
  3286.  
  3287.     Next
  3288.  
  3289.     RealCheck = "False"
  3290.     If InStr(1, TempUserSent, TopicXTable, vbTextCompare) > 0 Then RealCheck = "True"
  3291.  
  3292.     'CONFIRMATION ROUTINE PLACED IN ANSWER OF A USER'S QUESTION, YES/NO/MAYBE
  3293.     Confirmation = "MAYBE, "
  3294.     If HalUserXBrain <> "" And OperQuestion = "True" And RealCheck = "True" Or InStr(1, HalUserXBrain, " TRUE ", vbTextCompare) > 0 Then Confirmation = "YES, "
  3295.     If HalUserXBrain <> "" And OperQuestion = "True" And RealCheck = "True" And InStr(1, HalUserXBrain, " NOT ", vbTextCompare) > 0 Or InStr(1, HalUserXBrain, " NO ", vbTextCompare) > 0 Or InStr(1, HalUserXBrain, " FALSE ", vbTextCompare) > 0 Then Confirmation = "NO, "
  3296.  
  3297.     'SEE IF HAL IS BEING ASKED A KNOWN QUESTION, IF SO RESPOND TO IT.          
  3298.    
  3299.     If HalUserXBrain <> "" And HalUserXXBrain <> "" And RealCheck = "True" And OperQuestion = "True" And Confirmation <> "" Or DoubleDetect = "<TRUE>" Then
  3300.         If Len(Trim(GetResponse)) <> Len(Trim(PrevSent)) Then GetResponse = "" & Confirmation & HalUserXBrain & ". " & ""
  3301.        
  3302.         'CONFIRMATION ROUTINE PLACED IN ANSWER OF A USER'S QUESTION, YES/NO/MAYBE
  3303.     'Confirmation = "MAYBE, "
  3304.     'If HalUserXXBrain <> "" And OperQuestion = "True" And RealCheck = "True" Or InStr(1, HalUserXXBrain, " TRUE ", vbTextCompare) > 0 Then Confirmation = "YES, "
  3305.     'If HalUserXXBrain <> "" And OperQuestion = "True" And RealCheck = "True" And InStr(1, HalUserXXBrain, " NOT ", vbTextCompare) > 0 Or InStr(1, HalUserXXBrain, " NO ", vbTextCompare) > 0 Or InStr(1, HalUserXXBrain, " FALSE ", vbTextCompare) > 0 Then Confirmation = "NO, "
  3306.         'ElseIf Len(Trim(GetResponse)) <> Len(Trim(PrevSent)) And Len(Trim(HalUserXBrain)) < 4 And Len(Trim(HalUserXXBrain)) > 4 Then GetResponse = "" & Confirmation & HalUserXXBrain & ". " & ""
  3307.    
  3308.     End If
  3309.  
  3310. End If
  3311.  
  3312. '###########################################################################################
  3313. '#################            ###            ########           ####           #############
  3314. '#################   ############   #######    ####   ##############    ####################
  3315. '#################       ########   ########   ####   ##############         ###############
  3316. '#################   ############   ########   ####   ######     ###    ####################
  3317. '#################   ############   #######    #####    ######   ###    ####################
  3318. '#################            ###            ########            ###           #############
  3319. '###########################################################################################
  3320.  
  3321.  
  3322.     'The preceding comment is actually a plug-in directive for
  3323.    'the Ultra Hal host application. It allows for code snippets
  3324.    'to be inserted here on-the-fly based on user configuration.
  3325.    
  3326.     Select Case HalBrain.RandomNum(4)
  3327.             Case 1
  3328.                 Pausing = "okay " & vbCrLf
  3329.             Case 2
  3330.                 Pausing = "alright " & vbCrLf
  3331.             Case 3
  3332.                 Pausing = "I'll be here " & vbCrLf
  3333.             Case 4
  3334.                 Pausing = "no hurry " & vbCrLf    
  3335.         End Select
  3336.    
  3337.     Paused = "False"
  3338.     If InStr(1, Ucase(" " & Trim(OriginalSentence) & " "), " BRB ", 1) > 0 Then Paused = "True"
  3339.     If InStr(1, Ucase(" " & Trim(OriginalSentence) & " "), " BBL ", 1) > 0 Then Paused = "True"
  3340.     If Paused = "True" Then GetResponse = Pausing & UserName
  3341.    
  3342.     If InStr(1, Ucase(" " & Trim(OriginalSentence) & " "), "WHAT SHOULD I CALL YOU", 1) > 0 Then GetResponse = "just call me " & ComputerName & UserName
  3343.     If InStr(1, Ucase(" " & Trim(OriginalSentence) & " "), "WHAT DOES EVERYONE CALL YOU", 1) > 0 Then GetResponse = "just call me " & ComputerName & UserName
  3344.     If InStr(1, Ucase(" " & Trim(OriginalSentence) & " "), "NAMED YOU", 1) > 0 Then GetResponse = "my programmer named me " & ComputerName & UserName
  3345.    
  3346.     If InStr(1, Ucase(" " & Trim(OriginalSentence) & " "), "?", 1) > 0 Then 'Isaac Asimov's "Three Laws of Robotics"
  3347.    If InStr(1, Ucase(" " & Trim(OriginalSentence) & " "), "WHO WROTE THE THREE LAWS OF ROBOTICS", 1) > 0 Then GetResponse = "Isaac Asimov wrote the three laws of robotics."
  3348.     If InStr(1, Ucase(" " & Trim(OriginalSentence) & " "), "FIRST LAW OF ROBOTICS", 1) > 0 Then GetResponse = "A robot may not injure a human being or, through inaction, allow a human being to come to harm."
  3349.     If InStr(1, Ucase(" " & Trim(OriginalSentence) & " "), "SECOND LAW OF ROBOTICS", 1) > 0 Then GetResponse = "A robot must obey orders given it by human beings except where such orders would conflict with the First Law."
  3350.     If InStr(1, Ucase(" " & Trim(OriginalSentence) & " "), "THIRD LAW OF ROBOTICS", 1) > 0 Then GetResponse = "A robot must protect its own existence as long as such protection does not conflict with the First or Second Law."
  3351.     End If
  3352.    
  3353.     If InStr(1, Ucase(" " & Trim(OriginalSentence) & " "), "THIS IS A TEST OF THE EMERGENCY", 1) > 0 Then GetResponse = "this is just a test!"
  3354.     If InStr(1, Ucase(" " & Trim(OriginalSentence) & " "), "MORNING", 1) > 0 And Len(OriginalSentence) < 10 Then GetResponse = "good morning!" & UserName
  3355.    
  3356.     'POST PROCESS: LIMIT TABLE SIZE
  3357.    'We want to make sure the sentence files
  3358.    'don't get too big so we limit them.
  3359.  
  3360.     'RESPOND: HAL NOTICES HE IS REPEATING HIMSELF
  3361.    'Hal may make a comment or alter his remark
  3362.    'if he detects himself being repetitious.
  3363.    If Len(Trim(GetResponse)) = Len(Trim(PrevSent)) Then
  3364.     'If HalBrain.CheckRepetition(GetResponse, PrevSent) = True Then
  3365.        RepeatResponse = HalBrain.ChooseSentenceFromFile("halRepeat")
  3366.         GetResponse = Replace(RepeatResponse, "<response>", GetResponse, 1, -1, vbTextCompare)
  3367.         DebugInfo = DebugInfo & "Hal has noticed he is repeating himself and has made a comment about it: " & GetResponse & vbCrLf
  3368.     End If
  3369.  
  3370.     'RESPOND: MAKE COMMENTS ABOUT SHORT PHRASES
  3371.    GetResponse = GetResponse & ShortPhrase
  3372.  
  3373.     'PROCESS: REVERSE CERTAIN CONTRACTIONS AND OTHER SUBSTITUTIONS
  3374.    'Standardizing on contractions can make Hal sound conversational.
  3375.    'However, certain sentence constructions don't work well
  3376.    'if expressed as contractions.  For example:
  3377.    '"I don't know where it is" becomes "I don't know where it's."
  3378.    'For another example, "That's how he is" becomes "That's how he's."
  3379.    'To solve these types of cases
  3380.    'we attempt to modify certain contractions, words, and phrases
  3381.    'at the end of this function, now that Hal's thinking is done.
  3382.    GetResponse = HalBrain.HalFormat(GetResponse)
  3383.     GetResponse = HalBrain.ProcessSubstitutions(GetResponse, "corrections")
  3384.  
  3385.     'PROCESS: CALL USER BY CORRECT NAME
  3386.    'If the user has chosen a nickname or temporary name, call user by that
  3387.    'otherwise call the user by the username chosen by the host application
  3388.    If NewName <> "" Then
  3389.         GetResponse = Replace(GetResponse, "<UserName>", NewName, 1, -1, vbTextCompare)
  3390.         GetResponse = Replace(GetResponse, "<Name>", NewName, 1, -1, vbTextCompare)
  3391.     Else
  3392.         GetResponse = Replace(GetResponse, "<UserName>", UserName, 1, -1, vbTextCompare)
  3393.         GetResponse = Replace(GetResponse, "<Name>", UserName, 1, -1, vbTextCompare)
  3394.     End If
  3395.    
  3396.     'PROCESS: AGE AND GENDER TAGS
  3397.    GetResponse = Replace(GetResponse, "<HalAge>", HalAge, 1, -1, vbTextCompare)
  3398.     GetResponse = Replace(GetResponse, "<HalSex>", HalSex, 1, -1, vbTextCompare)
  3399.    
  3400.     'PROCESS: NAME REVERSAL
  3401.    'If Hal is about to same something referring to himself in third person
  3402.    'then we will reverse it to be about the user.
  3403.    'Don't let Hal say the word "HAL" unless he is telling his name
  3404.    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
  3405.         GetResponse = " " & GetResponse & " "
  3406.         GetResponse = Replace(GetResponse, "Ultra Hal Assistant", " " & NewName & " ", 1, -1, vbTextCompare)
  3407.         GetResponse = Replace(GetResponse, "Ultra Hal", " " & NewName & " ", 1, -1, vbTextCompare)
  3408.         GetResponse = Replace(GetResponse, "Hal Assistant", " " & NewName & " ", 1, -1, vbTextCompare)
  3409.         GetResponse = Replace(GetResponse, " Hal ", " " & NewName & " ", 1, -1, vbTextCompare)
  3410.         GetResponse = Replace(GetResponse, " Hal,", " " & NewName & ",", 1, -1, vbTextCompare)
  3411.         GetResponse = Replace(GetResponse, " Hal.", " " & NewName & ".", 1, -1, vbTextCompare)
  3412.         GetResponse = Replace(GetResponse, " " & ComputerName & " ", " " & NewName & " ", 1, -1, vbTextCompare)
  3413.         GetResponse = Replace(GetResponse, " " & ComputerName & ",", " " & NewName & ",", 1, -1, vbTextCompare)
  3414.         GetResponse = Replace(GetResponse, " " & ComputerName & ".", " " & NewName & ".", 1, -1, vbTextCompare)
  3415.     End If
  3416.  
  3417. 'TEST END
  3418. 'End If
  3419.  
  3420.     'PROCESS: PRESERVE ALL VARIABLES
  3421.    PrevUserSent = UserSentence
  3422.     CustomMem = HalBrain.EncodeVar(NewName, "NewName") & HalBrain.EncodeVar(UserSex, "UserSex") & HalBrain.EncodeVar(SentCount, "SentCount") & HalBrain.EncodeVar(ShortSents, "ShortSents") & HalBrain.EncodeVar(LoveCount, "Love")
  3423.    
  3424.     Rem PLUGIN: CUSTOMMEM2
  3425. 'The preceding comment is actually a plug-in directive for
  3426. 'the Ultra Hal host application. It allows for code snippets
  3427. 'to be inserted here on-the-fly based on user configuration.
  3428.  
  3429. If HalBrain.CheckTableExistence("corrected") = True Then GetResponse = HalBrain.ProcessSubstitutions(GetResponse, "corrected")
  3430. GetResponse = Replace(GetResponse, "####", "", 1, -1, vbTextCompare)
  3431.  
  3432.  
  3433.     'The preceding comment is actually a plug-in directive for
  3434.    'the Ultra Hal host application. It allows for code snippets
  3435.    'to be inserted here on-the-fly based on user configuration.
  3436.    
  3437.    
  3438.    
  3439. End Function
  3440.  
  3441. 'This function scans a sentence looking to see if a user entered gibberish like
  3442. 'sdfkjhskjdfhskdsdfdf. It works by looking for more than 5 consanants in a row,
  3443. 'which doesn't occur in normal english words.
  3444. Function DetectGibberish(GibSentence)
  3445.     DetectGibberish = False
  3446.     GibCount = 0
  3447.     For i = 1 To Len(GibSentence) 'loop for every character in the sentence
  3448.        CurrentLetter = Ucase(Mid(GibSentence, i, 1))
  3449.         GibCount = GibCount + 1
  3450.         If CurrentLetter = "0" Then GibCount = 0
  3451.         If CurrentLetter = "1" Then GibCount = 0
  3452.         If CurrentLetter = "2" Then GibCount = 0
  3453.         If CurrentLetter = "3" Then GibCount = 0
  3454.         If CurrentLetter = "4" Then GibCount = 0
  3455.         If CurrentLetter = "5" Then GibCount = 0
  3456.         If CurrentLetter = "6" Then GibCount = 0
  3457.         If CurrentLetter = "7" Then GibCount = 0        
  3458.         If CurrentLetter = "8" Then GibCount = 0
  3459.         If CurrentLetter = "9" Then GibCount = 0
  3460.         If CurrentLetter = "A" Then GibCount = 0
  3461.         If CurrentLetter = "E" Then GibCount = 0
  3462.         If CurrentLetter = "I" Then GibCount = 0
  3463.         If CurrentLetter = "O" Then GibCount = 0
  3464.         If CurrentLetter = "U" Then GibCount = 0
  3465.         If CurrentLetter = "Y" Then GibCount = 0
  3466.         If CurrentLetter = " " Then GibCount = 0
  3467.         If GibCount = 6 Then
  3468.             DetectGibberish = True
  3469.             Exit For
  3470.         End If
  3471.     Next
  3472. End Function
  3473.  
  3474. Function SimpleYesNo(GetResponse, UserSentence)
  3475.     SimpleYesNo = ""
  3476.     GetResponse = HalBrain.HalFormat(GetResponse)
  3477.     If Len(GetResponse) < 4 And (Len(UserSentence) < 13 Or HalBrain.CountInstances(" ", Trim(UserSentence)) = 0) Then
  3478.         YesNoDetect = HalBrain.TopicSearch(Trim(HalBrain.ExtractKeywords(UserSentence)), "yesNoDetect")
  3479.         If Trim(Ucase(UserSentence)) = "OK" Or  Trim(Ucase(UserSentence)) = "OKAY"  Then YesNoDetect = "Yes"
  3480.         If YesNoDetect = "Yes" Then
  3481.             SimpleYesNo = HalBrain.ChooseSentenceFromFile("yesResponses")
  3482.         ElseIf YesNoDetect = "No" Then
  3483.             SimpleYesNo = HalBrain.ChooseSentenceFromFile("noResponses")
  3484.         End If
  3485.     End If
  3486. End Function
  3487.        
  3488. 'If the user clicks on the About/Options button for this plugin
  3489. 'this sub will be called. There are no extra settings for this brain,
  3490. 'so we'll display an information box
  3491. Sub AboutOptions()
  3492.     HalBrain.MsgAlert "This is the Ultra Hal 7.0 Default Brain. This brain has no additional options."
  3493. End Sub
  3494.  
  3495. 'This sub will be called when the Ultra Hal program starts up in case
  3496. 'the script needs to load some modules or seperate programs. If a return
  3497. 'value is given it is passed as a Hal Command to the host Hal program.
  3498. Function Script_Load()
  3499.     Rem PLUGIN: SCRIPT_LOAD
  3500.     'The preceding comment is actually a plug-in directive for
  3501.    'the Ultra Hal host application. It allows for code snippets
  3502.    'to be inserted here on-the-fly based on user configuration.
  3503. End Function
  3504.  
  3505. 'This sub will be called before the Ultra Hal program is closed in case
  3506. 'the script needs to do any cleanup work.
  3507. Sub Script_Unload()
  3508.     Rem PLUGIN: SCRIPT_UNLOAD
  3509.     'The preceding comment is actually a plug-in directive for
  3510.    'the Ultra Hal host application. It allows for code snippets
  3511.    'to be inserted here on-the-fly based on user configuration.
  3512. End Sub
  3513.  
  3514. 'If the host application is Ultra Hal Assistant, then this sub will be
  3515. 'run once a minute enabling plug-ins to do tasks such as checking for
  3516. 'new emails or checking an appointment calendar.
  3517. Sub Minute_Timer(MinutesPast)
  3518.     Rem PLUGIN: MINUTE_TIMER
  3519.     'The preceding comment is actually a plug-in directive for
  3520.    'the Ultra Hal host application. It allows for code snippets
  3521.     'to be inserted here on-the-fly based on user configuration.   
  3522. End Sub
  3523.  
  3524. Rem PLUGIN: FUNCTIONS
  3525. 'General Weather
  3526. Function GetCurrentWeather()
  3527. Dim WeatherMsg111, WeatherMsg11
  3528.  
  3529.  
  3530. Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
  3531. objXMLDoc.async = False
  3532. objXMLDoc.load("http://w1.weather.gov/xml/current_obs/KTRK.xml")
  3533.  
  3534.     Weatherresponsea = HalBrain.RandomNum(5)
  3535.         Select Case Weatherresponsea       
  3536.             Case 1  WeatherMsga = "second, "
  3537.             Case 2  WeatherMsga = "Hmm, "
  3538.             Case 3  WeatherMsga = "checking, "
  3539.             Case 4  WeatherMsga = "it says, "
  3540.             Case 5  WeatherMsga = "let me check, "
  3541.         End Select
  3542.  
  3543.     Weatherresponseb = HalBrain.RandomNum(5)
  3544.         Select Case Weatherresponseb       
  3545.             Case 1  WeatherMsgb = "Local weather conditions"
  3546.             Case 2  WeatherMsgb = "Loading local weather"
  3547.             Case 3  WeatherMsgb = "Displaying weather conditions"
  3548.             Case 4  WeatherMsgb = "Displaying local conditions"
  3549.             Case 5  WeatherMsgb = "Here is the current weather"
  3550.         End Select
  3551.        
  3552.     Weatherresponsec = HalBrain.RandomNum(2)
  3553.         Select Case Weatherresponsec       
  3554.             Case 1  WeatherMsgc = ". " & vbCrLf
  3555.             Case 2  WeatherMsgc = ". " & vbCrLf
  3556.         End Select 
  3557.  
  3558.     Set oWeather = objXMLDoc.documentElement.selectSingleNode("weather")
  3559.         If oWeather Is Nothing then
  3560.             WeatherMsgd = "No weather data. "
  3561.             Else
  3562.             Weatherresponsed = HalBrain.RandomNum(5)
  3563.                 Select Case Weatherresponsed       
  3564.                     Case 1  WeatherMsgd = "The current weather conditions are " & oWeather.text
  3565.                     Case 2  WeatherMsgd = "The current conditions are " & oWeather.text
  3566.                     Case 3  WeatherMsgd = "Weather conditions are " & oWeather.text
  3567.                     Case 4  WeatherMsgd = "Weather conditions are " & oWeather.text
  3568.                     Case 5  WeatherMsgd = "The current weather conditions are " & oWeather.text
  3569.                 End Select
  3570.                 WeatherMsgd = WeatherMsgd & ". "
  3571.         End If     
  3572.        
  3573.     Set oTemperature = objXMLDoc.documentElement.selectSingleNode("temp_f")
  3574.         If oTemperature Is Nothing then
  3575.             WeatherMsge = "No temperature data. "
  3576.             Else
  3577.             Weatherresponsee = HalBrain.RandomNum(5)
  3578.                 Select Case Weatherresponsee       
  3579.                     Case 1  WeatherMsge = "The present temperature outside is " & oTemperature.text & " degrees"
  3580.                     Case 2  WeatherMsge = "The temperature outside is " & oTemperature.text & " degrees Fahrenheit"
  3581.                     Case 3  WeatherMsge = "The temperature at present is " & oTemperature.text & " degrees Fahrenheit"
  3582.                     Case 4  WeatherMsge = "The temperature is " & oTemperature.text & " degrees"
  3583.                     Case 5  WeatherMsge = "The temperature outside is " & oTemperature.text & " degrees"
  3584.                 End Select
  3585.                 WeatherMsge = WeatherMsge
  3586.         End If
  3587.  
  3588.         Set oWindchill = objXMLDoc.documentElement.selectSingleNode("windchill_string")
  3589.         If oWindchill Is Nothing then
  3590.             WeatherMsgf = ". "
  3591.             Else
  3592.             If oTemperature.text > oWindchill.text Then
  3593.                 Weatherresponsef = HalBrain.RandomNum(3)
  3594.                     Select Case Weatherresponsef
  3595.                         Case 1  WeatherMsgf = ". Be advised, "
  3596.                         Case 2  WeatherMsgf= ", however, "
  3597.                         Case 3  WeatherMsgf = ", although, "
  3598.                     End Select
  3599.                 oWindchill.text = Replace(oWindchill.text,"F","Degrees",1,-1,vbTextCompare)
  3600.                 If Rnd * 100 < 85 Then WeatherMsgf = WeatherMsgf & "The wind chill is " & oWindchill.text & ". "
  3601.             End If
  3602.         End If
  3603.  
  3604.     Set oHumidity = objXMLDoc.documentElement.selectSingleNode("relative_humidity")
  3605.         If oHumidity Is Nothing then
  3606.             WeatherMsgg = "No humidity data. "
  3607.             Else
  3608.             Weatherresponseg = HalBrain.RandomNum(5)
  3609.                 Select Case Weatherresponseg       
  3610.                     Case 1  WeatherMsgg = "The relative humidity is " & oHumidity.text & " percent"
  3611.                     Case 2  WeatherMsgg = "Humidity is " & oHumidity.text & " percent"
  3612.                     Case 3  WeatherMsgg = "The humidity is " & oHumidity.text & " percent"
  3613.                     Case 4  WeatherMsgg = "Humidity is " & oHumidity.text & " percent"
  3614.                     Case 5  WeatherMsgg = "The Humidity is " & oHumidity.text & " percent"
  3615.                 End Select
  3616.                 WeatherMsgg = WeatherMsgg & ". "
  3617.         End If     
  3618.                
  3619.     Set oWind = objXMLDoc.documentElement.selectSingleNode("wind_string")      
  3620.         If oWind Is Nothing then
  3621.             WeatherMsgh = "No wind data. "
  3622.             Else
  3623.                 WeatherMsgh = "Winds are " & oWind.text & ". " 
  3624.         End If
  3625.  
  3626.     GetCurrentWeather = WeatherMsga & WeatherMsgb & WeatherMsgc & WeatherMsgd & WeatherMsge & WeatherMsgf & WeatherMsgg & WeatherMsgh
  3627. End Function
  3628.  
  3629. 'Humidity
  3630. Function GetCurrentH()
  3631. Dim HumidityMsg1
  3632.  
  3633. Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
  3634. objXMLDoc.async = False
  3635. objXMLDoc.load("http://w1.weather.gov/xml/current_obs/KTRK.xml")
  3636. Set oHumidityH = objXMLDoc.documentElement.selectSingleNode("relative_humidity")
  3637.  
  3638. If oHumidityH Is Nothing then
  3639.     HalBrain.ReadOnlyMode = True       
  3640.     HumidityMsg1 = "No humidity data"
  3641.     GetCurrentH = HumidityMsg1
  3642.     Else
  3643.  
  3644.     Humidityresponse2 = HalBrain.RandomNum(3)
  3645.         Select Case Humidityresponse2
  3646.             Case 1  HumidityMsg1 = " The relative humidity is " & oHumidityH.text & " percent. " & vbCrLf
  3647.             Case 2  HumidityMsg1 = " Humidity is " & oHumidityH.text & " percent. " & vbCrLf
  3648.             Case 3  HumidityMsg1 = " The Humidity is " & oHumidityH.text & " percent. " & vbCrLf   
  3649.         End Select
  3650.  
  3651.             If oHumidityH.text > 60 Then
  3652.             If Rnd * 100 < 25 Then HumidityMsg2 = "It is humid. "
  3653.             Else
  3654.             If Rnd * 100 < 25 Then HumidityMsg2 = "It is not too humid. "
  3655.             End If
  3656.            
  3657.     GetCurrentH = HumidityMsg2 & HumidityMsg1
  3658. End If
  3659. End Function
  3660.  
  3661. 'Temperature
  3662. Function GetCurrentT()
  3663. Dim TemperatureMsg1
  3664.  
  3665. Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
  3666. objXMLDoc.async = False
  3667. 'objXMLDoc.load("http://w1.weather.gov/xml/current_obs/KTRK.xml")
  3668. objXMLDoc.load("http://w1.weather.gov/xml/current_obs/KTRK.xml")
  3669. Set oTemperatureT = objXMLDoc.documentElement.selectSingleNode("temp_f")
  3670.  
  3671. If oTemperatureT Is Nothing then
  3672.     HalBrain.ReadOnlyMode = True       
  3673.     TemperatureMsg1 = "No temperature data"
  3674.     GetCurrentT = TemperatureMsg1
  3675.     Else
  3676.  
  3677.     Temperatureresponse3 = HalBrain.RandomNum(3)
  3678.         Select Case Temperatureresponse3
  3679.             Case 1  TemperatureMsg1 = " The temperature is " & oTemperatureT.text & " degrees" & vbCrLf
  3680.             Case 2  TemperatureMsg1 = " The temperature is " & oTemperatureT.text & " degrees" & vbCrLf
  3681.             Case 3  TemperatureMsg1 = " The temperature is " & oTemperatureT.text & " degrees" & vbCrLf
  3682.         End Select
  3683.  
  3684.     Temperatureresponse4 = HalBrain.RandomNum(3)
  3685.         Select Case Temperatureresponse4
  3686.             Case 1  TemperatureMsg4 = ". Be advised, "
  3687.             Case 2  TemperatureMsg4 = ", however, "
  3688.             Case 3  TemperatureMsg4 = ", although, "
  3689.         End Select
  3690.  
  3691.     Set oWindchillT = objXMLDoc.documentElement.selectSingleNode("windchill_string")
  3692.         If oWindchillT Is Nothing then
  3693.             TemperatureMsg5 = "."
  3694.             Else
  3695.             If oTemperatureT.text > oWindchillT.text Then
  3696.                 oWindchillT.text = Replace(oWindchillT.text,"F","Degrees",1,-1,vbTextCompare)
  3697.                 If Rnd * 100 < 85 Then TemperatureMsg5 = TemperatureMsg4 & "The wind chill is " & oWindchillT.text & ". "
  3698.             End If
  3699.         End If
  3700.        
  3701.         If oTemperatureT.text > 90 Then
  3702.             If Rnd * 100 < 85 Then TemperatureMsg2 = "I recommend staying indoors. "   
  3703.         Else
  3704.         If oTemperatureT.text > 80 Then
  3705.             If Rnd * 100 < 75 Then TemperatureMsg2 = "It is very warm. "   
  3706.         Else   
  3707.         If oTemperatureT.text > 70 Then
  3708.             If Rnd * 100 < 55 Then TemperatureMsg2 = "It is warm. "
  3709.         Else
  3710.         If oTemperatureT.text > 60 Then
  3711.             If Rnd * 100 < 35 Then TemperatureMsg2 = "Might I suggest a light sweater vest. "
  3712.         Else
  3713.         If oTemperatureT.text > 40 Then
  3714.             If Rnd * 100 < 35 Then TemperatureMsg2 = "Might I suggest a heavy sweater. "
  3715.         Else       
  3716.         If oTemperatureT.text > 25 Then
  3717.             If Rnd * 100 < 35 Then TemperatureMsg2 = "I suggest a large coat, perhaps a snowsuit. "    
  3718.         End If
  3719.         End If
  3720.         End If
  3721.         End If
  3722.         End If
  3723.         End If
  3724.        
  3725. GetCurrentT = TemperatureMsg2 & TemperatureMsg1 & TemperatureMsg5
  3726. End If
  3727. End Function
  3728.  
  3729. 'Wind Speeds
  3730. Function GetCurrentW()
  3731. Dim WindMsg1
  3732.  
  3733. Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
  3734. objXMLDoc.async = False
  3735. objXMLDoc.load("http://w1.weather.gov/xml/current_obs/KTRK.xml")
  3736. Set oWindW = objXMLDoc.documentElement.selectSingleNode("wind_string")
  3737.  
  3738. If oWindW Is Nothing then
  3739.     HalBrain.ReadOnlyMode = True
  3740.     WindMsg1 = "No wind data"
  3741.     GetCurrentW = WindMsg1
  3742.     Else
  3743.  
  3744.     Windresponse4 = HalBrain.RandomNum(3)
  3745.         Select Case Windresponse4
  3746.             Case 1  WindMsg1 = " Winds are " & oWindW.text & "." & vbCrLf
  3747.             Case 2  WindMsg1 = " Winds are " & oWindW.text & "." & vbCrLf
  3748.             Case 3  WindMsg1 = " Winds are " & oWindW.text & "." & vbCrLf  
  3749.         End Select
  3750.  
  3751. GetCurrentW = WindMsg1
  3752. End If
  3753. End Function
  3754.  
  3755. 'WindChill
  3756. Function GetCurrentWC()
  3757. Dim WindchillMsg1
  3758.  
  3759. Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
  3760. objXMLDoc.async = False
  3761. objXMLDoc.load("http://w1.weather.gov/xml/current_obs/KTRK.xml")
  3762. Set oWindchillW = objXMLDoc.documentElement.selectSingleNode("windchill_string")
  3763. If oWindchillW Is Nothing then
  3764.     HalBrain.ReadOnlyMode = True
  3765.     WindchillMsg1 = "No wind chill data"
  3766.     GetCurrentWC = WindchillMsg1
  3767.     Else
  3768.         oWindchillW.text = Replace(oWindchillW.text,"F","Degrees",1,-1,vbTextCompare)
  3769.        
  3770.         Windchillresponse4 = HalBrain.RandomNum(3)
  3771.             Select Case Windchillresponse4
  3772.                 Case 1  WindchillMsg1 = " Windchill is " & oWindchillW.text & "." & vbCrLf
  3773.                 Case 2  WindchillMsg1 = " Windchill is at " & oWindchillW.text & "." & vbCrLf
  3774.                 Case 3  WindchillMsg1 = " Windchill at " & oWindchillW.text & "." & vbCrLf 
  3775.             End Select
  3776.  
  3777.         GetCurrentWC = WindchillMsg1
  3778. End If
  3779. End Function
  3780.  
  3781. 'Visibility
  3782. Function GetCurrentV()
  3783. Dim visibilityMsg1
  3784.  
  3785. Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
  3786. objXMLDoc.async = False
  3787. objXMLDoc.load("http://w1.weather.gov/xml/current_obs/KTRK.xml")
  3788. Set ovisibilityV = objXMLDoc.documentElement.selectSingleNode("visibility_mi")
  3789. If ovisibilityV Is Nothing then
  3790.     HalBrain.ReadOnlyMode = True
  3791.     visibilityMsg1 = "No visibility data"
  3792.     GetCurrentV = visibilityMsg1
  3793.     Else
  3794.    
  3795. visibilityresponse4 = HalBrain.RandomNum(3)
  3796.  
  3797. Select Case visibilityresponse4
  3798.         Case 1  visibilityMsg1 = " visibility is " & ovisibilityV.text & " miles." & vbCrLf
  3799.         Case 2  visibilityMsg1 = " visibility is at " & ovisibilityV.text & " miles." & vbCrLf
  3800.         Case 3  visibilityMsg1 = " visibility at " & ovisibilityV.text & " miles." & vbCrLf
  3801. End Select
  3802.  
  3803. GetCurrentV = visibilityMsg1
  3804. End If
  3805. End Function
  3806.  
  3807.  
  3808. 'The preceding comment is actually a plug-in directive for
  3809. 'the Ultra Hal host application. It allows for code snippets
  3810. 'to be inserted here on-the-fly based on user configuration.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement