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