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