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