--------------------------------------------------------------------------------
•Plugin basics
This first part sets up the file. When it is read, these commands tell the HalAssistant what to do with the file.
Rem Type=Plugin as opposed to "brain"
Rem Name=My Cool Plugin the name that people will see in the checklist
Rem Author=Captain Blasto your name
Rem Host=Assistant the program intended to use it
This next part puts the information in the "General Options / Brain" dialog and shows up when the plugin is checked. Further down in teh script you will make the actual lables and buttons. Much of this is standard VBS rather than HalScript commands.
'This sub setups the plug-ins option panel in Hal's options dialog
Sub OptionsPanel() the options panel looks for this name
lblPlugin(0).Caption = "AI Appointment Book:"
lblPlugin(0).Move 120, 120
lblPlugin(0).Visible = True
cmdPlugin(0).Caption = "View/Edit Appointment Book"
cmdPlugin(0).Move 520, 480, 2600, 375
cmdPlugin(0).Visible = True
cmdPlugin(1).Caption = "Edit User Defined Events"
cmdPlugin(1).Move 520, 980, 2600, 375
cmdPlugin(1).Visible = True
End Sub
Here is a short list of plugin ports Page ToolsInsert linksInsert links to other pages or uploaded files.
Pages Images and files Insert a link to a new pageLoading...No images or files uploaded yet.Insert image from URLTip: To turn text into a link, highlight the text, then click on a page or file from the list above.
Rem_PLUGIN Area Name Your Plugin can send messages to the script at these ports
Rem PLUGIN: AUTO-IDLE This port is inside the AutoIdle process and probably should end with "Exit Function"
Rem PLUGIN: PRE-PROCESS This one is immediately before the begining of the sentence manipulations. Use it if you want to by-pass the emotions and such and go directly to fixing the sentence structure for Hal's use.
Rem PLUGIN: POST-PROCESS Use this one if you want to skip fixing the sentence
Rem PLUGIN: CUSTOMMEM Ya got me! There's a CustomMem variable in the UltraHal function, but I haven't gotten into it yet.
Rem PLUGIN: PLUGINAREA1 This is after Hal tries to get the Topic, but before parsing out Names. Other than that...?
Rem PLUGIN: PLUGINAREA2 After dictionary and before Ziggy Spellbot(Did I add this?)
Rem PLUGIN: PLUGINAREA3 This is after main DB searches and some analytical stuff like antecedences
Rem PLUGIN: PLUGINAREA4 By now Hal is already trying to form a response
Rem PLUGIN: PLUGINAREA5 Just before some more or less random responses are made(if needed) I suspect this is where my TreknoBabble should go so as to make a response before it gets this far.
Rem PLUGIN: PLUGINAREA6 ...or here. This is just before it actually tries to make something out of nothing.
Rem PLUGIN: PLUGINAREA7 I think this is just before the final dressing up of the response.
Rem PLUGIN: CUSTOMMEM2 Again, I don't know what this one is. I suspect that since I don't know, it is very important and obvious.
Rem PLUGIN: SCRIPT_LOAD You can load a script on startup if you need to...
Rem PLUGIN: SCRIPT_UNLOAD ... then unload it here.
Rem PLUGIN: MINUTE_TIMER Hal runs this once a minute
Rem PLUGIN: FUNCTIONS If you make any functions they should be tabbed to this... I think...
--------------------------------------------------------------------------------
•Plugins under construction
---------------------------------------------------------------------------------
•HalBrainCommands raw
Here are code snippets relating to HalBrain that I swiped from Hal6.uhp
I will try to annotate them as I learn about them, but if anyone has any input, please contact me via the forums and we can include your comments.
HalBrain.StoreVars(HalCommands
HalBrain.ReadOnlyMode = True
HalBrain.AddDebug "Debug", "Ultra Hal Start"
TempParent = HalBrain.AddDebug("Debug", "Begin Processing Sentence " & CStr(i + 1), vbCyan)
HalBrain.AddDebug TempParent, "Sentence: " & Sentences(i)
HalBrain.DebugWatch "", "NewSent"
HalBrain.ExtractVar(CustomMem, "NextResponse")
HalBrain.TopicSearch(InputString2, "yesNoDetect")
HalBrain.SearchPattern(UltraHal, "***", 2)
HalBrain.EncodeVar(NextResponse, "NextResponse")
HalBrain.FixCaps(HalBrain.HalFormat(UltraHal))
HalBrain.HalFormat(UltraHal)
HalBrain.AlphaNumericalOnly(UserSentence)
HalBrain.SwitchPerson(UserSentence)
HalBrain.ProcessSubstitutions(UserSentence, "substitutions")
HalBrain.ChooseSentenceFromFile("userRepeat") & vbCrLf
HalBrain.RunQuery("SELECT searchString, topic FROM names WHERE strstr(' " & Replace(HalBrain.AlphaNumericalOnly(OriginalSentence), "'", "") & " ', searchString) > 0 LIMIT 1", NameSex) = True Then
HalBrain.RunQuery("SELECT searchString, topic FROM names WHERE strstr(' " & Replace(TempName, "'", "") & " ', searchString) > 0 LIMIT 1", NameSex()) = True Then
HalBrain.PatternDB(" " & HalBrain.AlphaNumericalOnly(PrevSent) & " ", "sexAskDetect") = "True" Then
HalBrain.CheckTableExistence(Trim(LCase(UserName)) & "_Sex") = False Then
HalBrain.CreateTable Trim(LCase(UserName)) & "_Sex", "TopicSearch", "autoLearningBrain"
HalBrain.AddToTable Trim(LCase(UserName)) & "_Sex", "TopicSearch", Trim(TempName), Trim(UCase(NewSex))
HalBrain.CountInstances("A", PrevUserSent)
HalBrain.RandomNum(4)
HalBrain.UsCaps(UserSentence))
HalBrain.WorldCaps(UserSentence))
HalBrain.CheckRepetition(LastGoodDeduction, UserSentence)
HalBrain.PatternDB(UserSentence, "patterns")
A PatternDB function also exists that can go through a large list
'of patterns in a database file and come up with responses.
'This function tries getting a response from the Enhanced_Main.brn keyword file. If a keyword or
'keyphrase is found in top priority, it overrides everything before this function.
'KeyBrain = HalBrain.KeywordBrain(UserSentence, WorkingDir & "Enhanced_Main.brn", False)
HalBrain.HalMath(OriginalSentence) & vbCrLf
'RESPOND: RESPOND BY PARAPHRASING THE USER WHEN "IS" OR "ARE" ARE FOUND
'This code section shows how strings can be split into arrays and used "live"
'within the script by Hal. This strategy can allow Hal to make many clever
'paraphrases of all sorts of sentences, with unlimited unpredictable variety.
If InStr(UserSentence, " IS ") > 0 And HalBrain.CheckLinkingVerb(UserSentence)
'RESPOND: ZABAWARE DLL RESPONSES
'This function from the DLL contains miscellaneous knowledge and simple conversation functions.
'This was taken from a very early version of Hal, and it is still useful sometimes, especially
'for respoding to short cliche questions and sentences, such as "How old are you?" and
'"where are you from?" and many others.
GetResponse = HalBrain.HalFormat(GetResponse)
If (Len(UserSentence) < 17 And Len(GetResponse) < 4) Then
OrigBrain = HalBrain.OriginalBrain(OriginalSentence)
HalBrain.QABrain(LongUserSent, Trim(LCase(UserName)) & "_TempSent", UserBrainRel)
HalBrain.RemoveExtraSpaces(CurrentSubject & " " & MentionedName & " " & HalBrain.TopicSearch(UserSentence, "topicRelationships") & " " & HalBrain.ExtractKeywords(" " & HalBrain.AlphaNumericalOnly(UserSentence) & " "))
HalBrain.CheatResponse(HalBrain.SwitchPerson((OriginalSentence)))
HalBrain.FixCaps(AnswerSent))
HalBrain.LimitSize Trim(LCase(UserName)) & "_TempSent", 10
'Some Hal's learned knowledge should be temporary because it is ephemeral in nature.
'Knowledge about weather, season, temperature, etc. are temporary knowledge
'that shouldn't be stored in Hal's permanent brain files. Ephemeral knowledge is
'detected and saved in a temporary table. The temporary table only stores 10
'entries in it at a time.
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
HalBrainCommands raw Page ToolsInsert linksInsert links to other pages or uploaded files.
Pages Images and files Insert a link to a new pageLoading...No images or files uploaded yet.Insert image from URLTip: To turn text into a link, highlight the text, then click on a page or file from the list above.
------------------------------------------------------------------------------
•A whole help file I didn't know about
--------------------------------------------------------------------------------
•Enumerating the hal6uhp file
By 'Enumerating' I mean I intend to go through the whole file part by part and describe each block of code as best I can. I do this not as an authority, but in an attempt to learn what the heck I am talking about. Should take about a year!
1.Header
Rem Type=Brain As opposed to plugin
Rem Name=Ultra Hal 6.0 Default Brain
Rem Author=Zabaware, Inc.
Rem Language=VBScript This is what makes everything worthwhile
Rem DB=HalBrain.db If you use another brain this will reflect that name
Headers are probably read by the EXE file to decide which part of Hal they belong to and how to handle them. I see them as short INI files.
2.UltraHal Function
This will probably take a while to go through, I will probably have to learn a lot before I start to make any sense here!
First off, I begin to suspect that each argument is an optional argument. I forget how that works, but I know you can ignore some of them sometimes because the function assumes or remembers a value unless you tell it otherwise.
Quoting the file comments:
'The UltraHal function is called by Ultra Hal Assistant 6.0 or a compatible host application
'It passes an unformated string of the user's input as well as all remembered variables.
'The UltraHal function splits the user's input into seperate sentences and than calls
'GetResponse to get a response for each user sentence. The UltraHal function performs all
'the initialization functions required for GetResponse so that GetResponse doesn't have to
'initialize several times if a user inputs more than 1 sentence.
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)
3.Respond User pressed enter but didn't say anything
'RESPOND: User pressed enter, but didn't say anything
InputString = Trim(InputString)
If Len(InputString) < 2 Then
UltraHal = "Please say something."
Exit Function
End If
InputString is the raw text that you typed into Hal
Trim removes spaces from the ends of the string.
If the LENgth of the resulting string is less than two characters long then we send Hal the input string "Please say something" to which he will reply with something pithy. But my experiments with this lead me to believe that I have it all wrong.
Exit Function is probably something I need to know. I believe it will pop you out of the UltraHal function and make Hal go straight to GetResponse. I could be wrong.
4.Auto-Idle
A sort of self timer, if nothing happens then it fires up the UltraHal function to make a response of some sort.
'PROCESS: AUTO-IDLE
'If AUTO-IDLE is enabled, it is called by the Ultra Hal Assistant host
'application at a set interval. This allows for the possibility of Hal
'being the first to say something if the user is idle.
Things like this bug me. Why would input string be 'auto-idle'?
If InputString = "AUTO-IDLE" Then
This is the first PlugIn port
Rem PLUGIN: AUTO-IDLE
'The preceding comment is actually a plug-in directive for
'the Ultra Hal host application. It allows for code snippets
'to be inserted here on-the-fly based on user configuration.
Re-invoke the Ultrahal function to include any new information
UltraHal = UltraHal & HalBrain.StoreVars(HalCommands, Hate, Swear, Insults, Compliment, PrevSent, LastResponseTime, PrevUserSent, CustomMem, GainControl, LastTopicList)
|Bump out of the previous(?) ultrahal itteration.
Exit Function
Done with auto-idle
End If
Auto-Idle Page ToolsInsert linksInsert links to other pages or uploaded files.
Pages Images and files Insert a link to a new pageLoading...No images or files uploaded yet.Insert image from URLTip: To turn text into a link, highlight the text, then click on a page or file from the list above.
5.Initialize Variables
'PROCESS: IF NO LEARNING IS REQUESTED, PUT DATABASE IN READ-ONLY MODE
'If read only mode is on, any requests to create a new table, add to
'a table, or delete records from a table will be ignored.
Learning level is the slider in the General Options - Brain section. ReadOnlyMode turns on and off the ability to write to the databases in Hal. You will see this in many plugins, as they open the DB for writing then close it when done to prevent further modification of the responses.
If LearningLevel = 0 Then HalBrain.ReadOnlyMode = True Else HalBrain.ReadOnlyMode = False
6.If no learning is required
I actually crippled this in 'Jane's' brain. I can't see any adult actually insulting a robot, so I don't have to deal with recentering her "emotions".
'PROCESS: EMOTIONAL FACTOR CENTERING
'We help Hal regain his emotional "center" gradually, even if the
'user doesn't catch on to dealing With Hal's feelings. The following
'code brings Hal's memory of hate, swearing, and insults gradually
'and randomly back to zero.
SpinWheel = Int(Rnd * 100)
If Hate > 0 And SpinWheel < 10 Then Hate = Hate - 1
If Swear > 0 And SpinWheel < 10 Then Swear = Swear - 1
If Insults > 0 And SpinWheel < 10 Then Insults = Insults - 1
7.Emotional Factor Centering
I actually crippled this in 'Jane's' brain. I can't see any adult actually insulting a robot, so I don't have to deal with recentering her "emotions".
'PROCESS: EMOTIONAL FACTOR CENTERING
'We help Hal regain his emotional "center" gradually, even if the
'user doesn't catch on to dealing With Hal's feelings. The following
'code brings Hal's memory of hate, swearing, and insults gradually
'and randomly back to zero.
SpinWheel = Int(Rnd * 100)
If Hate > 0 And SpinWheel < 10 Then Hate = Hate - 1
If Swear > 0 And SpinWheel < 10 Then Swear = Swear - 1
If Insults > 0 And SpinWheel < 10 Then Insults = Insults - 1
8.Emotional Variety
Rem PLUGIN: PRE-PROCESS
'The preceding comment is actually a plug-in directive for
'the Ultra Hal host application. It allows for code snippets
'to be inserted here on-the-fly based on user configuration.
This is a plugin port. If you want your plugin to be activated before anything is done to the sentence, this is the place.
9.Rem PLUGIN: PREPROCESS
Rem PLUGIN: PRE-PROCESS
'The preceding comment is actually a plug-in directive for
'the Ultra Hal host application. It allows for code snippets
'to be inserted here on-the-fly based on user configuration.
This is a plugin port. If you want your plugin to be activated before anything is done to the sentence, this is the place.
10.Split User's Input String Into Separate Sentences