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"
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
Comments (0)
You don't have permission to comment on this page.