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