Advertisement
Guest User

Untitled

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